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 |
||
19 |
from bzrlib import ( |
|
20 |
tests, |
|
21 |
revision, |
|
22 |
)
|
|
23 |
||
24 |
from bzrlib.plugins.gtk import commit |
|
25 |
||
26 |
||
27 |
# TODO: All we need is basic ancestry code to test this, we shouldn't need a
|
|
28 |
# TestCaseWithTransport, just a TestCaseWithMemoryTransport or somesuch.
|
|
29 |
||
30 |
class TestPendingRevisions(tests.TestCaseWithTransport): |
|
31 |
||
32 |
def test_pending_revisions_none(self): |
|
33 |
tree = self.make_branch_and_tree('.') |
|
34 |
tree.commit('one') |
|
35 |
||
36 |
self.assertIs(None, commit.pending_revisions(tree)) |
|
37 |
||
38 |
def test_pending_revisions_simple(self): |
|
39 |
tree = self.make_branch_and_tree('tree') |
|
40 |
rev_id1 = tree.commit('one') |
|
41 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
42 |
rev_id2 = tree2.commit('two') |
|
43 |
tree.merge_from_branch(tree2.branch) |
|
44 |
self.assertEqual([rev_id1, rev_id2], tree.get_parent_ids()) |
|
45 |
||
46 |
pending_revisions = commit.pending_revisions(tree) |
|
47 |
# One primary merge
|
|
48 |
self.assertEqual(1, len(pending_revisions)) |
|
49 |
# Revision == rev_id2
|
|
50 |
self.assertEqual(rev_id2, pending_revisions[0][0].revision_id) |
|
51 |
# No children of this revision.
|
|
52 |
self.assertEqual([], pending_revisions[0][1]) |
|
53 |
||
54 |
def test_pending_revisions_with_children(self): |
|
55 |
tree = self.make_branch_and_tree('tree') |
|
56 |
rev_id1 = tree.commit('one') |
|
57 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
58 |
rev_id2 = tree2.commit('two') |
|
59 |
rev_id3 = tree2.commit('three') |
|
60 |
rev_id4 = tree2.commit('four') |
|
61 |
tree.merge_from_branch(tree2.branch) |
|
62 |
self.assertEqual([rev_id1, rev_id4], tree.get_parent_ids()) |
|
63 |
||
64 |
pending_revisions = commit.pending_revisions(tree) |
|
65 |
# One primary merge
|
|
66 |
self.assertEqual(1, len(pending_revisions)) |
|
67 |
# Revision == rev_id2
|
|
68 |
self.assertEqual(rev_id4, pending_revisions[0][0].revision_id) |
|
69 |
# Two children for this revision
|
|
70 |
self.assertEqual(2, len(pending_revisions[0][1])) |
|
71 |
self.assertEqual(rev_id3, pending_revisions[0][1][0].revision_id) |
|
72 |
self.assertEqual(rev_id2, pending_revisions[0][1][1].revision_id) |
|
73 |
||
74 |
def test_pending_revisions_multi_merge(self): |
|
75 |
tree = self.make_branch_and_tree('tree') |
|
76 |
rev_id1 = tree.commit('one') |
|
77 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
78 |
rev_id2 = tree2.commit('two') |
|
79 |
rev_id3 = tree2.commit('three') |
|
80 |
tree3 = tree2.bzrdir.sprout('tree3').open_workingtree() |
|
81 |
rev_id4 = tree3.commit('four') |
|
82 |
rev_id5 = tree3.commit('five') |
|
83 |
tree.merge_from_branch(tree2.branch) |
|
84 |
tree.merge_from_branch(tree3.branch) |
|
85 |
self.assertEqual([rev_id1, rev_id3, rev_id5], tree.get_parent_ids()) |
|
86 |
||
87 |
pending_revisions = commit.pending_revisions(tree) |
|
88 |
# Two primary merges
|
|
89 |
self.assertEqual(2, len(pending_revisions)) |
|
90 |
# Revision == rev_id2
|
|
91 |
self.assertEqual(rev_id3, pending_revisions[0][0].revision_id) |
|
92 |
self.assertEqual(rev_id5, pending_revisions[1][0].revision_id) |
|
93 |
# One child for the first merge
|
|
94 |
self.assertEqual(1, len(pending_revisions[0][1])) |
|
95 |
self.assertEqual(rev_id2, pending_revisions[0][1][0].revision_id) |
|
96 |
# One child for the second merge
|
|
97 |
self.assertEqual(1, len(pending_revisions[1][1])) |
|
98 |
self.assertEqual(rev_id4, pending_revisions[1][1][0].revision_id) |
|
99 |
||
100 |
||
101 |
class Test_RevToPendingInfo(tests.TestCaseWithTransport): |
|
102 |
||
103 |
def test_basic_info(self): |
|
104 |
tree = self.make_branch_and_tree('tree') |
|
105 |
rev_id = tree.commit('Multiline\ncommit\nmessage', |
|
106 |
committer='Joe Foo <joe@foo.com>', |
|
107 |
timestamp=1191012408.674, |
|
108 |
timezone=-18000 |
|
109 |
)
|
|
110 |
rev = tree.branch.repository.get_revision(rev_id) |
|
111 |
rev_dict = commit.CommitDialog._rev_to_pending_info(rev) |
|
112 |
self.assertEqual({'committer':'Joe Foo', |
|
113 |
'summary':'Multiline', |
|
114 |
'date':'2007-09-28', |
|
115 |
'revision_id':rev_id, |
|
116 |
}, rev_dict) |
|
117 |
||
118 |
||
119 |
class CommitDialogNoWidgets(commit.CommitDialog): |
|
120 |
||
121 |
def construct(self): |
|
122 |
pass # Don't create any widgets here |
|
123 |
||
|
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
124 |
def fill_in_data(self): |
125 |
pass # With no widgets, there are no widgets to fill out |
|
126 |
||
127 |
||
128 |
class TestCommitDialogSimple(tests.TestCaseWithTransport): |
|
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
129 |
|
130 |
def test_setup_parameters_no_pending(self): |
|
131 |
tree = self.make_branch_and_tree('tree') |
|
132 |
rev_id = tree.commit('first') |
|
133 |
||
134 |
dlg = CommitDialogNoWidgets(tree) |
|
135 |
self.assertEqual(rev_id, dlg._basis_tree.get_revision_id()) |
|
136 |
self.assertIs(None, dlg._pending) |
|
137 |
self.assertFalse(dlg._is_checkout) |
|
138 |
||
139 |
def test_setup_parameters_checkout(self): |
|
140 |
tree = self.make_branch_and_tree('tree') |
|
141 |
rev_id = tree.commit('first') |
|
142 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
143 |
tree2.branch.bind(tree.branch) |
|
144 |
||
145 |
dlg = CommitDialogNoWidgets(tree2) |
|
146 |
self.assertEqual(rev_id, dlg._basis_tree.get_revision_id()) |
|
147 |
self.assertIs(None, dlg._pending) |
|
148 |
self.assertTrue(dlg._is_checkout) |
|
149 |
||
150 |
def test_setup_parameters_pending(self): |
|
151 |
tree = self.make_branch_and_tree('tree') |
|
152 |
rev_id1 = tree.commit('one') |
|
153 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
154 |
rev_id2 = tree2.commit('two') |
|
155 |
tree.merge_from_branch(tree2.branch) |
|
156 |
||
157 |
dlg = CommitDialogNoWidgets(tree) |
|
158 |
self.assertEqual(rev_id1, dlg._basis_tree.get_revision_id()) |
|
159 |
self.assertIsNot(None, dlg._pending) |
|
160 |
self.assertEqual(1, len(dlg._pending)) |
|
161 |
self.assertEqual(rev_id2, dlg._pending[0][0].revision_id) |
|
162 |
||
163 |
def test_setup_parameters_delta(self): |
|
164 |
tree = self.make_branch_and_tree('tree') |
|
165 |
self.build_tree(['tree/a']) |
|
166 |
tree.add(['a'], ['a-id']) |
|
167 |
||
168 |
dlg = CommitDialogNoWidgets(tree) |
|
|
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
169 |
self.assertIs(None, dlg._delta) |
170 |
dlg._compute_delta() |
|
171 |
||
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
172 |
delta = dlg._delta |
173 |
self.assertEqual([], delta.modified) |
|
174 |
self.assertEqual([], delta.renamed) |
|
175 |
self.assertEqual([], delta.removed) |
|
176 |
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. |
177 |
|
178 |
||
179 |
class TestCommitDialog(tests.TestCaseWithTransport): |
|
180 |
||
181 |
def test_no_pending(self): |
|
182 |
tree = self.make_branch_and_tree('tree') |
|
183 |
rev_id1 = tree.commit('one') |
|
184 |
||
185 |
dlg = commit.CommitDialog(tree) |
|
186 |
# TODO: assert that the pending box is hidden
|
|
187 |
||
188 |
def test_pending(self): |
|
189 |
tree = self.make_branch_and_tree('tree') |
|
190 |
rev_id1 = tree.commit('one') |
|
191 |
||
192 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
193 |
rev_id2 = tree2.commit('two', |
|
194 |
committer='Joe Foo <joe@foo.com>', |
|
195 |
timestamp=1191264271.05, |
|
196 |
timezone=+7200) |
|
197 |
tree.merge_from_branch(tree2.branch) |
|
198 |
||
199 |
dlg = commit.CommitDialog(tree) |
|
200 |
# TODO: assert that the pending box is set to show
|
|
201 |
values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_liststore] |
|
202 |
self.assertEqual([(rev_id2, '2007-10-01', 'Joe Foo', 'two')], values) |
|
203 |
||
204 |
def test_pending_multiple(self): |
|
205 |
tree = self.make_branch_and_tree('tree') |
|
206 |
rev_id1 = tree.commit('one') |
|
207 |
||
208 |
tree2 = tree.bzrdir.sprout('tree2').open_workingtree() |
|
209 |
rev_id2 = tree2.commit('two', |
|
210 |
committer='Joe Foo <joe@foo.com>', |
|
211 |
timestamp=1191264271.05, |
|
212 |
timezone=+7200) |
|
213 |
rev_id3 = tree2.commit('three', |
|
214 |
committer='Jerry Foo <jerry@foo.com>', |
|
215 |
timestamp=1191264278.05, |
|
216 |
timezone=+7200) |
|
217 |
tree.merge_from_branch(tree2.branch) |
|
218 |
tree3 = tree.bzrdir.sprout('tree3').open_workingtree() |
|
219 |
rev_id4 = tree3.commit('four', |
|
220 |
committer='Joe Foo <joe@foo.com>', |
|
221 |
timestamp=1191264279.05, |
|
222 |
timezone=+7200) |
|
223 |
rev_id5 = tree3.commit('five', |
|
224 |
committer='Jerry Foo <jerry@foo.com>', |
|
225 |
timestamp=1191372278.05, |
|
226 |
timezone=+7200) |
|
227 |
tree.merge_from_branch(tree3.branch) |
|
228 |
||
229 |
dlg = commit.CommitDialog(tree) |
|
230 |
# TODO: assert that the pending box is set to show
|
|
231 |
values = [(r[0], r[1], r[2], r[3]) for r in dlg._pending_liststore] |
|
232 |
self.assertEqual([(rev_id3, '2007-10-01', 'Jerry Foo', 'three'), |
|
233 |
(rev_id2, '2007-10-01', 'Joe Foo', 'two'), |
|
234 |
(rev_id5, '2007-10-03', 'Jerry Foo', 'five'), |
|
235 |
(rev_id4, '2007-10-01', 'Joe Foo', 'four'), |
|
236 |
], values) |