bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
1 |
# Copyright (C) 2007 John Arbash Meinel <john@arbash-meinel.com>
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
"""Test the Commit functionality."""
|
|
18 |
||
278.1.16
by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than |
19 |
import os |
20 |
||
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
21 |
from bzrlib import ( |
22 |
tests, |
|
23 |
revision, |
|
24 |
)
|
|
25 |
||
26 |
from bzrlib.plugins.gtk import commit |
|
27 |
||
28 |
||
29 |
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
|
|
30 |
# TestCaseWithTransport, just a TestCaseWithMemoryTransport or somesuch.
|
|
31 |
||
32 |
class TestPendingRevisions(tests.TestCaseWithTransport): |
|
33 |
||
34 |
def test_pending_revisions_none(self): |
|
35 |
tree = self.make_branch_and_tree('.') |
|
36 |
tree.commit('one') |
|
37 |
||
38 |
self.assertIs(None, commit.pending_revisions(tree)) |
|
39 |
||
40 |
def test_pending_revisions_simple(self): |
|
41 |
tree = self.make_branch_and_tree('tree') |
|
42 |
rev_id1 = tree.commit('one') |
|
43 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
44 |
rev_id2 = tree2.commit('two') |
|
45 |
tree.merge_from_branch(tree2.branch) |
|
46 |
self.assertEqual([rev_id1, rev_id2], tree.get_parent_ids()) |
|
47 |
||
48 |
pending_revisions = commit.pending_revisions(tree) |
|
49 |
# One primary merge
|
|
50 |
self.assertEqual(1, len(pending_revisions)) |
|
51 |
# Revision == rev_id2
|
|
52 |
self.assertEqual(rev_id2, pending_revisions[0][0].revision_id) |
|
53 |
# No children of this revision.
|
|
54 |
self.assertEqual([], pending_revisions[0][1]) |
|
55 |
||
56 |
def test_pending_revisions_with_children(self): |
|
57 |
tree = self.make_branch_and_tree('tree') |
|
58 |
rev_id1 = tree.commit('one') |
|
59 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
60 |
rev_id2 = tree2.commit('two') |
|
61 |
rev_id3 = tree2.commit('three') |
|
62 |
rev_id4 = tree2.commit('four') |
|
63 |
tree.merge_from_branch(tree2.branch) |
|
64 |
self.assertEqual([rev_id1, rev_id4], tree.get_parent_ids()) |
|
65 |
||
66 |
pending_revisions = commit.pending_revisions(tree) |
|
67 |
# One primary merge
|
|
68 |
self.assertEqual(1, len(pending_revisions)) |
|
69 |
# Revision == rev_id2
|
|
70 |
self.assertEqual(rev_id4, pending_revisions[0][0].revision_id) |
|
71 |
# Two children for this revision
|
|
72 |
self.assertEqual(2, len(pending_revisions[0][1])) |
|
73 |
self.assertEqual(rev_id3, pending_revisions[0][1][0].revision_id) |
|
74 |
self.assertEqual(rev_id2, pending_revisions[0][1][1].revision_id) |
|
75 |
||
76 |
def test_pending_revisions_multi_merge(self): |
|
77 |
tree = self.make_branch_and_tree('tree') |
|
78 |
rev_id1 = tree.commit('one') |
|
79 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
80 |
rev_id2 = tree2.commit('two') |
|
81 |
rev_id3 = tree2.commit('three') |
|
82 |
tree3 = tree2.bzrdir.sprout('tree3').open_workingtree() |
|
83 |
rev_id4 = tree3.commit('four') |
|
84 |
rev_id5 = tree3.commit('five') |
|
85 |
tree.merge_from_branch(tree2.branch) |
|
86 |
tree.merge_from_branch(tree3.branch) |
|
87 |
self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids()) |
|
88 |
||
89 |
pending_revisions = commit.pending_revisions(tree) |
|
90 |
# Two primary merges
|
|
91 |
self.assertEqual(2, len(pending_revisions)) |
|
92 |
# Revision == rev_id2
|
|
93 |
self.assertEqual(rev_id3, pending_revisions[0][0].revision_id) |
|
94 |
self.assertEqual(rev_id5, pending_revisions[1][0].revision_id) |
|
95 |
# One child for the first merge
|
|
96 |
self.assertEqual(1, len(pending_revisions[0][1])) |
|
97 |
self.assertEqual(rev_id2, pending_revisions[0][1][0].revision_id) |
|
98 |
# One child for the second merge
|
|
99 |
self.assertEqual(1, len(pending_revisions[1][1])) |
|
100 |
self.assertEqual(rev_id4, pending_revisions[1][1][0].revision_id) |
|
101 |
||
102 |
||
103 |
class Test_RevToPendingInfo(tests.TestCaseWithTransport): |
|
104 |
||
105 |
def test_basic_info(self): |
|
106 |
tree = self.make_branch_and_tree('tree') |
|
107 |
rev_id = tree.commit('Multiline\ncommit\nmessage', |
|
108 |
committer='Joe Foo <joe@foo.com>', |
|
109 |
timestamp=1191012408.674, |
|
110 |
timezone=-18000 |
|
111 |
)
|
|
112 |
rev = tree.branch.repository.get_revision(rev_id) |
|
113 |
rev_dict = commit.CommitDialog._rev_to_pending_info(rev) |
|
114 |
self.assertEqual({'committer':'Joe Foo', |
|
115 |
'summary':'Multiline', |
|
116 |
'date':'2007-09-28', |
|
117 |
'revision_id':rev_id, |
|
118 |
}, rev_dict) |
|
119 |
||
120 |
||
121 |
class CommitDialogNoWidgets(commit.CommitDialog): |
|
122 |
||
123 |
def construct(self): |
|
124 |
pass # Don't create any widgets here |
|
125 |
||
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
126 |
def fill_in_data(self): |
127 |
pass # With no widgets, there are no widgets to fill out |
|
128 |
||
129 |
||
130 |
class TestCommitDialogSimple(tests.TestCaseWithTransport): |
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
131 |
|
132 |
def test_setup_parameters_no_pending(self): |
|
133 |
tree = self.make_branch_and_tree('tree') |
|
134 |
rev_id = tree.commit('first') |
|
135 |
||
136 |
dlg = CommitDialogNoWidgets(tree) |
|
137 |
self.assertEqual(rev_id, dlg._basis_tree.get_revision_id()) |
|
138 |
self.assertIs(None, dlg._pending) |
|
139 |
self.assertFalse(dlg._is_checkout) |
|
140 |
||
141 |
def test_setup_parameters_checkout(self): |
|
142 |
tree = self.make_branch_and_tree('tree') |
|
143 |
rev_id = tree.commit('first') |
|
144 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
145 |
tree2.branch.bind(tree.branch) |
|
146 |
||
147 |
dlg = CommitDialogNoWidgets(tree2) |
|
148 |
self.assertEqual(rev_id, dlg._basis_tree.get_revision_id()) |
|
149 |
self.assertIs(None, dlg._pending) |
|
150 |
self.assertTrue(dlg._is_checkout) |
|
151 |
||
152 |
def test_setup_parameters_pending(self): |
|
153 |
tree = self.make_branch_and_tree('tree') |
|
154 |
rev_id1 = tree.commit('one') |
|
155 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
156 |
rev_id2 = tree2.commit('two') |
|
157 |
tree.merge_from_branch(tree2.branch) |
|
158 |
||
159 |
dlg = CommitDialogNoWidgets(tree) |
|
160 |
self.assertEqual(rev_id1, dlg._basis_tree.get_revision_id()) |
|
161 |
self.assertIsNot(None, dlg._pending) |
|
162 |
self.assertEqual(1, len(dlg._pending)) |
|
163 |
self.assertEqual(rev_id2, dlg._pending[0][0].revision_id) |
|
164 |
||
165 |
def test_setup_parameters_delta(self): |
|
166 |
tree = self.make_branch_and_tree('tree') |
|
167 |
self.build_tree(['tree/a']) |
|
168 |
tree.add(['a'], ['a-id']) |
|
169 |
||
170 |
dlg = CommitDialogNoWidgets(tree) |
|
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
171 |
self.assertIs(None, dlg._delta) |
172 |
dlg._compute_delta() |
|
173 |
||
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
174 |
delta = dlg._delta |
175 |
self.assertEqual([], delta.modified) |
|
176 |
self.assertEqual([], delta.renamed) |
|
177 |
self.assertEqual([], delta.removed) |
|
178 |
self.assertEqual([(u'a', 'a-id', 'file')], delta.added) |
|
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
179 |
|
180 |
||
181 |
class TestCommitDialog(tests.TestCaseWithTransport): |
|
182 |
||
183 |
def test_no_pending(self): |
|
184 |
tree = self.make_branch_and_tree('tree') |
|
185 |
rev_id1 = tree.commit('one') |
|
186 |
||
187 |
dlg = commit.CommitDialog(tree) |
|
188 |
# TODO: assert that the pending box is hidden
|
|
278.1.17
by John Arbash Meinel
Add a * reference for why you can't change the commit selection. |
189 |
commit_col = dlg._treeview_files.get_column(0) |
190 |
self.assertEqual('Commit', commit_col.get_title()) |
|
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
191 |
|
192 |
def test_pending(self): |
|
193 |
tree = self.make_branch_and_tree('tree') |
|
194 |
rev_id1 = tree.commit('one') |
|
195 |
||
196 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
197 |
rev_id2 = tree2.commit('two', |
|
198 |
committer='Joe Foo <joe@foo.com>', |
|
199 |
timestamp=1191264271.05, |
|
200 |
timezone=+7200) |
|
201 |
tree.merge_from_branch(tree2.branch) |
|
202 |
||
203 |
dlg = commit.CommitDialog(tree) |
|
204 |
# TODO: assert that the pending box is set to show
|
|
278.1.17
by John Arbash Meinel
Add a * reference for why you can't change the commit selection. |
205 |
commit_col = dlg._treeview_files.get_column(0) |
206 |
self.assertEqual('Commit*', commit_col.get_title()) |
|
207 |
||
278.1.15
by John Arbash Meinel
Hook up the list of modified files. |
208 |
values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store] |
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
209 |
self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values) |
210 |
||
211 |
def test_pending_multiple(self): |
|
212 |
tree = self.make_branch_and_tree('tree') |
|
213 |
rev_id1 = tree.commit('one') |
|
214 |
||
215 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
216 |
rev_id2 = tree2.commit('two', |
|
217 |
committer='Joe Foo <joe@foo.com>', |
|
218 |
timestamp=1191264271.05, |
|
219 |
timezone=+7200) |
|
220 |
rev_id3 = tree2.commit('three', |
|
221 |
committer='Jerry Foo <jerry@foo.com>', |
|
222 |
timestamp=1191264278.05, |
|
223 |
timezone=+7200) |
|
224 |
tree.merge_from_branch(tree2.branch) |
|
225 |
tree3 = tree.bzrdir.sprout('tree3').open_workingtree() |
|
226 |
rev_id4 = tree3.commit('four', |
|
227 |
committer='Joe Foo <joe@foo.com>', |
|
228 |
timestamp=1191264279.05, |
|
229 |
timezone=+7200) |
|
230 |
rev_id5 = tree3.commit('five', |
|
231 |
committer='Jerry Foo <jerry@foo.com>', |
|
232 |
timestamp=1191372278.05, |
|
233 |
timezone=+7200) |
|
234 |
tree.merge_from_branch(tree3.branch) |
|
235 |
||
236 |
dlg = commit.CommitDialog(tree) |
|
237 |
# TODO: assert that the pending box is set to show
|
|
278.1.15
by John Arbash Meinel
Hook up the list of modified files. |
238 |
values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_store] |
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
239 |
self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'), |
240 |
(rev_id2, '2007-10-01', 'Joe Foo', 'two'), |
|
241 |
(rev_id5, '2007-10-03', 'Jerry Foo', 'five'), |
|
242 |
(rev_id4, '2007-10-01', 'Joe Foo', 'four'), |
|
243 |
], values) |
|
278.1.15
by John Arbash Meinel
Hook up the list of modified files. |
244 |
|
278.1.16
by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than |
245 |
def test_filelist_added(self): |
278.1.15
by John Arbash Meinel
Hook up the list of modified files. |
246 |
tree = self.make_branch_and_tree('tree') |
247 |
self.build_tree(['tree/a', 'tree/b/', 'tree/b/c']) |
|
248 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
249 |
||
250 |
dlg = commit.CommitDialog(tree) |
|
251 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
252 |
self.assertEqual([('a-id', 'a', True, 'a', 'added'), |
|
253 |
('b-id', 'b', True, 'b/', 'added'), |
|
254 |
('c-id', 'b/c', True, 'b/c', 'added'), |
|
255 |
], values) |
|
278.1.16
by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than |
256 |
|
257 |
def test_filelist_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 |
dlg = commit.CommitDialog(tree) |
|
267 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
268 |
self.assertEqual([('b-id', 'd', True, 'b/ => d/', 'renamed'), |
|
269 |
('a-id', 'd/a', True, 'a => d/a', 'renamed'), |
|
270 |
], values) |
|
271 |
||
272 |
def test_filelist_modified(self): |
|
273 |
tree = self.make_branch_and_tree('tree') |
|
274 |
self.build_tree(['tree/a']) |
|
275 |
tree.add(['a'], ['a-id']) |
|
276 |
rev_id1 = tree.commit('one') |
|
277 |
||
278 |
self.build_tree_contents([('tree/a', 'new contents for a\n')]) |
|
279 |
||
280 |
dlg = commit.CommitDialog(tree) |
|
281 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
282 |
self.assertEqual([('a-id', 'a', True, 'a', 'modified'), |
|
283 |
], values) |
|
284 |
||
285 |
def test_filelist_renamed_and_modified(self): |
|
286 |
tree = self.make_branch_and_tree('tree') |
|
287 |
self.build_tree(['tree/a', 'tree/b/', 'tree/b/c']) |
|
288 |
tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id']) |
|
289 |
rev_id1 = tree.commit('one') |
|
290 |
||
291 |
tree.rename_one('b', 'd') |
|
292 |
tree.rename_one('a', 'd/a') |
|
293 |
self.build_tree_contents([('tree/d/a', 'new contents for a\n'), |
|
294 |
('tree/d/c', 'new contents for c\n'), |
|
295 |
])
|
|
296 |
# 'c' is not considered renamed, because only its parent was moved, it
|
|
297 |
# stayed in the same directory
|
|
298 |
||
299 |
dlg = commit.CommitDialog(tree) |
|
300 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
301 |
self.assertEqual([('b-id', 'd', True, 'b/ => d/', 'renamed'), |
|
302 |
('a-id', 'd/a', True, 'a => d/a', 'renamed and modified'), |
|
303 |
('c-id', 'd/c', True, 'd/c', 'modified'), |
|
304 |
], values) |
|
305 |
||
306 |
def test_filelist_kind_changed(self): |
|
307 |
tree = self.make_branch_and_tree('tree') |
|
308 |
self.build_tree(['tree/a', 'tree/b']) |
|
309 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
310 |
tree.commit('one') |
|
311 |
||
312 |
os.remove('tree/a') |
|
313 |
self.build_tree(['tree/a/']) |
|
278.1.17
by John Arbash Meinel
Add a * reference for why you can't change the commit selection. |
314 |
# XXX: This is technically valid, and the file list handles it fine,
|
315 |
# but 'show_diff_trees()' does not, so we skip this part of the
|
|
316 |
# test for now.
|
|
317 |
# tree.rename_one('b', 'c')
|
|
318 |
# os.remove('tree/c')
|
|
319 |
# self.build_tree(['tree/c/'])
|
|
278.1.16
by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than |
320 |
|
321 |
dlg = commit.CommitDialog(tree) |
|
322 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
323 |
self.assertEqual([('a-id', 'a', True, 'a => a/', 'kind changed'), |
|
278.1.17
by John Arbash Meinel
Add a * reference for why you can't change the commit selection. |
324 |
# ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
|
278.1.16
by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than |
325 |
], values) |
326 |
||
327 |
def test_filelist_removed(self): |
|
328 |
tree = self.make_branch_and_tree('tree') |
|
329 |
self.build_tree(['tree/a', 'tree/b/']) |
|
330 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
331 |
tree.commit('one') |
|
332 |
||
333 |
os.remove('tree/a') |
|
334 |
tree.remove('b', force=True) |
|
335 |
||
336 |
dlg = commit.CommitDialog(tree) |
|
337 |
values = [(r[0], r[1], r[2], r[3], r[4]) for r in dlg._files_store] |
|
338 |
self.assertEqual([('a-id', 'a', True, 'a', 'removed'), |
|
339 |
('b-id', 'b', True, 'b/', 'removed'), |
|
340 |
], values) |
|
278.1.18
by John Arbash Meinel
Start checking the diff view is correct. |
341 |
|
342 |
def test_diff_view(self): |
|
343 |
tree = self.make_branch_and_tree('tree') |
|
344 |
self.build_tree(['tree/a', 'tree/b']) |
|
345 |
tree.add(['a', 'b'], ['a-id', 'b-id']) |
|
346 |
tree.commit('one') |
|
347 |
||
348 |
self.build_tree_contents([('tree/a', 'new contents for a\n')]) |
|
349 |
tree.remove('b') |
|
350 |
||
351 |
dlg = commit.CommitDialog(tree) |
|
352 |
diff_buffer = dlg._diff_view.buffer |
|
353 |
text = diff_buffer.get_text(diff_buffer.get_start_iter(), |
|
354 |
diff_buffer.get_end_iter()).splitlines(True) |
|
355 |
||
356 |
self.assertEqual("=== removed file 'b'\n", text[0]) |
|
357 |
self.assertContainsRe(text[1], |
|
358 |
r"--- b\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d") |
|
359 |
self.assertEqual('+++ b\t1970-01-01 00:00:00 +0000\n', text[2]) |
|
360 |
self.assertEqual('@@ -1,1 +0,0 @@\n', text[3]) |
|
361 |
self.assertEqual('-contents of tree/b\n', text[4]) |
|
362 |
self.assertEqual('\n', text[5]) |
|
363 |
||
364 |
self.assertEqual("=== modified file 'a'\n", text[6]) |
|
365 |
self.assertContainsRe(text[7], |
|
366 |
r"--- a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d") |
|
367 |
self.assertContainsRe(text[8], |
|
368 |
r"\+\+\+ a\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d") |
|
369 |
self.assertEqual('@@ -1,1 +1,1 @@\n', text[9]) |
|
370 |
self.assertEqual('-contents of tree/a\n', text[10]) |
|
371 |
self.assertEqual('+new contents for a\n', text[11]) |
|
372 |
self.assertEqual('\n', text[12]) |
|
373 |
||
374 |
self.assertEqual('Diff for whole tree', dlg._diff_label.get_text()) |