/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 18:03:33 UTC
  • mto: This revision was merged to the branch mainline in revision 772.
  • Revision ID: sinzui.is@verizon.net-20120123180333-b4gfaywl1280i3mg
Added test for success.

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, 'patch'), ('a', 'a', 'patch')])
 
120
        MockMethod.bind(self, widget.diff_view, 'show_diff')
 
121
        widget.treeview.set_cursor(Gtk.TreePath(path=1), None, False)
 
122
        widget._treeview_cursor_cb(None)
 
123
        self.assertTrue(widget.diff_view.show_diff.called)
 
124
        self.assertEqual((['a'],), widget.diff_view.show_diff.args)
 
125
 
 
126
    def test_treeview_cursor_cb_with_destroyed_treeview(self):
 
127
        widget = FakeDiffWidget()
 
128
        widget.set_diff_text_sections(
 
129
            [('', None, 'patch'), ('a', 'a', 'patch')])
 
130
        MockMethod.bind(self, widget.diff_view, 'show_diff')
 
131
        widget.treeview.destroy()
 
132
        widget._treeview_cursor_cb(None)
 
133
        self.assertFalse(widget.diff_view.show_diff.called)
 
134
 
 
135
 
94
136
class MockDiffWidget(object):
95
137
 
96
138
    def set_diff_text_sections(self, sections):
98
140
 
99
141
 
100
142
class MockWindow(object):
 
143
 
101
144
    def __init__(self):
102
145
        self.diff = MockDiffWidget()
103
146
        self.merge_successful = False
303
346
            [('a-id', 'a', 'removed', 'a'),
304
347
             ('b-id', 'b', 'removed', 'b/'),
305
348
            ], tree)
 
349
 
 
350
    def test_status_missing_file(self):
 
351
        this = self.make_branch_and_tree('this')
 
352
        self.build_tree(['this/foo'])
 
353
        this.add(['foo'], ['foo-id'])
 
354
        this.commit('add')
 
355
 
 
356
        other = this.bzrdir.sprout('other').open_workingtree()
 
357
 
 
358
        os.remove('this/foo')
 
359
        this.remove('foo', force=True)
 
360
        this.commit('remove')
 
361
 
 
362
        f = open('other/foo', 'wt')
 
363
        try:
 
364
            f.write('Modified\n')
 
365
        finally:
 
366
            f.close()
 
367
        other.commit('modified')
 
368
 
 
369
        this.merge_from_branch(other.branch)
 
370
        conflicts.resolve(this)
 
371
 
 
372
        self.assertStatusEqual(
 
373
            [('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
 
374
            this)
 
375
 
 
376
    def test_status_missing_directory(self):
 
377
        this = self.make_branch_and_tree('this')
 
378
        self.build_tree(['this/foo/', 'this/foo/bar'])
 
379
        this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
 
380
        this.commit('add')
 
381
 
 
382
        other = this.bzrdir.sprout('other').open_workingtree()
 
383
 
 
384
        os.remove('this/foo/bar')
 
385
        os.rmdir('this/foo')
 
386
        this.remove('foo', force=True)
 
387
        this.commit('remove')
 
388
 
 
389
        f = open('other/foo/bar', 'wt')
 
390
        try:
 
391
            f.write('Modified\n')
 
392
        finally:
 
393
            f.close()
 
394
        other.commit('modified')
 
395
 
 
396
        this.merge_from_branch(other.branch)
 
397
        conflicts.resolve(this)
 
398
 
 
399
        self.assertStatusEqual(
 
400
            [('foo-id', u'foo', 'added', u'foo/'),
 
401
             ('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],
 
402
            this)