18
18
from cStringIO import StringIO
21
from bzrlib import errors, tests
22
from bzrlib.merge_directive import MergeDirective2
24
from bzrlib.plugins.gtk.diff import (
27
iter_changes_to_status,
28
MergeDirectiveController,
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
36
from bzrlib import tests
38
-from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
39
+from bzrlib.plugins.gtk.diff import (
42
+ iter_changes_to_status,
46
class TestDiffViewSimple(tests.TestCase):
21
from bzrlib import tests
23
from bzrlib.plugins.gtk.diff import DiffView, _iter_changes_to_status
49
26
class TestDiffViewSimple(tests.TestCase):
95
class MockDiffWidget(object):
97
def set_diff_text_sections(self, sections):
98
self.sections = list(sections)
101
class MockWindow(object):
103
self.diff = MockDiffWidget()
104
self.merge_successful = False
106
def set_title(self, title):
109
def _get_save_path(self, basename):
112
def _get_merge_target(self):
118
def _merge_successful(self):
119
self.merge_successful = True
121
def _conflicts(self):
122
self.conflicts = True
124
def _handle_error(self, e):
125
self.handled_error = e
128
class TestDiffController(tests.TestCaseWithTransport):
130
def get_controller(self):
131
window = MockWindow()
132
return DiffController('load-path', eg_diff.splitlines(True), window)
134
def test_get_diff_sections(self):
135
controller = self.get_controller()
136
controller = DiffController('.', eg_diff.splitlines(True),
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])
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:]),
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)
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')
161
class TestMergeDirectiveController(tests.TestCaseWithTransport):
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')])
169
other.commit('second commit')
172
directive = MergeDirective2.from_objects(other.branch.repository,
173
other.last_revision(), 0,
177
return this, other, directive
179
def make_merged_window(self, directive):
180
window = MockWindow()
181
controller = MergeDirectiveController('directive', directive, window)
182
controller.perform_merge(window)
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')
192
def test_perform_merge_conflicts(self):
193
this, other, directive = self.make_this_other_directive()
194
self.build_tree_contents([('this/foo', 'bar')])
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')
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')])
207
window = self.make_merged_window(directive)
208
self.assertIsInstance(window.handled_error, errors.UncommittedChanges)
211
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
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)
217
78
def test_status_added(self):