/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 16:20:15 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629162015-amhe7xj4cdmup4id
Rename GtkProgressBarStack to GtkWindowProgressBarStack

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
27
    iter_changes_to_status,
39
28
    MergeDirectiveController,
40
29
    )
41
 
from bzrlib.plugins.gtk.tests import MockMethod
42
 
 
43
 
 
44
30
eg_diff = """\
45
31
=== modified file 'tests/test_diff.py'
46
32
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
83
69
class TestDiffView(tests.TestCaseWithTransport):
84
70
 
85
71
    def test_unicode(self):
86
 
        self.requireFeature(UnicodeFilenameFeature)
 
72
        self.requireFeature(tests.UnicodeFilenameFeature)
87
73
 
88
74
        tree = self.make_branch_and_tree('tree')
89
75
        self.build_tree([u'tree/\u03a9'])
94
80
        view.show_diff(None)
95
81
        buf = view.buffer
96
82
        start, end = buf.get_bounds()
97
 
        text = buf.get_text(start, end, True)
 
83
        text = buf.get_text(start, end)
98
84
        self.assertContainsRe(text,
99
85
            "=== added file '\xce\xa9'\n"
100
86
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
105
91
            )
106
92
 
107
93
 
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
 
 
134
94
class MockDiffWidget(object):
135
95
 
136
96
    def set_diff_text_sections(self, sections):
138
98
 
139
99
 
140
100
class MockWindow(object):
141
 
 
142
101
    def __init__(self):
143
102
        self.diff = MockDiffWidget()
144
103
        self.merge_successful = False
344
303
            [('a-id', 'a', 'removed', 'a'),
345
304
             ('b-id', 'b', 'removed', 'b/'),
346
305
            ], 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)