/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-01-23 17:04:56 UTC
  • mto: This revision was merged to the branch mainline in revision 772.
  • Revision ID: sinzui.is@verizon.net-20120123170456-09ci0chsm91yjfea
Do not update diff_view when the treeview is being destroyed.

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 bzrlib import (
 
22
    conflicts,
 
23
    errors,
 
24
    tests,
 
25
    )
 
26
try:
 
27
    from bzrlib.tests.features import UnicodeFilenameFeature
 
28
except ImportError: # bzr < 2.5
 
29
    from bzrlib.tests import UnicodeFilenameFeature
22
30
from bzrlib.merge_directive import MergeDirective2
23
31
 
24
32
from bzrlib.plugins.gtk.diff import (
25
33
    DiffController,
26
34
    DiffView,
 
35
    DiffWidget,
27
36
    iter_changes_to_status,
28
37
    MergeDirectiveController,
29
38
    )
 
39
from bzrlib.plugins.gtk.tests import MockMethod
 
40
 
 
41
 
30
42
eg_diff = """\
31
43
=== modified file 'tests/test_diff.py'
32
44
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
69
81
class TestDiffView(tests.TestCaseWithTransport):
70
82
 
71
83
    def test_unicode(self):
72
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
84
        self.requireFeature(UnicodeFilenameFeature)
73
85
 
74
86
        tree = self.make_branch_and_tree('tree')
75
87
        self.build_tree([u'tree/\u03a9'])
80
92
        view.show_diff(None)
81
93
        buf = view.buffer
82
94
        start, end = buf.get_bounds()
83
 
        text = buf.get_text(start, end)
 
95
        text = buf.get_text(start, end, True)
84
96
        self.assertContainsRe(text,
85
97
            "=== added file '\xce\xa9'\n"
86
98
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
91
103
            )
92
104
 
93
105
 
 
106
 
 
107
class FakeDiffWidget(DiffWidget):
 
108
 
 
109
    SHOW_WIDGETS = False
 
110
 
 
111
 
 
112
class TestDiffWidget(tests.TestCaseWithTransport):
 
113
 
 
114
    def test_treeview_cursor_cbd_with_destroyed_treeview(self):
 
115
        widget = FakeDiffWidget()
 
116
        widget.set_diff_text_sections([('a', None, 'patch')])
 
117
        MockMethod.bind(self, widget.diff_view, 'show_diff')
 
118
        widget.treeview.destroy()
 
119
        widget._treeview_cursor_cb(None)
 
120
        self.assertFalse(widget.diff_view.show_diff.called)
 
121
 
 
122
 
94
123
class MockDiffWidget(object):
95
124
 
96
125
    def set_diff_text_sections(self, sections):
98
127
 
99
128
 
100
129
class MockWindow(object):
 
130
 
101
131
    def __init__(self):
102
132
        self.diff = MockDiffWidget()
103
133
        self.merge_successful = False
303
333
            [('a-id', 'a', 'removed', 'a'),
304
334
             ('b-id', 'b', 'removed', 'b/'),
305
335
            ], tree)
 
336
 
 
337
    def test_status_missing_file(self):
 
338
        this = self.make_branch_and_tree('this')
 
339
        self.build_tree(['this/foo'])
 
340
        this.add(['foo'], ['foo-id'])
 
341
        this.commit('add')
 
342
 
 
343
        other = this.bzrdir.sprout('other').open_workingtree()
 
344
 
 
345
        os.remove('this/foo')
 
346
        this.remove('foo', force=True)
 
347
        this.commit('remove')
 
348
 
 
349
        f = open('other/foo', 'wt')
 
350
        try:
 
351
            f.write('Modified\n')
 
352
        finally:
 
353
            f.close()
 
354
        other.commit('modified')
 
355
 
 
356
        this.merge_from_branch(other.branch)
 
357
        conflicts.resolve(this)
 
358
 
 
359
        self.assertStatusEqual(
 
360
            [('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
 
361
            this)
 
362
 
 
363
    def test_status_missing_directory(self):
 
364
        this = self.make_branch_and_tree('this')
 
365
        self.build_tree(['this/foo/', 'this/foo/bar'])
 
366
        this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
 
367
        this.commit('add')
 
368
 
 
369
        other = this.bzrdir.sprout('other').open_workingtree()
 
370
 
 
371
        os.remove('this/foo/bar')
 
372
        os.rmdir('this/foo')
 
373
        this.remove('foo', force=True)
 
374
        this.commit('remove')
 
375
 
 
376
        f = open('other/foo/bar', 'wt')
 
377
        try:
 
378
            f.write('Modified\n')
 
379
        finally:
 
380
            f.close()
 
381
        other.commit('modified')
 
382
 
 
383
        this.merge_from_branch(other.branch)
 
384
        conflicts.resolve(this)
 
385
 
 
386
        self.assertStatusEqual(
 
387
            [('foo-id', u'foo', 'added', u'foo/'),
 
388
             ('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],
 
389
            this)