/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: 2009-05-28 11:07:02 UTC
  • mto: This revision was merged to the branch mainline in revision 640.
  • Revision ID: v.ladeuil+lp@free.fr-20090528110702-alqi2wojbzdopwol
Complete tests around saved commit messages.

* tests/test_commit.py:
(QuestionHelpers): Factor out helpers for embedded dialogs.
(TestSavedCommitMessages): Factor out helpers for saved commit
messages.
(TestReusingSavedCommitMessages): Add tests for saved messages
reuse.

* commit.py:
(CommitDialog._do_cancel): Use the overidable dialog for tests
purposes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
668
668
                          ]), dlg._get_specific_files())
669
669
 
670
670
 
671
 
class TestCommitDialog_Commit(tests.TestCaseWithTransport):
672
 
    """Tests on the actual 'commit' button being pushed."""
 
671
class QuestionHelpers(object):
673
672
 
674
673
    def _set_question_yes(self, dlg):
675
674
        """Set the dialog to answer YES to any questions."""
689
688
            return gtk.RESPONSE_NO
690
689
        dlg._question_dialog = _question_no
691
690
 
 
691
 
 
692
class TestCommitDialog_Commit(tests.TestCaseWithTransport, QuestionHelpers):
 
693
    """Tests on the actual 'commit' button being pushed."""
 
694
 
692
695
    def test_bound_commit_local(self):
693
696
        tree = self.make_branch_and_tree('tree')
694
697
        self.build_tree(['tree/a'])
1089
1092
        self.assertSanitize('foo\nbar\nbaz\n', 'foo\r\nbar\rbaz\n')
1090
1093
 
1091
1094
 
1092
 
class TestUncommitHook(tests.TestCaseWithTransport):
1093
 
 
1094
 
    def setUp(self):
1095
 
        super(TestUncommitHook, self).setUp()
1096
 
        self.tree = self.make_branch_and_tree('tree')
1097
 
        self.config = self.tree.branch.get_config()
1098
 
        self.build_tree(['tree/a', 'tree/b'])
1099
 
        self.tree.add(['a'], ['a-id'])
1100
 
        self.tree.add(['b'], ['b-id'])
1101
 
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
1102
 
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
1103
 
        rev3 = self.tree.commit('three',
1104
 
                                revprops=self._get_file_info_revprops(3))
 
1095
class TestSavedCommitMessages(tests.TestCaseWithTransport):
1105
1096
 
1106
1097
    def _get_file_info_dict(self, rank):
1107
1098
        file_info = [dict(path='a', file_id='a-id', message='a msg %d' % rank),
1118
1109
    def _get_file_commit_messages(self):
1119
1110
        return self.config.get_user_option('gtk_file_commit_messages')
1120
1111
 
 
1112
 
 
1113
class TestUncommitHook(TestSavedCommitMessages):
 
1114
 
 
1115
    def setUp(self):
 
1116
        super(TestUncommitHook, self).setUp()
 
1117
        self.tree = self.make_branch_and_tree('tree')
 
1118
        self.config = self.tree.branch.get_config()
 
1119
        self.build_tree(['tree/a', 'tree/b'])
 
1120
        self.tree.add(['a'], ['a-id'])
 
1121
        self.tree.add(['b'], ['b-id'])
 
1122
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
 
1123
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
 
1124
        rev3 = self.tree.commit('three',
 
1125
                                revprops=self._get_file_info_revprops(3))
 
1126
 
1121
1127
    def test_uncommit_one_by_one(self):
1122
1128
        uncommit.uncommit(self.tree.branch, tree=self.tree)
1123
1129
        self.assertEquals(u'three', self._get_commit_message())
1144
1150
        self.assertEquals(u'd4:a-id37:a msg 1\n******\na msg 2\n******\na msg 3'
1145
1151
                          '4:b-id37:b msg 1\n******\nb msg 2\n******\nb msg 3e',
1146
1152
                          self._get_file_commit_messages())
 
1153
 
 
1154
 
 
1155
class TestReusingSavedCommitMessages(TestSavedCommitMessages, QuestionHelpers):
 
1156
 
 
1157
    def setUp(self):
 
1158
        super(TestReusingSavedCommitMessages, self).setUp()
 
1159
        self.tree = self.make_branch_and_tree('tree')
 
1160
        self.config = self.tree.branch.get_config()
 
1161
        self.config.set_user_option('per_file_commits', 'true')
 
1162
        self.build_tree(['tree/a', 'tree/b'])
 
1163
        self.tree.add(['a'], ['a-id'])
 
1164
        self.tree.add(['b'], ['b-id'])
 
1165
        rev1 = self.tree.commit('one', revprops=self._get_file_info_revprops(1))
 
1166
        rev2 = self.tree.commit('two', revprops=self._get_file_info_revprops(2))
 
1167
        uncommit.uncommit(self.tree.branch, tree=self.tree)
 
1168
        self.build_tree_contents([('tree/a', 'new a content\n'),
 
1169
                                  ('tree/b', 'new b content'),])
 
1170
 
 
1171
    def test_setup_saved_messages(self):
 
1172
        # Check the initial setup
 
1173
        self.assertEquals(u'two', self._get_commit_message())
 
1174
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
 
1175
                          self._get_file_commit_messages())
 
1176
 
 
1177
    def test_messages_are_reloaded(self):
 
1178
        dlg = commit.CommitDialog(self.tree)
 
1179
        self.assertEquals(u'two', dlg._get_global_commit_message())
 
1180
        self.assertEquals(([u'a', u'b'],
 
1181
                           [{ 'path': 'a',
 
1182
                             'file_id': 'a-id', 'message': 'a msg 2',},
 
1183
                           {'path': 'b',
 
1184
                            'file_id': 'b-id', 'message': 'b msg 2',}],),
 
1185
                          dlg._get_specific_files())
 
1186
 
 
1187
    def test_messages_are_consumed(self):
 
1188
        dlg = commit.CommitDialog(self.tree)
 
1189
        dlg._do_commit()
 
1190
        self.assertEquals(u'', self._get_commit_message())
 
1191
        self.assertEquals(u'de', self._get_file_commit_messages())
 
1192
 
 
1193
    def test_messages_are_saved_on_cancel_if_required(self):
 
1194
        dlg = commit.CommitDialog(self.tree)
 
1195
        self._set_question_yes(dlg) # Save messages
 
1196
        dlg._do_cancel()
 
1197
        self.assertEquals(u'two', self._get_commit_message())
 
1198
        self.assertEquals(u'd4:a-id7:a msg 24:b-id7:b msg 2e',
 
1199
                          self._get_file_commit_messages())
 
1200
 
 
1201
    def test_messages_are_cleared_on_cancel_if_required(self):
 
1202
        dlg = commit.CommitDialog(self.tree)
 
1203
        self._set_question_no(dlg) # Don't save messages
 
1204
        dlg._do_cancel()
 
1205
        self.assertEquals(u'', self._get_commit_message())
 
1206
        self.assertEquals(u'de',
 
1207
                          self._get_file_commit_messages())