/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
  • Author(s): Chris Lamb
  • Date: 2008-05-01 13:00:15 UTC
  • mto: This revision was merged to the branch mainline in revision 482.
  • Revision ID: jelmer@samba.org-20080501130015-lmn22j03044vqngp
Set suitable FDO categories in .desktop files

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
22
 
from bzrlib.merge_directive import MergeDirective2
23
 
 
24
 
from bzrlib.plugins.gtk.diff import (
25
 
    DiffController,
26
 
    DiffView,
27
 
    iter_changes_to_status,
28
 
    MergeDirectiveController,
29
 
    )
30
 
eg_diff = """\
31
 
=== modified file 'tests/test_diff.py'
32
 
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
33
 
+++ tests/test_diff.py  2008-05-08 22:44:02 +0000
34
 
@@ -20,7 +20,11 @@
35
 
 
36
 
 from bzrlib import tests
37
 
 
38
 
-from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
39
 
+from bzrlib.plugins.gtk.diff import (
40
 
+    DiffController,
41
 
+    DiffView,
42
 
+    iter_changes_to_status,
43
 
+    )
44
 
 
45
 
 
46
 
 class TestDiffViewSimple(tests.TestCase):
47
 
"""
 
21
from bzrlib import tests
 
22
 
 
23
from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
 
24
 
48
25
 
49
26
class TestDiffViewSimple(tests.TestCase):
50
27
 
69
46
class TestDiffView(tests.TestCaseWithTransport):
70
47
 
71
48
    def test_unicode(self):
72
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
49
        from bzrlib.tests.test_diff import UnicodeFilename
 
50
        self.requireFeature(UnicodeFilename)
73
51
 
74
52
        tree = self.make_branch_and_tree('tree')
75
53
        self.build_tree([u'tree/\u03a9'])
91
69
            )
92
70
 
93
71
 
94
 
class MockDiffWidget(object):
95
 
 
96
 
    def set_diff_text_sections(self, sections):
97
 
        self.sections = list(sections)
98
 
 
99
 
 
100
 
class MockWindow(object):
101
 
    def __init__(self):
102
 
        self.diff = MockDiffWidget()
103
 
        self.merge_successful = False
104
 
 
105
 
    def set_title(self, title):
106
 
        self.title = title
107
 
 
108
 
    def _get_save_path(self, basename):
109
 
        return 'save-path'
110
 
 
111
 
    def _get_merge_target(self):
112
 
        return 'this'
113
 
 
114
 
    def destroy(self):
115
 
        pass
116
 
 
117
 
    def _merge_successful(self):
118
 
        self.merge_successful = True
119
 
 
120
 
    def _conflicts(self):
121
 
        self.conflicts = True
122
 
 
123
 
    def _handle_error(self, e):
124
 
        self.handled_error = e
125
 
 
126
 
 
127
 
class TestDiffController(tests.TestCaseWithTransport):
128
 
 
129
 
    def get_controller(self):
130
 
        window = MockWindow()
131
 
        return DiffController('load-path', eg_diff.splitlines(True), window)
132
 
 
133
 
    def test_get_diff_sections(self):
134
 
        controller = self.get_controller()
135
 
        controller = DiffController('.', eg_diff.splitlines(True),
136
 
                                    controller.window)
137
 
        sections = list(controller.get_diff_sections())
138
 
        self.assertEqual('Complete Diff', sections[0][0])
139
 
        self.assertIs(None, sections[0][1])
140
 
        self.assertEqual(eg_diff, sections[0][2])
141
 
 
142
 
        self.assertEqual('tests/test_diff.py', sections[1][0])
143
 
        self.assertEqual('tests/test_diff.py', sections[1][1])
144
 
        self.assertEqual(''.join(eg_diff.splitlines(True)[1:]),
145
 
                         sections[1][2])
146
 
 
147
 
    def test_initialize_window(self):
148
 
        controller = self.get_controller()
149
 
        controller.initialize_window(controller.window)
150
 
        self.assertEqual(2, len(controller.window.diff.sections))
151
 
        self.assertEqual('load-path - diff', controller.window.title)
152
 
 
153
 
    def test_perform_save(self):
154
 
        self.build_tree_contents([('load-path', 'foo')])
155
 
        controller = self.get_controller()
156
 
        controller.perform_save(None)
157
 
        self.assertFileEqual('foo', 'save-path')
158
 
 
159
 
 
160
 
class TestMergeDirectiveController(tests.TestCaseWithTransport):
161
 
 
162
 
    def make_this_other_directive(self):
163
 
        this = self.make_branch_and_tree('this')
164
 
        this.commit('first commit')
165
 
        other = this.bzrdir.sprout('other').open_workingtree()
166
 
        self.build_tree_contents([('other/foo', 'bar')])
167
 
        other.add('foo')
168
 
        other.commit('second commit')
169
 
        other.lock_write()
170
 
        try:
171
 
            directive = MergeDirective2.from_objects(other.branch.repository,
172
 
                                                     other.last_revision(), 0,
173
 
                                                     0, 'this')
174
 
        finally:
175
 
            other.unlock()
176
 
        return this, other, directive
177
 
 
178
 
    def make_merged_window(self, directive):
179
 
        window = MockWindow()
180
 
        controller = MergeDirectiveController('directive', directive, window)
181
 
        controller.perform_merge(window)
182
 
        return window
183
 
 
184
 
    def test_perform_merge_success(self):
185
 
        this, other, directive = self.make_this_other_directive()
186
 
        window = self.make_merged_window(directive)
187
 
        self.assertTrue(window.merge_successful)
188
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
189
 
        self.assertFileEqual('bar', 'this/foo')
190
 
 
191
 
    def test_perform_merge_conflicts(self):
192
 
        this, other, directive = self.make_this_other_directive()
193
 
        self.build_tree_contents([('this/foo', 'bar')])
194
 
        this.add('foo')
195
 
        this.commit('message')
196
 
        window = self.make_merged_window(directive)
197
 
        self.assertFalse(window.merge_successful)
198
 
        self.assertTrue(window.conflicts)
199
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
200
 
        self.assertFileEqual('bar', 'this/foo')
201
 
 
202
 
    def test_perform_merge_uncommitted_changes(self):
203
 
        this, other, directive = self.make_this_other_directive()
204
 
        self.build_tree_contents([('this/foo', 'bar')])
205
 
        this.add('foo')
206
 
        window = self.make_merged_window(directive)
207
 
        self.assertIsInstance(window.handled_error, errors.UncommittedChanges)
208
 
 
209
 
 
210
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
211
73
 
212
74
    def assertStatusEqual(self, expected, tree):