/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_commit.py

  • Committer: Vincent Ladeuil
  • Date: 2008-11-06 15:45:24 UTC
  • mto: This revision was merged to the branch mainline in revision 625.
  • Revision ID: v.ladeuil+lp@free.fr-20081106154524-n9al5n1pome2xo0u
Fix bug #289220 by using the right parameter order.

* status.py:
(StatusWindow.row_diff): One can argue that the parameters are in
the wrong order or just respect their meaning :) Thanks to Anne
Mohsen for noticing and proposing the fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 John Arbash Meinel <john@arbash-meinel.com>
 
1
# Copyright (C) 2007 John Arbash Meinel <john@arbash-meinel.com>
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
import gtk
22
22
 
23
23
from bzrlib import (
24
 
    branch,
 
24
    tests,
25
25
    revision,
26
 
    tests,
27
 
    uncommit,
28
26
    )
29
 
try:
30
 
    from bzrlib import bencode
31
 
except ImportError:
32
 
    from bzrlib.util import bencode
 
27
from bzrlib.util import bencode
33
28
 
34
29
from bzrlib.plugins.gtk import commit
35
30
 
649
644
                            'message':'message\nfor b_dir\n'},
650
645
                          ]), dlg._get_specific_files())
651
646
 
652
 
    def test_specific_files_sanitizes_messages(self):
653
 
        tree = self.make_branch_and_tree('tree')
654
 
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
655
 
        self.build_tree(['tree/a_file', 'tree/b_dir/'])
656
 
        tree.add(['a_file', 'b_dir'], ['1a-id', '0b-id'])
657
 
 
658
 
        dlg = commit.CommitDialog(tree)
659
 
        dlg._commit_selected_radio.set_active(True)
660
 
        self.assertEqual((['a_file', 'b_dir'], []), dlg._get_specific_files())
661
 
 
662
 
        dlg._treeview_files.set_cursor((1,))
663
 
        dlg._set_file_commit_message('Test\r\nmessage\rfor a_file\n')
664
 
        dlg._treeview_files.set_cursor((2,))
665
 
        dlg._set_file_commit_message('message\r\nfor\nb_dir\r')
666
 
 
667
 
        self.assertEqual((['a_file', 'b_dir'],
668
 
                          [{'path':'a_file', 'file_id':'1a-id',
669
 
                            'message':'Test\nmessage\nfor a_file\n'},
670
 
                           {'path':'b_dir', 'file_id':'0b-id',
671
 
                            'message':'message\nfor\nb_dir\n'},
672
 
                          ]), dlg._get_specific_files())
673
 
 
674
 
 
675
 
class QuestionHelpers(object):
 
647
 
 
648
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
 
649
    """Tests on the actual 'commit' button being pushed."""
676
650
 
677
651
    def _set_question_yes(self, dlg):
678
652
        """Set the dialog to answer YES to any questions."""
692
666
            return gtk.RESPONSE_NO
693
667
        dlg._question_dialog = _question_no
694
668
 
695
 
 
696
 
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
697
 
    """Tests on the actual 'commit' button being pushed."""
698
 
 
699
669
    def test_bound_commit_local(self):
700
670
        tree = self.make_branch_and_tree('tree')
701
671
        self.build_tree(['tree/a'])
717
687
        self.assertEqual(last_rev, dlg.committed_revision_id)
718
688
        self.assertEqual(rev_id1, tree.branch.last_revision())
719
689
 
720
 
    def test_commit_global_sanitizes_message(self):
721
 
        tree = self.make_branch_and_tree('tree')
722
 
        self.build_tree(['tree/a'])
723
 
        tree.add(['a'], ['a-id'])
724
 
        rev_id1 = tree.commit('one')
725
 
 
726
 
        self.build_tree(['tree/b'])
727
 
        tree.add(['b'], ['b-id'])
728
 
        dlg = commit.CommitDialog(tree)
729
 
        # With the check box set, it should only effect the local branch
730
 
        dlg._set_global_commit_message('Commit\r\nmessage\rfoo\n')
731
 
        dlg._do_commit()
732
 
        rev = tree.branch.repository.get_revision(tree.last_revision())
733
 
        self.assertEqual('Commit\nmessage\nfoo\n', rev.message)
734
 
 
735
690
    def test_bound_commit_both(self):
736
691
        tree = self.make_branch_and_tree('tree')
737
692
        self.build_tree(['tree/a'])
1075
1030
                          {'path':u'\u03a9', 'file_id':'omega-id',
1076
1031
                           'message':u'\u03a9 is the end of all things.\n'},
1077
1032
                         ], file_info_decoded)
1078
 
 
1079
 
 
1080
 
class TestSanitizeMessage(tests.TestCase):
1081
 
 
1082
 
    def assertSanitize(self, expected, original):
1083
 
        self.assertEqual(expected,
1084
 
                         commit._sanitize_and_decode_message(original))
1085
 
 
1086
 
    def test_untouched(self):
1087
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1088
 
 
1089
 
    def test_converts_cr_to_lf(self):
1090
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1091
 
 
1092
 
    def test_converts_crlf_to_lf(self):
1093
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1094
 
 
1095
 
    def test_converts_mixed_to_lf(self):
1096
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1097
 
 
1098
 
 
1099
 
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1100
 
 
1101
 
    def setUp(self):
1102
 
        super(TestSavedCommitMessages, self).setUp()
1103
 
        # Install our hook
1104
 
        branch.Branch.hooks.install_named_hook(
1105
 
            'post_uncommit', commit.save_commit_messages, None)
1106
 
 
1107
 
    def _get_file_info_dict(self, rank):
1108
 
        file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1109
 
                     dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1110
 
        return file_info
1111
 
 
1112
 
    def _get_file_info_revprops(self, rank):
1113
 
        file_info_prop = self._get_file_info_dict(rank)
1114
 
        return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1115
 
 
1116
 
    def _get_commit_message(self):
1117
 
        return self.config.get_user_option('gtk_global_commit_message')
1118
 
 
1119
 
    def _get_file_commit_messages(self):
1120
 
        return self.config.get_user_option('gtk_file_commit_messages')
1121
 
 
1122
 
 
1123
 
class TestUncommitHook(TestSavedCommitMessages):
1124
 
 
1125
 
    def setUp(self):
1126
 
        super(TestUncommitHook, self).setUp()
1127
 
        self.tree = self.make_branch_and_tree('tree')
1128
 
        self.config = self.tree.branch.get_config()
1129
 
        self.build_tree(['tree/a', 'tree/b'])
1130
 
        self.tree.add(['a'], ['a-id'])
1131
 
        self.tree.add(['b'], ['b-id'])
1132
 
        rev1 = self.tree.commit('one', rev_id='one-id',
1133
 
                                revprops=self._get_file_info_revprops(1))
1134
 
        rev2 = self.tree.commit('two', rev_id='two-id',
1135
 
                                revprops=self._get_file_info_revprops(2))
1136
 
        rev3 = self.tree.commit('three', rev_id='three-id',
1137
 
                                revprops=self._get_file_info_revprops(3))
1138
 
 
1139
 
    def test_uncommit_one_by_one(self):
1140
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1141
 
        self.assertEquals(u'three', self._get_commit_message())
1142
 
        self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1143
 
                          self._get_file_commit_messages())
1144
 
 
1145
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1146
 
        self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1147
 
        self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1148
 
                          '4:b-id22:b msg 2\n******\nb msg 3e',
1149
 
                          self._get_file_commit_messages())
1150
 
 
1151
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1152
 
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1153
 
                          self._get_commit_message())
1154
 
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1155
 
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1156
 
                          self._get_file_commit_messages())
1157
 
 
1158
 
    def test_uncommit_all_at_once(self):
1159
 
        uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1160
 
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1161
 
                          self._get_commit_message())
1162
 
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1163
 
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1164
 
                          self._get_file_commit_messages())
1165
 
 
1166
 
 
1167
 
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1168
 
 
1169
 
    def setUp(self):
1170
 
        super(TestReusingSavedCommitMessages, self).setUp()
1171
 
        self.tree = self.make_branch_and_tree('tree')
1172
 
        self.config = self.tree.branch.get_config()
1173
 
        self.config.set_user_option('per_file_commits', 'true')
1174
 
        self.build_tree(['tree/a', 'tree/b'])
1175
 
        self.tree.add(['a'], ['a-id'])
1176
 
        self.tree.add(['b'], ['b-id'])
1177
 
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1178
 
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1179
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1180
 
        self.build_tree_contents([('tree/a', 'new a content\n'),
1181
 
                                  ('tree/b', 'new b content'),])
1182
 
 
1183
 
    def _get_commit_dialog(self, tree):
1184
 
        # Ensure we will never use a dialog that can actually prompt the user
1185
 
        # during the test suite. Test *can* and *should* override with the
1186
 
        # correct question dialog type.
1187
 
        dlg = commit.CommitDialog(tree)
1188
 
        self._set_question_no(dlg)
1189
 
        return dlg
1190
 
 
1191
 
    def test_setup_saved_messages(self):
1192
 
        # Check the initial setup
1193
 
        self.assertEquals(u'two', self._get_commit_message())
1194
 
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1195
 
                          self._get_file_commit_messages())
1196
 
 
1197
 
    def test_messages_are_reloaded(self):
1198
 
        dlg = self._get_commit_dialog(self.tree)
1199
 
        self.assertEquals(u'two', dlg._get_global_commit_message())
1200
 
        self.assertEquals(([u'a', u'b'],
1201
 
                           [{ 'path': 'a',
1202
 
                             'file_id': 'a-id', 'message': 'a msg 2',},
1203
 
                           {'path': 'b',
1204
 
                            'file_id': 'b-id', 'message': 'b msg 2',}],),
1205
 
                          dlg._get_specific_files())
1206
 
 
1207
 
    def test_messages_are_consumed(self):
1208
 
        dlg = self._get_commit_dialog(self.tree)
1209
 
        dlg._do_commit()
1210
 
        self.assertEquals(u'', self._get_commit_message())
1211
 
        self.assertEquals(u'de', self._get_file_commit_messages())
1212
 
 
1213
 
    def test_messages_are_saved_on_cancel_if_required(self):
1214
 
        dlg = self._get_commit_dialog(self.tree)
1215
 
        self._set_question_yes(dlg) # Save messages
1216
 
        dlg._do_cancel()
1217
 
        self.assertEquals(u'two', self._get_commit_message())
1218
 
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1219
 
                          self._get_file_commit_messages())
1220
 
 
1221
 
    def test_messages_are_cleared_on_cancel_if_required(self):
1222
 
        dlg = self._get_commit_dialog(self.tree)
1223
 
        self._set_question_no(dlg) # Don't save messages
1224
 
        dlg._do_cancel()
1225
 
        self.assertEquals(u'', self._get_commit_message())
1226
 
        self.assertEquals(u'de',
1227
 
                          self._get_file_commit_messages())