/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: Jelmer Vernooij
  • Date: 2011-12-20 16:47:38 UTC
  • Revision ID: jelmer@canonical.com-20111220164738-l6tgnbttkxmq6877
Cope with some strings being unicode when returned by some versions of gtk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Test the Commit functionality."""
18
18
 
19
19
import os
20
 
import subprocess
21
 
from tempfile import NamedTemporaryFile
22
20
 
23
21
from gi.repository import Gtk
24
22
 
37
35
    commit,
38
36
    commitmsgs,
39
37
    )
40
 
from bzrlib.plugins.gtk.commitmsgs import SavedCommitMessagesManager
41
 
from bzrlib.plugins.gtk.tests import MockMethod
42
38
 
43
39
 
44
40
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
148
144
 
149
145
class TestCommitDialogSimple(tests.TestCaseWithTransport):
150
146
 
151
 
    def test_init(self):
152
 
        MockMethod.bind(self, CommitDialogNoWidgets, 'setup_params')
153
 
        MockMethod.bind(self, CommitDialogNoWidgets, 'construct')
154
 
        MockMethod.bind(self, CommitDialogNoWidgets, 'fill_in_data')
155
 
 
156
 
        tree = self.make_branch_and_tree('tree')
157
 
        rev_id = tree.commit('first')
158
 
        dlg = CommitDialogNoWidgets(tree)
159
 
        self.assertIs(tree, dlg._wt)
160
 
        self.assertIs(None, dlg._selected)
161
 
        self.assertTrue(dlg._enable_per_file_commits)
162
 
        self.assertTrue(dlg._commit_all_changes)
163
 
        self.assertIs(None, dlg.committed_revision_id)
164
 
        self.assertIs(None, dlg._last_selected_file)
165
 
        self.assertIsInstance(
166
 
            dlg._saved_commit_messages_manager, SavedCommitMessagesManager)
167
 
        self.assertTrue(CommitDialogNoWidgets.setup_params.called)
168
 
        self.assertTrue(CommitDialogNoWidgets.construct.called)
169
 
        self.assertTrue(CommitDialogNoWidgets.fill_in_data.called)
170
 
 
171
147
    def test_setup_parameters_no_pending(self):
172
148
        tree = self.make_branch_and_tree('tree')
173
149
        rev_id = tree.commit('first')
216
192
        self.assertEqual([], delta.removed)
217
193
        self.assertEqual([(u'a', 'a-id', 'file')], delta.added)
218
194
 
219
 
    def test_on_treeview_files_cursor_changed_no_selection(self):
220
 
        MockMethod.bind(self, CommitDialogNoWidgets, '_update_per_file_info')
221
 
        tree = self.make_branch_and_tree('tree')
222
 
        rev_id = tree.commit('first')
223
 
        dlg = CommitDialogNoWidgets(tree)
224
 
        treeview = Gtk.TreeView()
225
 
        dlg._on_treeview_files_cursor_changed(treeview)
226
 
        self.assertFalse(CommitDialogNoWidgets._update_per_file_info.called)
227
 
 
228
 
    def test_on_treeview_files_cursor_changed_with_destroyed_treeview(self):
229
 
        MockMethod.bind(self, CommitDialogNoWidgets, '_update_per_file_info')
230
 
        tree = self.make_branch_and_tree('tree')
231
 
        rev_id = tree.commit('first')
232
 
        dlg = CommitDialogNoWidgets(tree)
233
 
        treeview = Gtk.TreeView()
234
 
        treeview.destroy()
235
 
        dlg._on_treeview_files_cursor_changed(treeview)
236
 
        self.assertFalse(CommitDialogNoWidgets._update_per_file_info.called)
237
 
 
238
195
 
239
196
class TestCommitDialog(tests.TestCaseWithTransport):
240
197
 
1298
1255
        self.assertEquals(u'', self._get_commit_message())
1299
1256
        self.assertEquals(u'de',
1300
1257
                          self._get_file_commit_messages())
1301
 
 
1302
 
 
1303
 
class BzrHandlePatchTestCase(tests.TestCase):
1304
 
 
1305
 
    def setUp(self):
1306
 
        top = os.path.abspath(os.path.join(
1307
 
            os.path.dirname(__file__), os.pardir))
1308
 
        self.script = os.path.join(top, 'bzr-handle-patch')
1309
 
        self.env = dict(os.environ)
1310
 
        self.env['BZR_PLUGINS_AT'] = 'gtk@%s' % top
1311
 
        self.patch = NamedTemporaryFile()
1312
 
        self.patch.write('\n'.join([
1313
 
            "=== added file '_test.txt'",
1314
 
            "--- _test.txt      1970-01-01 00:00:00 +0000",
1315
 
            "+++ _test.txt      2012-02-03 20:00:34 +0000",
1316
 
            "@@ -0,0 +1,1 @@",
1317
 
            "+hello",
1318
 
            ]))
1319
 
        self.patch.flush()
1320
 
        super(BzrHandlePatchTestCase, self).setUp()
1321
 
 
1322
 
    def test_smoketest(self):
1323
 
        # This is a smoke test to verify the process starts.
1324
 
        bzr_notify = subprocess.Popen(
1325
 
            [self.script, self.patch.name, 'test'],
1326
 
            stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self.env)
1327
 
        stdout, stderr = bzr_notify.communicate()
1328
 
        self.assertEqual('', stdout)
1329
 
        self.assertEqual('', stderr)