/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_diff.py

  • Committer: Curtis Hovey
  • Date: 2012-02-03 22:55:40 UTC
  • mto: This revision was merged to the branch mainline in revision 774.
  • Revision ID: sinzui.is@verizon.net-20120203225540-wg553pau7kjihy2k
Added a smoketest for bzr-handle-patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
import os
20
20
 
21
 
from bzrlib import errors, tests
 
21
from gi.repository import Gtk
 
22
 
 
23
from bzrlib import (
 
24
    conflicts,
 
25
    errors,
 
26
    tests,
 
27
    )
 
28
try:
 
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
23
33
 
24
34
from bzrlib.plugins.gtk.diff import (
25
35
    DiffController,
26
36
    DiffView,
 
37
    DiffWidget,
 
38
    DiffWindow,
27
39
    iter_changes_to_status,
28
40
    MergeDirectiveController,
29
41
    )
 
42
from bzrlib.plugins.gtk.tests import MockMethod
 
43
 
 
44
 
30
45
eg_diff = """\
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):
70
85
 
71
86
    def test_unicode(self):
72
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
87
        self.requireFeature(UnicodeFilenameFeature)
73
88
 
74
89
        tree = self.make_branch_and_tree('tree')
75
90
        self.build_tree([u'tree/\u03a9'])
80
95
        view.show_diff(None)
81
96
        buf = view.buffer
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'
91
106
            )
92
107
 
93
108
 
 
109
 
 
110
class FakeDiffWidget(DiffWidget):
 
111
 
 
112
    SHOW_WIDGETS = False
 
113
 
 
114
 
 
115
class TestDiffWidget(tests.TestCaseWithTransport):
 
116
 
 
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)
 
124
 
 
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)
 
133
 
 
134
 
 
135
class FakeDiffWindow(DiffWindow):
 
136
 
 
137
    SHOW_WIDGETS = False
 
138
 
 
139
 
 
140
class DiffWindowTestCase(tests.TestCaseWithTransport):
 
141
 
 
142
    def test_init(self):
 
143
        window = DiffWindow()
 
144
        self.assertEqual('bzr diff', window.props.title)
 
145
        self.assertEqual(0, window.props.border_width)
 
146
 
 
147
    def test_init_construct_without_operations(self):
 
148
        window = DiffWindow()
 
149
        widgets = window.vbox.get_children()
 
150
        self.assertEqual(2, len(widgets))
 
151
        self.assertIsInstance(widgets[0], Gtk.MenuBar)
 
152
        self.assertIsInstance(widgets[1], DiffWidget)
 
153
 
 
154
    def test_init_construct_with_operations(self):
 
155
        method = MockMethod()
 
156
        window = DiffWindow(operations=[('title', method)])
 
157
        widgets = window.vbox.get_children()
 
158
        self.assertEqual(3, len(widgets))
 
159
        self.assertIsInstance(widgets[0], Gtk.MenuBar)
 
160
        self.assertIsInstance(widgets[1], Gtk.HButtonBox)
 
161
        self.assertIsInstance(widgets[2], DiffWidget)
 
162
 
 
163
    def test_get_menu_bar(self):
 
164
        window = DiffWindow()
 
165
        menu_bar = window._get_menu_bar()
 
166
        self.assertIsNot(None, menu_bar)
 
167
        menus = menu_bar.get_children()
 
168
        self.assertEqual(1, len(menus))
 
169
        self.assertEqual('_View', menus[0].props.label)
 
170
        sub_menu = menus[0].get_submenu()
 
171
        self.assertIsNot(None, sub_menu)
 
172
        items = sub_menu.get_children()
 
173
        self.assertEqual(1, len(items))
 
174
        menus[0].get_submenu().get_children()[0].props.label
 
175
        self.assertEqual('Wrap _Long Lines', items[0].props.label)
 
176
 
 
177
    def test_get_button_bar_with_none(self):
 
178
        window = DiffWindow()
 
179
        self.assertIs(None, window._get_button_bar(None))
 
180
 
 
181
    def test_get_button_bar_with_operations(self):
 
182
        window = DiffWindow()
 
183
        method = MockMethod()
 
184
        button_bar = window._get_button_bar([('title', method)])
 
185
        self.assertIsNot(None, button_bar)
 
186
        buttons = button_bar.get_children()
 
187
        self.assertEqual(1, len(buttons))
 
188
        self.assertEqual('title', buttons[0].props.label)
 
189
        buttons[0].emit('clicked')
 
190
        self.assertIs(True, method.called)
 
191
 
 
192
 
 
193
 
94
194
class MockDiffWidget(object):
95
195
 
96
196
    def set_diff_text_sections(self, sections):
98
198
 
99
199
 
100
200
class MockWindow(object):
 
201
 
101
202
    def __init__(self):
102
203
        self.diff = MockDiffWidget()
103
204
        self.merge_successful = False
303
404
            [('a-id', 'a', 'removed', 'a'),
304
405
             ('b-id', 'b', 'removed', 'b/'),
305
406
            ], tree)
 
407
 
 
408
    def test_status_missing_file(self):
 
409
        this = self.make_branch_and_tree('this')
 
410
        self.build_tree(['this/foo'])
 
411
        this.add(['foo'], ['foo-id'])
 
412
        this.commit('add')
 
413
 
 
414
        other = this.bzrdir.sprout('other').open_workingtree()
 
415
 
 
416
        os.remove('this/foo')
 
417
        this.remove('foo', force=True)
 
418
        this.commit('remove')
 
419
 
 
420
        f = open('other/foo', 'wt')
 
421
        try:
 
422
            f.write('Modified\n')
 
423
        finally:
 
424
            f.close()
 
425
        other.commit('modified')
 
426
 
 
427
        this.merge_from_branch(other.branch)
 
428
        conflicts.resolve(this)
 
429
 
 
430
        self.assertStatusEqual(
 
431
            [('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
 
432
            this)
 
433
 
 
434
    def test_status_missing_directory(self):
 
435
        this = self.make_branch_and_tree('this')
 
436
        self.build_tree(['this/foo/', 'this/foo/bar'])
 
437
        this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
 
438
        this.commit('add')
 
439
 
 
440
        other = this.bzrdir.sprout('other').open_workingtree()
 
441
 
 
442
        os.remove('this/foo/bar')
 
443
        os.rmdir('this/foo')
 
444
        this.remove('foo', force=True)
 
445
        this.commit('remove')
 
446
 
 
447
        f = open('other/foo/bar', 'wt')
 
448
        try:
 
449
            f.write('Modified\n')
 
450
        finally:
 
451
            f.close()
 
452
        other.commit('modified')
 
453
 
 
454
        this.merge_from_branch(other.branch)
 
455
        conflicts.resolve(this)
 
456
 
 
457
        self.assertStatusEqual(
 
458
            [('foo-id', u'foo', 'added', u'foo/'),
 
459
             ('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],
 
460
            this)