18
18
from cStringIO import StringIO
21
from bzrlib import errors, tests
21
from gi.repository import Gtk
29
from bzrlib.tests.features import UnicodeFilenameFeature
30
except ImportError: # bzr < 2.5
31
from bzrlib.tests import UnicodeFilenameFeature
22
32
from bzrlib.merge_directive import MergeDirective2
24
34
from bzrlib.plugins.gtk.diff import (
27
39
iter_changes_to_status,
28
40
MergeDirectiveController,
42
from bzrlib.plugins.gtk.tests import MockMethod
31
46
=== modified file 'tests/test_diff.py'
32
47
--- tests/test_diff.py 2008-03-11 13:18:28 +0000
69
84
class TestDiffView(tests.TestCaseWithTransport):
71
86
def test_unicode(self):
72
self.requireFeature(tests.UnicodeFilenameFeature)
87
self.requireFeature(UnicodeFilenameFeature)
74
89
tree = self.make_branch_and_tree('tree')
75
90
self.build_tree([u'tree/\u03a9'])
80
95
view.show_diff(None)
82
97
start, end = buf.get_bounds()
83
text = buf.get_text(start, end)
98
text = buf.get_text(start, end, True)
84
99
self.assertContainsRe(text,
85
100
"=== added file '\xce\xa9'\n"
86
101
'--- .*\t1970-01-01 00:00:00 \\+0000\n'
110
class FakeDiffWidget(DiffWidget):
115
class TestDiffWidget(tests.TestCaseWithTransport):
117
def test_treeview_cursor_cb(self):
118
widget = FakeDiffWidget()
119
widget.set_diff_text_sections(
120
[('', None, 'patch1'), ('a', 'a', 'patch2')])
121
widget.treeview.set_cursor(Gtk.TreePath(path=1), None, False)
122
widget._treeview_cursor_cb(None)
123
self.assertTrue('patch2', widget.diff_view.buffer.props.text)
125
def test_treeview_cursor_cb_with_destroyed_treeview(self):
126
widget = FakeDiffWidget()
127
widget.set_diff_text_sections(
128
[('', None, 'patch1'), ('a', 'a', 'patch2')])
129
MockMethod.bind(self, widget.diff_view, 'show_diff')
130
widget.treeview.destroy()
131
widget._treeview_cursor_cb(None)
132
self.assertFalse(widget.diff_view.show_diff.called)
135
class FakeDiffWindow(DiffWindow):
140
class DiffWindowTestCase(tests.TestCaseWithTransport):
142
def test_get_button_bar_with_none(self):
143
window = DiffWindow()
144
self.assertIs(None, window._get_button_bar(None))
146
def test_get_button_bar_with_operations(self):
147
window = DiffWindow()
148
method = MockMethod()
149
button_bar = window._get_button_bar([('title', method)])
150
self.assertIsNot(None, button_bar)
151
buttons = button_bar.get_children()
152
self.assertEqual(1, len(buttons))
153
self.assertEqual('title', buttons[0].props.label)
154
buttons[0].emit('clicked')
155
self.assertIs(True, method.called)
94
158
class MockDiffWidget(object):
96
160
def set_diff_text_sections(self, sections):
303
368
[('a-id', 'a', 'removed', 'a'),
304
369
('b-id', 'b', 'removed', 'b/'),
372
def test_status_missing_file(self):
373
this = self.make_branch_and_tree('this')
374
self.build_tree(['this/foo'])
375
this.add(['foo'], ['foo-id'])
378
other = this.bzrdir.sprout('other').open_workingtree()
380
os.remove('this/foo')
381
this.remove('foo', force=True)
382
this.commit('remove')
384
f = open('other/foo', 'wt')
386
f.write('Modified\n')
389
other.commit('modified')
391
this.merge_from_branch(other.branch)
392
conflicts.resolve(this)
394
self.assertStatusEqual(
395
[('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
398
def test_status_missing_directory(self):
399
this = self.make_branch_and_tree('this')
400
self.build_tree(['this/foo/', 'this/foo/bar'])
401
this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
404
other = this.bzrdir.sprout('other').open_workingtree()
406
os.remove('this/foo/bar')
408
this.remove('foo', force=True)
409
this.commit('remove')
411
f = open('other/foo/bar', 'wt')
413
f.write('Modified\n')
416
other.commit('modified')
418
this.merge_from_branch(other.branch)
419
conflicts.resolve(this)
421
self.assertStatusEqual(
422
[('foo-id', u'foo', 'added', u'foo/'),
423
('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],