/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: Markus Korn
  • Date: 2009-03-05 16:50:39 UTC
  • mto: (635.2.4 trunk)
  • mto: This revision was merged to the branch mainline in revision 639.
  • Revision ID: thekorn@gmx.de-20090305165039-h6xh48wr9lwe1661
* register BranchSelectionBox() as a gobject type to fix (LP: #294396)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
672
667
                          ]), dlg._get_specific_files())
673
668
 
674
669
 
675
 
class QuestionHelpers(object):
 
670
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
 
671
    """Tests on the actual 'commit' button being pushed."""
676
672
 
677
673
    def _set_question_yes(self, dlg):
678
674
        """Set the dialog to answer YES to any questions."""
692
688
            return gtk.RESPONSE_NO
693
689
        dlg._question_dialog = _question_no
694
690
 
695
 
 
696
 
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
697
 
    """Tests on the actual 'commit' button being pushed."""
698
 
 
699
691
    def test_bound_commit_local(self):
700
692
        tree = self.make_branch_and_tree('tree')
701
693
        self.build_tree(['tree/a'])
1094
1086
 
1095
1087
    def test_converts_mixed_to_lf(self):
1096
1088
        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())