/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-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

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
 
86
81
        rev_id1 = tree.commit('one')
87
82
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
88
83
        rev_id2 = tree2.commit('two')
 
84
        rev_id3 = tree2.commit('three')
89
85
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
90
 
        rev_id3 = tree2.commit('three')
91
86
        rev_id4 = tree3.commit('four')
92
87
        rev_id5 = tree3.commit('five')
93
88
        tree.merge_from_branch(tree2.branch)
94
 
        tree.merge_from_branch(tree3.branch, force=True)
 
89
        tree.merge_from_branch(tree3.branch)
95
90
        self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids())
96
91
 
97
92
        pending_revisions = commit.pending_revisions(tree)
271
266
                               committer='Jerry Foo <jerry@foo.com>',
272
267
                               timestamp=1191372278.05,
273
268
                               timezone=+7200)
274
 
        tree.merge_from_branch(tree3.branch, force=True)
 
269
        tree.merge_from_branch(tree3.branch)
275
270
 
276
271
        dlg = commit.CommitDialog(tree)
277
272
        # TODO: assert that the pending box is set to show
416
411
        text = diff_buffer.get_text(diff_buffer.get_start_iter(),
417
412
                                    diff_buffer.get_end_iter()).splitlines(True)
418
413
 
419
 
        self.assertEqual("=== modified file 'a'\n", text[0])
 
414
        self.assertEqual("=== removed file 'b'\n", text[0])
420
415
        self.assertContainsRe(text[1],
 
416
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
 
417
        self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[2])
 
418
        self.assertEqual('@@ -1,1 +0,0 @@\n', text[3])
 
419
        self.assertEqual('-contents of tree/b\n', text[4])
 
420
        self.assertEqual('\n', text[5])
 
421
 
 
422
        self.assertEqual("=== modified file 'a'\n", text[6])
 
423
        self.assertContainsRe(text[7],
421
424
            r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
422
 
        self.assertContainsRe(text[2],
423
 
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
424
 
        self.assertEqual('@@ -1,1 +1,1 @@\n', text[3])
425
 
        self.assertEqual('-contents of tree/a\n', text[4])
426
 
        self.assertEqual('+new contents for a\n', text[5])
427
 
        self.assertEqual('\n', text[6])
428
 
 
429
 
        self.assertEqual("=== removed file 'b'\n", text[7])
430
425
        self.assertContainsRe(text[8],
431
 
            r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
432
 
        self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[9])
433
 
        self.assertEqual('@@ -1,1 +0,0 @@\n', text[10])
434
 
        self.assertEqual('-contents of tree/b\n', text[11])
 
426
            r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d")
 
427
        self.assertEqual('@@ -1,1 +1,1 @@\n', text[9])
 
428
        self.assertEqual('-contents of tree/a\n', text[10])
 
429
        self.assertEqual('+new contents for a\n', text[11])
435
430
        self.assertEqual('\n', text[12])
436
431
 
437
432
        self.assertEqual('Diff for All Files', dlg._diff_label.get_text())
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."""
679
653
        self.questions = []
680
 
        def _question_yes(*args, **kwargs):
 
654
        def _question_yes(*args):
681
655
            self.questions.append(args)
682
656
            self.questions.append('YES')
683
657
            return gtk.RESPONSE_YES
686
660
    def _set_question_no(self, dlg):
687
661
        """Set the dialog to answer NO to any questions."""
688
662
        self.questions = []
689
 
        def _question_no(*args, **kwargs):
 
663
        def _question_no(*args):
690
664
            self.questions.append(args)
691
665
            self.questions.append('NO')
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'])
753
708
        self.assertEqual(last_rev, dlg.committed_revision_id)
754
709
        self.assertEqual(last_rev, tree.branch.last_revision())
755
710
 
756
 
    def test_commit_empty_message(self):
 
711
    def test_commit_no_message(self):
757
712
        tree = self.make_branch_and_tree('tree')
758
713
        self.build_tree(['tree/a', 'tree/b'])
759
714
        tree.add(['a'], ['a-id'])
988
943
        rev = tree.branch.repository.get_revision(rev_id2)
989
944
        self.assertEqual('Commit just "a"', rev.message)
990
945
        file_info = rev.properties['file-info']
991
 
        self.assertEqual(u'ld7:file_id4:a-id'
992
 
                         '7:message14:Message for A\n'
993
 
                         '4:path1:a'
994
 
                         'ee',
995
 
                         file_info)
 
946
        self.assertEqual('ld7:file_id4:a-id'
 
947
                           '7:message14:Message for A\n'
 
948
                           '4:path1:a'
 
949
                         'ee', file_info)
996
950
        self.assertEqual([{'path':'a', 'file_id':'a-id',
997
 
                           'message':'Message for A\n'},],
998
 
                         bencode.bdecode(file_info.encode('UTF-8')))
 
951
                           'message':'Message for A\n'},
 
952
                         ], bencode.bdecode(file_info))
999
953
 
1000
954
    def test_commit_messages_after_merge(self):
1001
955
        tree = self.make_branch_and_tree('tree')
1022
976
        self.assertEqual('Merging from "tree2"\n', rev.message)
1023
977
        self.assertEqual([rev_id1, rev_id2], rev.parent_ids)
1024
978
        file_info = rev.properties['file-info']
1025
 
        self.assertEqual(u'ld7:file_id4:a-id'
1026
 
                         '7:message14:Message for A\n'
1027
 
                         '4:path1:a'
1028
 
                         'ee',
1029
 
                         file_info)
 
979
        self.assertEqual('ld7:file_id4:a-id'
 
980
                           '7:message14:Message for A\n'
 
981
                           '4:path1:a'
 
982
                         'ee', file_info)
1030
983
        self.assertEqual([{'path':'a', 'file_id':'a-id',
1031
 
                           'message':'Message for A\n'},],
1032
 
                         bencode.bdecode(file_info.encode('UTF-8')))
 
984
                           'message':'Message for A\n'},
 
985
                         ], bencode.bdecode(file_info))
1033
986
 
1034
987
    def test_commit_unicode_messages(self):
1035
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
988
        from bzrlib.tests.test_diff import UnicodeFilename
 
989
        self.requireFeature(UnicodeFilename)
1036
990
 
1037
991
        tree = self.make_branch_and_tree('tree')
1038
992
        tree.branch.get_config().set_user_option('per_file_commits', 'true')
1077
1031
                          {'path':u'\u03a9', 'file_id':'omega-id',
1078
1032
                           'message':u'\u03a9 is the end of all things.\n'},
1079
1033
                         ], file_info_decoded)
1080
 
 
1081
 
 
1082
 
class TestSanitizeMessage(tests.TestCase):
1083
 
 
1084
 
    def assertSanitize(self, expected, original):
1085
 
        self.assertEqual(expected,
1086
 
                         commit._sanitize_and_decode_message(original))
1087
 
 
1088
 
    def test_untouched(self):
1089
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\nbar\nbaz\n')
1090
 
 
1091
 
    def test_converts_cr_to_lf(self):
1092
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\rbar\rbaz\r')
1093
 
 
1094
 
    def test_converts_crlf_to_lf(self):
1095
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\r\nbaz\r\n')
1096
 
 
1097
 
    def test_converts_mixed_to_lf(self):
1098
 
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1099
 
 
1100
 
 
1101
 
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1102
 
 
1103
 
    def setUp(self):
1104
 
        super(TestSavedCommitMessages, self).setUp()
1105
 
        # Install our hook
1106
 
        branch.Branch.hooks.install_named_hook(
1107
 
            'post_uncommit', commit.save_commit_messages, None)
1108
 
 
1109
 
    def _get_file_info_dict(self, rank):
1110
 
        file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1111
 
                     dict(path='b', file_id='b-id', message='b msg %d' % rank)]
1112
 
        return file_info
1113
 
 
1114
 
    def _get_file_info_revprops(self, rank):
1115
 
        file_info_prop = self._get_file_info_dict(rank)
1116
 
        return {'file-info': bencode.bencode(file_info_prop).decode('UTF-8')}
1117
 
 
1118
 
    def _get_commit_message(self):
1119
 
        return self.config.get_user_option('gtk_global_commit_message')
1120
 
 
1121
 
    def _get_file_commit_messages(self):
1122
 
        return self.config.get_user_option('gtk_file_commit_messages')
1123
 
 
1124
 
 
1125
 
class TestUncommitHook(TestSavedCommitMessages):
1126
 
 
1127
 
    def setUp(self):
1128
 
        super(TestUncommitHook, self).setUp()
1129
 
        self.tree = self.make_branch_and_tree('tree')
1130
 
        self.config = self.tree.branch.get_config()
1131
 
        self.build_tree(['tree/a', 'tree/b'])
1132
 
        self.tree.add(['a'], ['a-id'])
1133
 
        self.tree.add(['b'], ['b-id'])
1134
 
        rev1 = self.tree.commit('one', rev_id='one-id',
1135
 
                                revprops=self._get_file_info_revprops(1))
1136
 
        rev2 = self.tree.commit('two', rev_id='two-id',
1137
 
                                revprops=self._get_file_info_revprops(2))
1138
 
        rev3 = self.tree.commit('three', rev_id='three-id',
1139
 
                                revprops=self._get_file_info_revprops(3))
1140
 
 
1141
 
    def test_uncommit_one_by_one(self):
1142
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1143
 
        self.assertEquals(u'three', self._get_commit_message())
1144
 
        self.assertEquals(u'd4:a-id7:a msg 34:b-id7:b msg 3e',
1145
 
                          self._get_file_commit_messages())
1146
 
 
1147
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1148
 
        self.assertEquals(u'two\n******\nthree', self._get_commit_message())
1149
 
        self.assertEquals(u'd4:a-id22:a msg 2\n******\na msg 3'
1150
 
                          '4:b-id22:b msg 2\n******\nb msg 3e',
1151
 
                          self._get_file_commit_messages())
1152
 
 
1153
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1154
 
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1155
 
                          self._get_commit_message())
1156
 
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1157
 
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1158
 
                          self._get_file_commit_messages())
1159
 
 
1160
 
    def test_uncommit_all_at_once(self):
1161
 
        uncommit.uncommit(self.tree.branch, tree=self.tree, revno=1)
1162
 
        self.assertEquals(u'one\n******\ntwo\n******\nthree',
1163
 
                          self._get_commit_message())
1164
 
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1165
 
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1166
 
                          self._get_file_commit_messages())
1167
 
 
1168
 
 
1169
 
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
1170
 
 
1171
 
    def setUp(self):
1172
 
        super(TestReusingSavedCommitMessages, self).setUp()
1173
 
        self.tree = self.make_branch_and_tree('tree')
1174
 
        self.config = self.tree.branch.get_config()
1175
 
        self.config.set_user_option('per_file_commits', 'true')
1176
 
        self.build_tree(['tree/a', 'tree/b'])
1177
 
        self.tree.add(['a'], ['a-id'])
1178
 
        self.tree.add(['b'], ['b-id'])
1179
 
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1180
 
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1181
 
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1182
 
        self.build_tree_contents([('tree/a', 'new a content\n'),
1183
 
                                  ('tree/b', 'new b content'),])
1184
 
 
1185
 
    def _get_commit_dialog(self, tree):
1186
 
        # Ensure we will never use a dialog that can actually prompt the user
1187
 
        # during the test suite. Test *can* and *should* override with the
1188
 
        # correct question dialog type.
1189
 
        dlg = commit.CommitDialog(tree)
1190
 
        self._set_question_no(dlg)
1191
 
        return dlg
1192
 
 
1193
 
    def test_setup_saved_messages(self):
1194
 
        # Check the initial setup
1195
 
        self.assertEquals(u'two', self._get_commit_message())
1196
 
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1197
 
                          self._get_file_commit_messages())
1198
 
 
1199
 
    def test_messages_are_reloaded(self):
1200
 
        dlg = self._get_commit_dialog(self.tree)
1201
 
        self.assertEquals(u'two', dlg._get_global_commit_message())
1202
 
        self.assertEquals(([u'a', u'b'],
1203
 
                           [{ 'path': 'a',
1204
 
                             'file_id': 'a-id', 'message': 'a msg 2',},
1205
 
                           {'path': 'b',
1206
 
                            'file_id': 'b-id', 'message': 'b msg 2',}],),
1207
 
                          dlg._get_specific_files())
1208
 
 
1209
 
    def test_messages_are_consumed(self):
1210
 
        dlg = self._get_commit_dialog(self.tree)
1211
 
        dlg._do_commit()
1212
 
        self.assertEquals(u'', self._get_commit_message())
1213
 
        self.assertEquals(u'de', self._get_file_commit_messages())
1214
 
 
1215
 
    def test_messages_are_saved_on_cancel_if_required(self):
1216
 
        dlg = self._get_commit_dialog(self.tree)
1217
 
        self._set_question_yes(dlg) # Save messages
1218
 
        dlg._do_cancel()
1219
 
        self.assertEquals(u'two', self._get_commit_message())
1220
 
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
1221
 
                          self._get_file_commit_messages())
1222
 
 
1223
 
    def test_messages_are_cleared_on_cancel_if_required(self):
1224
 
        dlg = self._get_commit_dialog(self.tree)
1225
 
        self._set_question_no(dlg) # Don't save messages
1226
 
        dlg._do_cancel()
1227
 
        self.assertEquals(u'', self._get_commit_message())
1228
 
        self.assertEquals(u'de',
1229
 
                          self._get_file_commit_messages())