98
class MockDiffWidget(object):
100
def set_diff_text_sections(self, sections):
101
self.sections = list(sections)
104
class MockWindow(object):
107
self.diff = MockDiffWidget()
108
self.merge_successful = False
110
def set_title(self, title):
113
def _get_save_path(self, basename):
116
def _get_merge_target(self):
122
def _merge_successful(self):
123
self.merge_successful = True
125
def _conflicts(self):
126
self.conflicts = True
128
def _handle_error(self, e):
129
self.handled_error = e
132
class TestDiffController(tests.TestCaseWithTransport):
134
def get_controller(self):
135
window = MockWindow()
136
return DiffController('load-path', eg_diff.splitlines(True), window)
138
def test_get_diff_sections(self):
139
controller = self.get_controller()
140
controller = DiffController('.', eg_diff.splitlines(True),
142
sections = list(controller.get_diff_sections())
143
self.assertEqual('Complete Diff', sections[0][0])
144
self.assertIs(None, sections[0][1])
145
self.assertEqual(eg_diff, sections[0][2])
147
self.assertEqual('tests/test_diff.py', sections[1][0])
148
self.assertEqual('tests/test_diff.py', sections[1][1])
149
self.assertEqual(''.join(eg_diff.splitlines(True)[1:]),
152
def test_initialize_window(self):
153
controller = self.get_controller()
154
controller.initialize_window(controller.window)
155
self.assertEqual(2, len(controller.window.diff.sections))
156
self.assertEqual('load-path - diff', controller.window.title)
158
def test_perform_save(self):
159
self.build_tree_contents([('load-path', 'foo')])
160
controller = self.get_controller()
161
controller.perform_save(None)
162
self.assertFileEqual('foo', 'save-path')
165
class TestMergeDirectiveController(tests.TestCaseWithTransport):
167
def make_this_other_directive(self):
168
this = self.make_branch_and_tree('this')
169
this.commit('first commit')
170
other = this.bzrdir.sprout('other').open_workingtree()
171
self.build_tree_contents([('other/foo', 'bar')])
173
other.commit('second commit')
176
directive = MergeDirective2.from_objects(other.branch.repository,
177
other.last_revision(), 0,
181
return this, other, directive
183
def make_merged_window(self, directive):
184
window = MockWindow()
185
controller = MergeDirectiveController('directive', directive, window)
186
controller.perform_merge(window)
189
def test_perform_merge_success(self):
190
this, other, directive = self.make_this_other_directive()
191
window = self.make_merged_window(directive)
192
self.assertTrue(window.merge_successful)
193
self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
194
self.assertFileEqual('bar', 'this/foo')
196
def test_perform_merge_conflicts(self):
197
this, other, directive = self.make_this_other_directive()
198
self.build_tree_contents([('this/foo', 'bar')])
200
this.commit('message')
201
window = self.make_merged_window(directive)
202
self.assertFalse(window.merge_successful)
203
self.assertTrue(window.conflicts)
204
self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
205
self.assertFileEqual('bar', 'this/foo')
207
def test_perform_merge_uncommitted_changes(self):
208
this, other, directive = self.make_this_other_directive()
209
self.build_tree_contents([('this/foo', 'bar')])
211
window = self.make_merged_window(directive)
212
self.assertIsInstance(window.handled_error, errors.UncommittedChanges)
215
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
217
74
def assertStatusEqual(self, expected, tree):
218
values = iter_changes_to_status(tree.basis_tree(), tree)
75
values = _iter_changes_to_status(tree.basis_tree(), tree)
219
76
self.assertEqual(expected, values)
221
78
def test_status_added(self):
308
165
[('a-id', 'a', 'removed', 'a'),
309
166
('b-id', 'b', 'removed', 'b/'),
312
def test_status_missing_file(self):
313
this = self.make_branch_and_tree('this')
314
self.build_tree(['this/foo'])
315
this.add(['foo'], ['foo-id'])
318
other = this.bzrdir.sprout('other').open_workingtree()
320
os.remove('this/foo')
321
this.remove('foo', force=True)
322
this.commit('remove')
324
f = open('other/foo', 'wt')
326
f.write('Modified\n')
329
other.commit('modified')
331
this.merge_from_branch(other.branch)
332
conflicts.resolve(this)
334
self.assertStatusEqual(
335
[('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),],
338
def test_status_missing_directory(self):
339
this = self.make_branch_and_tree('this')
340
self.build_tree(['this/foo/', 'this/foo/bar'])
341
this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
344
other = this.bzrdir.sprout('other').open_workingtree()
346
os.remove('this/foo/bar')
348
this.remove('foo', force=True)
349
this.commit('remove')
351
f = open('other/foo/bar', 'wt')
353
f.write('Modified\n')
356
other.commit('modified')
358
this.merge_from_branch(other.branch)
359
conflicts.resolve(this)
361
self.assertStatusEqual(
362
[('foo-id', u'foo', 'added', u'foo/'),
363
('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),],