bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
|
232.1.4
by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines. |
1 |
# -*- coding: utf-8 -*-
|
2 |
# Copyright (C) 2007 Adeodato Simó <dato@net.com.org.es>
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 |
||
18 |
from cStringIO import StringIO |
|
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
19 |
import os |
|
232.1.4
by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines. |
20 |
|
|
613.1.1
by Vincent Ladeuil
Fix bug #286834 bu handling 'missing' files corner case. |
21 |
from bzrlib import ( |
22 |
conflicts, |
|
23 |
errors, |
|
24 |
tests, |
|
25 |
)
|
|
|
737
by Jelmer Vernooij
Support new location of UnicodeFilenameFeature in 2.5. |
26 |
try: |
27 |
from bzrlib.tests.features import UnicodeFilenameFeature |
|
28 |
except ImportError: # bzr < 2.5 |
|
29 |
from bzrlib.tests import UnicodeFilenameFeature |
|
|
493.1.1
by Aaron Bentley
Work around bug for old merge directives in bzr.dev |
30 |
from bzrlib.merge_directive import MergeDirective2 |
|
278.1.13
by John Arbash Meinel
minor cleanup |
31 |
|
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
32 |
from bzrlib.plugins.gtk.diff import ( |
33 |
DiffController, |
|
34 |
DiffView, |
|
|
771.1.4
by Curtis Hovey
Do not update diff_view when the treeview is being destroyed. |
35 |
DiffWidget, |
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
36 |
iter_changes_to_status, |
|
487.2.5
by Aaron Bentley
Test successful merge |
37 |
MergeDirectiveController, |
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
38 |
)
|
|
771.1.4
by Curtis Hovey
Do not update diff_view when the treeview is being destroyed. |
39 |
from bzrlib.plugins.gtk.tests import MockMethod |
40 |
||
41 |
||
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
42 |
eg_diff = """\ |
43 |
=== modified file 'tests/test_diff.py'
|
|
44 |
--- tests/test_diff.py 2008-03-11 13:18:28 +0000
|
|
45 |
+++ tests/test_diff.py 2008-05-08 22:44:02 +0000
|
|
46 |
@@ -20,7 +20,11 @@
|
|
47 |
|
|
48 |
from bzrlib import tests
|
|
49 |
|
|
50 |
-from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
|
|
51 |
+from bzrlib.plugins.gtk.diff import (
|
|
52 |
+ DiffController,
|
|
53 |
+ DiffView,
|
|
54 |
+ iter_changes_to_status,
|
|
55 |
+ )
|
|
56 |
|
|
57 |
|
|
58 |
class TestDiffViewSimple(tests.TestCase):
|
|
59 |
"""
|
|
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
60 |
|
61 |
class TestDiffViewSimple(tests.TestCase): |
|
|
278.1.13
by John Arbash Meinel
minor cleanup |
62 |
|
|
232.1.4
by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines. |
63 |
def test_parse_colordiffrc(self): |
64 |
colordiffrc = '''\ |
|
65 |
newtext=blue
|
|
66 |
oldtext = Red
|
|
67 |
# now a comment and a blank line
|
|
68 |
||
69 |
diffstuff = #ffff00
|
|
70 |
# another comment preceded by whitespace
|
|
71 |
'''
|
|
72 |
colors = { |
|
73 |
'newtext': 'blue', |
|
74 |
'oldtext': 'Red', |
|
75 |
'diffstuff': '#ffff00', |
|
76 |
}
|
|
|
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
77 |
parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc)) |
|
232.1.4
by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines. |
78 |
self.assertEqual(colors, parsed_colors) |
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
79 |
|
80 |
||
81 |
class TestDiffView(tests.TestCaseWithTransport): |
|
82 |
||
83 |
def test_unicode(self): |
|
|
737
by Jelmer Vernooij
Support new location of UnicodeFilenameFeature in 2.5. |
84 |
self.requireFeature(UnicodeFilenameFeature) |
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
85 |
|
86 |
tree = self.make_branch_and_tree('tree') |
|
87 |
self.build_tree([u'tree/\u03a9']) |
|
88 |
tree.add([u'\u03a9'], ['omega-id']) |
|
89 |
||
90 |
view = DiffView() |
|
91 |
view.set_trees(tree, tree.basis_tree()) |
|
92 |
view.show_diff(None) |
|
93 |
buf = view.buffer |
|
94 |
start, end = buf.get_bounds() |
|
|
734.1.7
by Curtis Hovey
Updated buffer.getText() calls and ModifierType enums. |
95 |
text = buf.get_text(start, end, True) |
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
96 |
self.assertContainsRe(text, |
97 |
"=== added file '\xce\xa9'\n" |
|
98 |
'--- .*\t1970-01-01 00:00:00 \\+0000\n' |
|
99 |
r'\+\+\+ .*\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d\n' |
|
100 |
'@@ -0,0 \\+1,1 @@\n' |
|
101 |
'\\+contents of tree/\xce\xa9\n' |
|
102 |
'\n' |
|
103 |
)
|
|
104 |
||
105 |
||
|
771.1.4
by Curtis Hovey
Do not update diff_view when the treeview is being destroyed. |
106 |
|
107 |
class FakeDiffWidget(DiffWidget): |
|
108 |
||
109 |
SHOW_WIDGETS = False |
|
110 |
||
111 |
||
112 |
class TestDiffWidget(tests.TestCaseWithTransport): |
|
113 |
||
114 |
def test_treeview_cursor_cbd_with_destroyed_treeview(self): |
|
115 |
widget = FakeDiffWidget() |
|
116 |
widget.set_diff_text_sections([('a', None, 'patch')]) |
|
117 |
MockMethod.bind(self, widget.diff_view, 'show_diff') |
|
118 |
widget.treeview.destroy() |
|
119 |
widget._treeview_cursor_cb(None) |
|
120 |
self.assertFalse(widget.diff_view.show_diff.called) |
|
121 |
||
122 |
||
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
123 |
class MockDiffWidget(object): |
124 |
||
125 |
def set_diff_text_sections(self, sections): |
|
126 |
self.sections = list(sections) |
|
127 |
||
128 |
||
129 |
class MockWindow(object): |
|
|
713
by Jelmer Vernooij
Remove some unused imports, fix some formatting. |
130 |
|
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
131 |
def __init__(self): |
132 |
self.diff = MockDiffWidget() |
|
|
487.2.7
by Aaron Bentley
Add more merge tests |
133 |
self.merge_successful = False |
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
134 |
|
135 |
def set_title(self, title): |
|
136 |
self.title = title |
|
137 |
||
138 |
def _get_save_path(self, basename): |
|
139 |
return 'save-path' |
|
140 |
||
|
487.2.5
by Aaron Bentley
Test successful merge |
141 |
def _get_merge_target(self): |
|
487.2.6
by Aaron Bentley
Ensure MergeController sets pending merges and updates files |
142 |
return 'this' |
|
487.2.5
by Aaron Bentley
Test successful merge |
143 |
|
144 |
def destroy(self): |
|
145 |
pass
|
|
146 |
||
147 |
def _merge_successful(self): |
|
148 |
self.merge_successful = True |
|
149 |
||
|
487.2.7
by Aaron Bentley
Add more merge tests |
150 |
def _conflicts(self): |
151 |
self.conflicts = True |
|
152 |
||
|
487.2.8
by Aaron Bentley
Update error handling to use window |
153 |
def _handle_error(self, e): |
154 |
self.handled_error = e |
|
155 |
||
|
487.2.4
by Aaron Bentley
Add tests for DiffController |
156 |
|
157 |
class TestDiffController(tests.TestCaseWithTransport): |
|
158 |
||
159 |
def get_controller(self): |
|
160 |
window = MockWindow() |
|
161 |
return DiffController('load-path', eg_diff.splitlines(True), window) |
|
162 |
||
163 |
def test_get_diff_sections(self): |
|
164 |
controller = self.get_controller() |
|
165 |
controller = DiffController('.', eg_diff.splitlines(True), |
|
166 |
controller.window) |
|
167 |
sections = list(controller.get_diff_sections()) |
|
168 |
self.assertEqual('Complete Diff', sections[0][0]) |
|
169 |
self.assertIs(None, sections[0][1]) |
|
170 |
self.assertEqual(eg_diff, sections[0][2]) |
|
171 |
||
172 |
self.assertEqual('tests/test_diff.py', sections[1][0]) |
|
173 |
self.assertEqual('tests/test_diff.py', sections[1][1]) |
|
174 |
self.assertEqual(''.join(eg_diff.splitlines(True)[1:]), |
|
175 |
sections[1][2]) |
|
176 |
||
177 |
def test_initialize_window(self): |
|
178 |
controller = self.get_controller() |
|
179 |
controller.initialize_window(controller.window) |
|
180 |
self.assertEqual(2, len(controller.window.diff.sections)) |
|
181 |
self.assertEqual('load-path - diff', controller.window.title) |
|
182 |
||
183 |
def test_perform_save(self): |
|
184 |
self.build_tree_contents([('load-path', 'foo')]) |
|
185 |
controller = self.get_controller() |
|
186 |
controller.perform_save(None) |
|
187 |
self.assertFileEqual('foo', 'save-path') |
|
188 |
||
189 |
||
|
487.2.5
by Aaron Bentley
Test successful merge |
190 |
class TestMergeDirectiveController(tests.TestCaseWithTransport): |
191 |
||
|
487.2.7
by Aaron Bentley
Add more merge tests |
192 |
def make_this_other_directive(self): |
|
487.2.5
by Aaron Bentley
Test successful merge |
193 |
this = self.make_branch_and_tree('this') |
194 |
this.commit('first commit') |
|
195 |
other = this.bzrdir.sprout('other').open_workingtree() |
|
|
487.2.7
by Aaron Bentley
Add more merge tests |
196 |
self.build_tree_contents([('other/foo', 'bar')]) |
197 |
other.add('foo') |
|
|
487.2.5
by Aaron Bentley
Test successful merge |
198 |
other.commit('second commit') |
199 |
other.lock_write() |
|
200 |
try: |
|
|
493.1.1
by Aaron Bentley
Work around bug for old merge directives in bzr.dev |
201 |
directive = MergeDirective2.from_objects(other.branch.repository, |
202 |
other.last_revision(), 0, |
|
203 |
0, 'this') |
|
|
487.2.5
by Aaron Bentley
Test successful merge |
204 |
finally: |
205 |
other.unlock() |
|
|
487.2.7
by Aaron Bentley
Add more merge tests |
206 |
return this, other, directive |
207 |
||
208 |
def make_merged_window(self, directive): |
|
|
487.2.5
by Aaron Bentley
Test successful merge |
209 |
window = MockWindow() |
210 |
controller = MergeDirectiveController('directive', directive, window) |
|
211 |
controller.perform_merge(window) |
|
|
487.2.7
by Aaron Bentley
Add more merge tests |
212 |
return window |
213 |
||
214 |
def test_perform_merge_success(self): |
|
215 |
this, other, directive = self.make_this_other_directive() |
|
216 |
window = self.make_merged_window(directive) |
|
|
487.2.5
by Aaron Bentley
Test successful merge |
217 |
self.assertTrue(window.merge_successful) |
|
487.2.6
by Aaron Bentley
Ensure MergeController sets pending merges and updates files |
218 |
self.assertEqual(other.last_revision(), this.get_parent_ids()[1]) |
|
487.2.7
by Aaron Bentley
Add more merge tests |
219 |
self.assertFileEqual('bar', 'this/foo') |
220 |
||
221 |
def test_perform_merge_conflicts(self): |
|
222 |
this, other, directive = self.make_this_other_directive() |
|
223 |
self.build_tree_contents([('this/foo', 'bar')]) |
|
224 |
this.add('foo') |
|
225 |
this.commit('message') |
|
226 |
window = self.make_merged_window(directive) |
|
227 |
self.assertFalse(window.merge_successful) |
|
228 |
self.assertTrue(window.conflicts) |
|
229 |
self.assertEqual(other.last_revision(), this.get_parent_ids()[1]) |
|
230 |
self.assertFileEqual('bar', 'this/foo') |
|
|
487.2.5
by Aaron Bentley
Test successful merge |
231 |
|
|
487.2.8
by Aaron Bentley
Update error handling to use window |
232 |
def test_perform_merge_uncommitted_changes(self): |
233 |
this, other, directive = self.make_this_other_directive() |
|
234 |
self.build_tree_contents([('this/foo', 'bar')]) |
|
235 |
this.add('foo') |
|
236 |
window = self.make_merged_window(directive) |
|
237 |
self.assertIsInstance(window.handled_error, errors.UncommittedChanges) |
|
238 |
||
|
487.2.5
by Aaron Bentley
Test successful merge |
239 |
|
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
240 |
class Test_IterChangesToStatus(tests.TestCaseWithTransport): |
241 |
||
242 |
def assertStatusEqual(self, expected, tree): |
|
|
450
by Aaron Bentley
Update to use new Tree.iter_changes |
243 |
values = iter_changes_to_status(tree.basis_tree(), tree) |
|
278.1.29
by John Arbash Meinel
Start testing with Unicode data. |
244 |
self.assertEqual(expected, values) |
245 |
||
246 |
def test_status_added(self): |
|
247 |
tree = self.make_branch_and_tree('tree') |
|
248 |
self.build_tree(['tree/a', 'tree/b/', 'tree/b/c']) |
|
249 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
250 |
||
251 |
self.assertStatusEqual( |
|
252 |
[('a-id', 'a', 'added', 'a'), |
|
253 |
('b-id', 'b', 'added', 'b/'), |
|
254 |
('c-id', 'b/c', 'added', 'b/c'), |
|
255 |
], tree) |
|
256 |
||
257 |
def test_status_renamed(self): |
|
258 |
tree = self.make_branch_and_tree('tree') |
|
259 |
self.build_tree(['tree/a', 'tree/b/', 'tree/b/c']) |
|
260 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
261 |
rev_id1 = tree.commit('one') |
|
262 |
||
263 |
tree.rename_one('b', 'd') |
|
264 |
tree.rename_one('a', 'd/a') |
|
265 |
||
266 |
self.assertStatusEqual( |
|
267 |
[('b-id', 'd', 'renamed', 'b/ => d/'), |
|
268 |
('a-id', 'd/a', 'renamed', 'a => d/a'), |
|
269 |
], tree) |
|
270 |
||
271 |
def test_status_modified(self): |
|
272 |
tree = self.make_branch_and_tree('tree') |
|
273 |
self.build_tree(['tree/a']) |
|
274 |
tree.add(['a'], ['a-id']) |
|
275 |
rev_id1 = tree.commit('one') |
|
276 |
||
277 |
self.build_tree_contents([('tree/a', 'new contents for a\n')]) |
|
278 |
||
279 |
self.assertStatusEqual( |
|
280 |
[('a-id', 'a', 'modified', 'a'), |
|
281 |
], tree) |
|
282 |
||
283 |
def test_status_renamed_and_modified(self): |
|
284 |
tree = self.make_branch_and_tree('tree') |
|
285 |
self.build_tree(['tree/a', 'tree/b/', 'tree/b/c']) |
|
286 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
287 |
rev_id1 = tree.commit('one') |
|
288 |
||
289 |
tree.rename_one('b', 'd') |
|
290 |
tree.rename_one('a', 'd/a') |
|
291 |
self.build_tree_contents([('tree/d/a', 'new contents for a\n'), |
|
292 |
('tree/d/c', 'new contents for c\n'), |
|
293 |
])
|
|
294 |
# 'c' is not considered renamed, because only its parent was moved, it
|
|
295 |
# stayed in the same directory
|
|
296 |
||
297 |
self.assertStatusEqual( |
|
298 |
[('b-id', 'd', 'renamed', 'b/ => d/'), |
|
299 |
('a-id', 'd/a', 'renamed and modified', 'a => d/a'), |
|
300 |
('c-id', 'd/c', 'modified', 'd/c'), |
|
301 |
], tree) |
|
302 |
||
303 |
def test_status_kind_changed(self): |
|
304 |
tree = self.make_branch_and_tree('tree') |
|
305 |
self.build_tree(['tree/a', 'tree/b']) |
|
306 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
307 |
tree.commit('one') |
|
308 |
||
309 |
os.remove('tree/a') |
|
310 |
self.build_tree(['tree/a/']) |
|
311 |
# XXX: This is technically valid, and the file list handles it fine,
|
|
312 |
# but 'show_diff_trees()' does not, so we skip this part of the
|
|
313 |
# test for now.
|
|
314 |
# tree.rename_one('b', 'c')
|
|
315 |
# os.remove('tree/c')
|
|
316 |
# self.build_tree(['tree/c/'])
|
|
317 |
||
318 |
self.assertStatusEqual( |
|
319 |
[('a-id', 'a', 'kind changed', 'a => a/'), |
|
320 |
# ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
|
|
321 |
], tree) |
|
322 |
||
323 |
def test_status_removed(self): |
|
324 |
tree = self.make_branch_and_tree('tree') |
|
325 |
self.build_tree(['tree/a', 'tree/b/']) |
|
326 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
327 |
tree.commit('one') |
|
328 |
||
329 |
os.remove('tree/a') |
|
330 |
tree.remove('b', force=True) |
|
331 |
||
332 |
self.assertStatusEqual( |
|
333 |
[('a-id', 'a', 'removed', 'a'), |
|
334 |
('b-id', 'b', 'removed', 'b/'), |
|
335 |
], tree) |
|
|
613.1.1
by Vincent Ladeuil
Fix bug #286834 bu handling 'missing' files corner case. |
336 |
|
337 |
def test_status_missing_file(self): |
|
338 |
this = self.make_branch_and_tree('this') |
|
339 |
self.build_tree(['this/foo']) |
|
340 |
this.add(['foo'], ['foo-id']) |
|
341 |
this.commit('add') |
|
342 |
||
343 |
other = this.bzrdir.sprout('other').open_workingtree() |
|
344 |
||
345 |
os.remove('this/foo') |
|
346 |
this.remove('foo', force=True) |
|
347 |
this.commit('remove') |
|
348 |
||
349 |
f = open('other/foo', 'wt') |
|
350 |
try: |
|
351 |
f.write('Modified\n') |
|
352 |
finally: |
|
353 |
f.close() |
|
354 |
other.commit('modified') |
|
355 |
||
356 |
this.merge_from_branch(other.branch) |
|
357 |
conflicts.resolve(this) |
|
358 |
||
359 |
self.assertStatusEqual( |
|
360 |
[('foo-id', 'foo.OTHER', 'missing', 'foo.OTHER'),], |
|
361 |
this) |
|
362 |
||
363 |
def test_status_missing_directory(self): |
|
364 |
this = self.make_branch_and_tree('this') |
|
365 |
self.build_tree(['this/foo/', 'this/foo/bar']) |
|
366 |
this.add(['foo', 'foo/bar'], ['foo-id', 'bar-id']) |
|
367 |
this.commit('add') |
|
368 |
||
369 |
other = this.bzrdir.sprout('other').open_workingtree() |
|
370 |
||
371 |
os.remove('this/foo/bar') |
|
372 |
os.rmdir('this/foo') |
|
373 |
this.remove('foo', force=True) |
|
374 |
this.commit('remove') |
|
375 |
||
376 |
f = open('other/foo/bar', 'wt') |
|
377 |
try: |
|
378 |
f.write('Modified\n') |
|
379 |
finally: |
|
380 |
f.close() |
|
381 |
other.commit('modified') |
|
382 |
||
383 |
this.merge_from_branch(other.branch) |
|
384 |
conflicts.resolve(this) |
|
385 |
||
386 |
self.assertStatusEqual( |
|
387 |
[('foo-id', u'foo', 'added', u'foo/'), |
|
388 |
('bar-id', u'foo/bar.OTHER', 'missing', u'foo/bar.OTHER'),], |
|
389 |
this) |