/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: Jelmer Vernooij
  • Date: 2008-06-29 19:07:23 UTC
  • mto: This revision was merged to the branch mainline in revision 515.
  • Revision ID: jelmer@samba.org-20080629190723-l8mzg9x4oec0lhsl
Return cleartext from seahorse module

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 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
 
21
from bzrlib import errors, tests
32
22
from bzrlib.merge_directive import MergeDirective2
33
23
 
34
24
from bzrlib.plugins.gtk.diff import (
35
25
    DiffController,
36
26
    DiffView,
37
 
    DiffWidget,
38
 
    DiffWindow,
39
27
    iter_changes_to_status,
40
28
    MergeDirectiveController,
41
29
    )
42
 
from bzrlib.plugins.gtk.tests import MockMethod
43
 
 
44
 
 
45
30
eg_diff = """\
46
31
=== modified file 'tests/test_diff.py'
47
32
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
84
69
class TestDiffView(tests.TestCaseWithTransport):
85
70
 
86
71
    def test_unicode(self):
87
 
        self.requireFeature(UnicodeFilenameFeature)
 
72
        self.requireFeature(tests.UnicodeFilenameFeature)
88
73
 
89
74
        tree = self.make_branch_and_tree('tree')
90
75
        self.build_tree([u'tree/\u03a9'])
95
80
        view.show_diff(None)
96
81
        buf = view.buffer
97
82
        start, end = buf.get_bounds()
98
 
        text = buf.get_text(start, end, True)
 
83
        text = buf.get_text(start, end)
99
84
        self.assertContainsRe(text,
100
85
            "=== added file '\xce\xa9'\n"
101
86
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
106
91
            )
107
92
 
108
93
 
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
 
 
194
94
class MockDiffWidget(object):
195
95
 
196
96
    def set_diff_text_sections(self, sections):
198
98
 
199
99
 
200
100
class MockWindow(object):
201
 
 
202
101
    def __init__(self):
203
102
        self.diff = MockDiffWidget()
204
103
        self.merge_successful = False
404
303
            [('a-id', 'a', 'removed', 'a'),
405
304
             ('b-id', 'b', 'removed', 'b/'),
406
305
            ], 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)