/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 19:49:55 UTC
  • mto: This revision was merged to the branch mainline in revision 773.
  • Revision ID: sinzui.is@verizon.net-20120203194955-69jvr0mgu8igea0i
Updated bzr-notify to gtk3.

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,
27
38
    iter_changes_to_status,
28
39
    MergeDirectiveController,
29
40
    )
 
41
from bzrlib.plugins.gtk.tests import MockMethod
 
42
 
 
43
 
30
44
eg_diff = """\
31
45
=== modified file 'tests/test_diff.py'
32
46
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
69
83
class TestDiffView(tests.TestCaseWithTransport):
70
84
 
71
85
    def test_unicode(self):
72
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
86
        self.requireFeature(UnicodeFilenameFeature)
73
87
 
74
88
        tree = self.make_branch_and_tree('tree')
75
89
        self.build_tree([u'tree/\u03a9'])
80
94
        view.show_diff(None)
81
95
        buf = view.buffer
82
96
        start, end = buf.get_bounds()
83
 
        text = buf.get_text(start, end)
 
97
        text = buf.get_text(start, end, True)
84
98
        self.assertContainsRe(text,
85
99
            "=== added file '\xce\xa9'\n"
86
100
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
91
105
            )
92
106
 
93
107
 
 
108
 
 
109
class FakeDiffWidget(DiffWidget):
 
110
 
 
111
    SHOW_WIDGETS = False
 
112
 
 
113
 
 
114
class TestDiffWidget(tests.TestCaseWithTransport):
 
115
 
 
116
    def test_treeview_cursor_cb(self):
 
117
        widget = FakeDiffWidget()
 
118
        widget.set_diff_text_sections(
 
119
            [('', None, 'patch1'), ('a', 'a', 'patch2')])
 
120
        widget.treeview.set_cursor(Gtk.TreePath(path=1), None, False)
 
121
        widget._treeview_cursor_cb(None)
 
122
        self.assertTrue('patch2', widget.diff_view.buffer.props.text)
 
123
 
 
124
    def test_treeview_cursor_cb_with_destroyed_treeview(self):
 
125
        widget = FakeDiffWidget()
 
126
        widget.set_diff_text_sections(
 
127
            [('', None, 'patch1'), ('a', 'a', 'patch2')])
 
128
        MockMethod.bind(self, widget.diff_view, 'show_diff')
 
129
        widget.treeview.destroy()
 
130
        widget._treeview_cursor_cb(None)
 
131
        self.assertFalse(widget.diff_view.show_diff.called)
 
132
 
 
133
 
94
134
class MockDiffWidget(object):
95
135
 
96
136
    def set_diff_text_sections(self, sections):
98
138
 
99
139
 
100
140
class MockWindow(object):
 
141
 
101
142
    def __init__(self):
102
143
        self.diff = MockDiffWidget()
103
144
        self.merge_successful = False
303
344
            [('a-id', 'a', 'removed', 'a'),
304
345
             ('b-id', 'b', 'removed', 'b/'),
305
346
            ], tree)
 
347
 
 
348
    def test_status_missing_file(self):
 
349
        this = self.make_branch_and_tree('this')
 
350
        self.build_tree(['this/foo'])
 
351
        this.add(['foo'], ['foo-id'])
 
352
        this.commit('add')
 
353
 
 
354
        other = this.bzrdir.sprout('other').open_workingtree()
 
355
 
 
356
        os.remove('this/foo')
 
357
        this.remove('foo', force=True)
 
358
        this.commit('remove')
 
359
 
 
360
        f = open('other/foo', 'wt')
 
361
        try:
 
362
            f.write('Modified\n')
 
363
        finally:
 
364
            f.close()
 
365
        other.commit('modified')
 
366
 
 
367
        this.merge_from_branch(other.branch)
 
368
        conflicts.resolve(this)
 
369
 
 
370
        self.assertStatusEqual(
 
371
            [('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
 
372
            this)
 
373
 
 
374
    def test_status_missing_directory(self):
 
375
        this = self.make_branch_and_tree('this')
 
376
        self.build_tree(['this/foo/', 'this/foo/bar'])
 
377
        this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
 
378
        this.commit('add')
 
379
 
 
380
        other = this.bzrdir.sprout('other').open_workingtree()
 
381
 
 
382
        os.remove('this/foo/bar')
 
383
        os.rmdir('this/foo')
 
384
        this.remove('foo', force=True)
 
385
        this.commit('remove')
 
386
 
 
387
        f = open('other/foo/bar', 'wt')
 
388
        try:
 
389
            f.write('Modified\n')
 
390
        finally:
 
391
            f.close()
 
392
        other.commit('modified')
 
393
 
 
394
        this.merge_from_branch(other.branch)
 
395
        conflicts.resolve(this)
 
396
 
 
397
        self.assertStatusEqual(
 
398
            [('foo-id', u'foo', 'added', u'foo/'),
 
399
             ('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],
 
400
            this)