/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 21:15:32 UTC
  • mto: This revision was merged to the branch mainline in revision 774.
  • Revision ID: sinzui.is@verizon.net-20120203211532-8y0oo38120ys4em8
Added test for DiffWindow._get_button_bar.

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_get_button_bar_with_none(self):
 
143
        window = DiffWindow()
 
144
        self.assertIs(None, window._get_button_bar(None))
 
145
 
 
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)
 
156
 
 
157
 
94
158
class MockDiffWidget(object):
95
159
 
96
160
    def set_diff_text_sections(self, sections):
98
162
 
99
163
 
100
164
class MockWindow(object):
 
165
 
101
166
    def __init__(self):
102
167
        self.diff = MockDiffWidget()
103
168
        self.merge_successful = False
303
368
            [('a-id', 'a', 'removed', 'a'),
304
369
             ('b-id', 'b', 'removed', 'b/'),
305
370
            ], tree)
 
371
 
 
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'])
 
376
        this.commit('add')
 
377
 
 
378
        other = this.bzrdir.sprout('other').open_workingtree()
 
379
 
 
380
        os.remove('this/foo')
 
381
        this.remove('foo', force=True)
 
382
        this.commit('remove')
 
383
 
 
384
        f = open('other/foo', 'wt')
 
385
        try:
 
386
            f.write('Modified\n')
 
387
        finally:
 
388
            f.close()
 
389
        other.commit('modified')
 
390
 
 
391
        this.merge_from_branch(other.branch)
 
392
        conflicts.resolve(this)
 
393
 
 
394
        self.assertStatusEqual(
 
395
            [('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
 
396
            this)
 
397
 
 
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'])
 
402
        this.commit('add')
 
403
 
 
404
        other = this.bzrdir.sprout('other').open_workingtree()
 
405
 
 
406
        os.remove('this/foo/bar')
 
407
        os.rmdir('this/foo')
 
408
        this.remove('foo', force=True)
 
409
        this.commit('remove')
 
410
 
 
411
        f = open('other/foo/bar', 'wt')
 
412
        try:
 
413
            f.write('Modified\n')
 
414
        finally:
 
415
            f.close()
 
416
        other.commit('modified')
 
417
 
 
418
        this.merge_from_branch(other.branch)
 
419
        conflicts.resolve(this)
 
420
 
 
421
        self.assertStatusEqual(
 
422
            [('foo-id', u'foo', 'added', u'foo/'),
 
423
             ('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],
 
424
            this)