/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-03-09 13:47:52 UTC
  • mto: This revision was merged to the branch mainline in revision 447.
  • Revision ID: jelmer@samba.org-20080309134752-syf9kwzy6e919jhj
Add note about python-nautilus requiring a libpythonXX.so symlink.

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
 
92
69
            )
93
70
 
94
71
 
95
 
class MockDiffWidget(object):
96
 
 
97
 
    def set_diff_text_sections(self, sections):
98
 
        self.sections = list(sections)
99
 
 
100
 
 
101
 
class MockWindow(object):
102
 
    def __init__(self):
103
 
        self.diff = MockDiffWidget()
104
 
        self.merge_successful = False
105
 
 
106
 
    def set_title(self, title):
107
 
        self.title = title
108
 
 
109
 
    def _get_save_path(self, basename):
110
 
        return 'save-path'
111
 
 
112
 
    def _get_merge_target(self):
113
 
        return 'this'
114
 
 
115
 
    def destroy(self):
116
 
        pass
117
 
 
118
 
    def _merge_successful(self):
119
 
        self.merge_successful = True
120
 
 
121
 
    def _conflicts(self):
122
 
        self.conflicts = True
123
 
 
124
 
    def _handle_error(self, e):
125
 
        self.handled_error = e
126
 
 
127
 
 
128
 
class TestDiffController(tests.TestCaseWithTransport):
129
 
 
130
 
    def get_controller(self):
131
 
        window = MockWindow()
132
 
        return DiffController('load-path', eg_diff.splitlines(True), window)
133
 
 
134
 
    def test_get_diff_sections(self):
135
 
        controller = self.get_controller()
136
 
        controller = DiffController('.', eg_diff.splitlines(True),
137
 
                                    controller.window)
138
 
        sections = list(controller.get_diff_sections())
139
 
        self.assertEqual('Complete Diff', sections[0][0])
140
 
        self.assertIs(None, sections[0][1])
141
 
        self.assertEqual(eg_diff, sections[0][2])
142
 
 
143
 
        self.assertEqual('tests/test_diff.py', sections[1][0])
144
 
        self.assertEqual('tests/test_diff.py', sections[1][1])
145
 
        self.assertEqual(''.join(eg_diff.splitlines(True)[1:]),
146
 
                         sections[1][2])
147
 
 
148
 
    def test_initialize_window(self):
149
 
        controller = self.get_controller()
150
 
        controller.initialize_window(controller.window)
151
 
        self.assertEqual(2, len(controller.window.diff.sections))
152
 
        self.assertEqual('load-path - diff', controller.window.title)
153
 
 
154
 
    def test_perform_save(self):
155
 
        self.build_tree_contents([('load-path', 'foo')])
156
 
        controller = self.get_controller()
157
 
        controller.perform_save(None)
158
 
        self.assertFileEqual('foo', 'save-path')
159
 
 
160
 
 
161
 
class TestMergeDirectiveController(tests.TestCaseWithTransport):
162
 
 
163
 
    def make_this_other_directive(self):
164
 
        this = self.make_branch_and_tree('this')
165
 
        this.commit('first commit')
166
 
        other = this.bzrdir.sprout('other').open_workingtree()
167
 
        self.build_tree_contents([('other/foo', 'bar')])
168
 
        other.add('foo')
169
 
        other.commit('second commit')
170
 
        other.lock_write()
171
 
        try:
172
 
            directive = MergeDirective2.from_objects(other.branch.repository,
173
 
                                                     other.last_revision(), 0,
174
 
                                                     0, 'this')
175
 
        finally:
176
 
            other.unlock()
177
 
        return this, other, directive
178
 
 
179
 
    def make_merged_window(self, directive):
180
 
        window = MockWindow()
181
 
        controller = MergeDirectiveController('directive', directive, window)
182
 
        controller.perform_merge(window)
183
 
        return window
184
 
 
185
 
    def test_perform_merge_success(self):
186
 
        this, other, directive = self.make_this_other_directive()
187
 
        window = self.make_merged_window(directive)
188
 
        self.assertTrue(window.merge_successful)
189
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
190
 
        self.assertFileEqual('bar', 'this/foo')
191
 
 
192
 
    def test_perform_merge_conflicts(self):
193
 
        this, other, directive = self.make_this_other_directive()
194
 
        self.build_tree_contents([('this/foo', 'bar')])
195
 
        this.add('foo')
196
 
        this.commit('message')
197
 
        window = self.make_merged_window(directive)
198
 
        self.assertFalse(window.merge_successful)
199
 
        self.assertTrue(window.conflicts)
200
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
201
 
        self.assertFileEqual('bar', 'this/foo')
202
 
 
203
 
    def test_perform_merge_uncommitted_changes(self):
204
 
        this, other, directive = self.make_this_other_directive()
205
 
        self.build_tree_contents([('this/foo', 'bar')])
206
 
        this.add('foo')
207
 
        window = self.make_merged_window(directive)
208
 
        self.assertIsInstance(window.handled_error, errors.UncommittedChanges)
209
 
 
210
 
 
211
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
212
73
 
213
74
    def assertStatusEqual(self, expected, tree):
214
 
        values = iter_changes_to_status(tree.basis_tree(), tree)
 
75
        values = _iter_changes_to_status(tree.basis_tree(), tree)
215
76
        self.assertEqual(expected, values)
216
77
 
217
78
    def test_status_added(self):