bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
1 |
# Copyright (C) 2006-2007 by Jelmer Vernooij
|
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
|
|
|
0.436.16
by Jelmer Vernooij
Some more work on maptree. |
16 |
"""Tests for the rebase code."""
|
|
0.436.2
by Jelmer Vernooij
Add stubs for testsuite, rebase-continue and rebase-abort commands. |
17 |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
18 |
from bzrlib.errors import UnknownFormatError, NoSuchFile |
|
0.436.6
by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation. |
19 |
from bzrlib.revision import NULL_REVISION |
|
0.436.5
by Jelmer Vernooij
Import change_revision_parent from bzr-svn. |
20 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
21 |
||
22 |
from rebase import (marshall_rebase_plan, unmarshall_rebase_plan, |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
23 |
replay_snapshot, generate_simple_plan, |
24 |
generate_transpose_plan, rebase_plan_exists, |
|
|
0.436.18
by Jelmer Vernooij
More tests, extend MapTree a bit. |
25 |
rebase_todo, REBASE_PLAN_FILENAME, |
26 |
REBASE_CURRENT_REVID_FILENAME, read_rebase_plan, |
|
27 |
remove_rebase_plan, read_active_rebase_revid, |
|
28 |
write_active_rebase_revid, write_rebase_plan, MapTree) |
|
|
0.436.5
by Jelmer Vernooij
Import change_revision_parent from bzr-svn. |
29 |
|
|
0.436.4
by Jelmer Vernooij
Add some tests. |
30 |
|
|
0.436.3
by Jelmer Vernooij
Fill in commands. |
31 |
class RebasePlanReadWriterTests(TestCase): |
|
0.436.4
by Jelmer Vernooij
Add some tests. |
32 |
def test_simple_marshall_rebase_plan(self): |
33 |
self.assertEqualDiff( |
|
34 |
"""# Bazaar rebase plan 1
|
|
35 |
1 bla
|
|
36 |
oldrev newrev newparent1 newparent2
|
|
37 |
""", marshall_rebase_plan((1, "bla"), |
|
38 |
{"oldrev": ("newrev", ["newparent1", "newparent2"])})) |
|
39 |
||
40 |
def test_simple_unmarshall_rebase_plan(self): |
|
41 |
self.assertEquals(((1, "bla"), |
|
42 |
{"oldrev": ("newrev", ["newparent1", "newparent2"])}), |
|
43 |
unmarshall_rebase_plan("""# Bazaar rebase plan 1 |
|
44 |
1 bla
|
|
45 |
oldrev newrev newparent1 newparent2
|
|
46 |
""")) |
|
47 |
||
48 |
def test_unmarshall_rebase_plan_formatunknown(self): |
|
49 |
self.assertRaises(UnknownFormatError, |
|
50 |
unmarshall_rebase_plan, """# Bazaar rebase plan x |
|
51 |
1 bla
|
|
52 |
oldrev newrev newparent1 newparent2
|
|
53 |
""") |
|
|
0.436.5
by Jelmer Vernooij
Import change_revision_parent from bzr-svn. |
54 |
|
55 |
||
56 |
class ConversionTests(TestCaseWithTransport): |
|
57 |
def test_simple(self): |
|
58 |
wt = self.make_branch_and_tree('.') |
|
59 |
b = wt.branch |
|
60 |
file('hello', 'w').write('hello world') |
|
61 |
wt.add('hello') |
|
62 |
wt.commit(message='add hello', rev_id="bla") |
|
63 |
file('hello', 'w').write('world') |
|
64 |
wt.commit(message='change hello', rev_id="bloe") |
|
65 |
wt.set_last_revision("bla") |
|
66 |
b.set_revision_history(["bla"]) |
|
67 |
file('hello', 'w').write('world') |
|
68 |
wt.commit(message='change hello', rev_id="bla2") |
|
69 |
||
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
70 |
newrev = replay_snapshot(wt.branch.repository, "bla2", "bla4", |
|
0.436.5
by Jelmer Vernooij
Import change_revision_parent from bzr-svn. |
71 |
["bloe"]) |
72 |
self.assertEqual("bla4", newrev) |
|
73 |
self.assertTrue(wt.branch.repository.has_revision(newrev)) |
|
74 |
self.assertEqual(["bloe"], wt.branch.repository.revision_parents(newrev)) |
|
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
75 |
self.assertEqual("bla2", wt.branch.repository.get_revision(newrev).properties["rebase-of"]) |
|
0.436.6
by Jelmer Vernooij
Add somewhat more complex plan generation function, rebase implementation. |
76 |
|
77 |
||
78 |
class PlanCreatorTests(TestCaseWithTransport): |
|
79 |
def test_simple_plan_creator(self): |
|
80 |
wt = self.make_branch_and_tree('.') |
|
81 |
b = wt.branch |
|
82 |
file('hello', 'w').write('hello world') |
|
83 |
wt.add('hello') |
|
84 |
wt.commit(message='add hello', rev_id="bla") |
|
85 |
file('hello', 'w').write('world') |
|
86 |
wt.commit(message='change hello', rev_id="bloe") |
|
87 |
wt.set_last_revision("bla") |
|
88 |
b.set_revision_history(["bla"]) |
|
89 |
file('hello', 'w').write('world') |
|
90 |
wt.commit(message='change hello', rev_id="bla2") |
|
91 |
||
92 |
self.assertEquals({'bla2': ('newbla2', ["bloe"])}, |
|
93 |
generate_simple_plan(b.repository, b.revision_history(), "bla2", "bloe", |
|
94 |
lambda y: "new"+y.revision_id)) |
|
95 |
||
96 |
def test_simple_plan_creator_extra_history(self): |
|
97 |
wt = self.make_branch_and_tree('.') |
|
98 |
b = wt.branch |
|
99 |
file('hello', 'w').write('hello world') |
|
100 |
wt.add('hello') |
|
101 |
wt.commit(message='add hello', rev_id="bla") |
|
102 |
file('hello', 'w').write('world') |
|
103 |
wt.commit(message='change hello', rev_id="bloe") |
|
104 |
wt.set_last_revision("bla") |
|
105 |
b.set_revision_history(["bla"]) |
|
106 |
file('hello', 'w').write('world') |
|
107 |
wt.commit(message='change hello', rev_id="bla2") |
|
108 |
file('hello', 'w').write('universe') |
|
109 |
wt.commit(message='change hello again', rev_id="bla3") |
|
110 |
||
111 |
self.assertEquals({'bla2': ('newbla2', ["bloe"]), 'bla3': ('newbla3', ['newbla2'])}, |
|
112 |
generate_simple_plan(b.repository, b.revision_history(), "bla2", "bloe", |
|
113 |
lambda y: "new"+y.revision_id)) |
|
114 |
||
115 |
||
116 |
def test_generate_transpose_plan(self): |
|
117 |
wt = self.make_branch_and_tree('.') |
|
118 |
b = wt.branch |
|
119 |
file('hello', 'w').write('hello world') |
|
120 |
wt.add('hello') |
|
121 |
wt.commit(message='add hello', rev_id="bla") |
|
122 |
file('hello', 'w').write('world') |
|
123 |
wt.commit(message='change hello', rev_id="bloe") |
|
124 |
wt.set_last_revision("bla") |
|
125 |
b.set_revision_history(["bla"]) |
|
126 |
file('hello', 'w').write('world') |
|
127 |
wt.commit(message='change hello', rev_id="bla2") |
|
128 |
file('hello', 'w').write('universe') |
|
129 |
wt.commit(message='change hello again', rev_id="bla3") |
|
130 |
wt.set_last_revision("bla") |
|
131 |
b.set_revision_history(["bla"]) |
|
132 |
file('hello', 'w').write('somebar') |
|
133 |
wt.commit(message='change hello yet again', rev_id="blie") |
|
134 |
wt.set_last_revision(NULL_REVISION) |
|
135 |
b.set_revision_history([]) |
|
136 |
wt.add('hello') |
|
137 |
wt.commit(message='add hello', rev_id="lala") |
|
138 |
||
139 |
self.assertEquals({ |
|
140 |
'bla': ('lala', []), |
|
141 |
'blie': ('newblie', ['lala']), |
|
142 |
},
|
|
143 |
generate_transpose_plan(b.repository, b.repository.get_revision_graph("blie"), |
|
144 |
{"bla": "lala"}, lambda y: "new"+y.revision_id)) |
|
145 |
self.assertEquals({ |
|
146 |
'bla': ('lala', []), |
|
147 |
'bla2': ('newbla2', ['lala']), |
|
148 |
'bla3': ('newbla3', ['newbla2']), |
|
149 |
'blie': ('newblie', ['lala']), |
|
150 |
'bloe': ('newbloe', ['lala'])}, |
|
151 |
generate_transpose_plan(b.repository, b.repository.get_revision_graph(), |
|
152 |
{"bla": "lala"}, lambda y: "new"+y.revision_id)) |
|
153 |
||
|
0.436.7
by Jelmer Vernooij
Add more test, make basic rebase work. |
154 |
|
155 |
class PlanFileTests(TestCaseWithTransport): |
|
156 |
def test_rebase_plan_exists_false(self): |
|
157 |
wt = self.make_branch_and_tree('.') |
|
158 |
self.assertFalse(rebase_plan_exists(wt)) |
|
159 |
||
160 |
def test_rebase_plan_exists_empty(self): |
|
161 |
wt = self.make_branch_and_tree('.') |
|
162 |
wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "") |
|
163 |
self.assertFalse(rebase_plan_exists(wt)) |
|
164 |
||
165 |
def test_rebase_plan_exists(self): |
|
166 |
wt = self.make_branch_and_tree('.') |
|
167 |
wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "foo") |
|
168 |
self.assertTrue(rebase_plan_exists(wt)) |
|
169 |
||
170 |
def test_remove_rebase_plan(self): |
|
171 |
wt = self.make_branch_and_tree('.') |
|
172 |
wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "foo") |
|
173 |
remove_rebase_plan(wt) |
|
174 |
self.assertFalse(rebase_plan_exists(wt)) |
|
175 |
||
176 |
def test_remove_rebase_plan_twice(self): |
|
177 |
wt = self.make_branch_and_tree('.') |
|
178 |
remove_rebase_plan(wt) |
|
179 |
self.assertFalse(rebase_plan_exists(wt)) |
|
180 |
||
181 |
def test_write_rebase_plan(self): |
|
182 |
wt = self.make_branch_and_tree('.') |
|
183 |
file('hello', 'w').write('hello world') |
|
184 |
wt.add('hello') |
|
185 |
wt.commit(message='add hello', rev_id="bla") |
|
186 |
write_rebase_plan(wt, |
|
187 |
{"oldrev": ("newrev", ["newparent1", "newparent2"])}) |
|
188 |
self.assertEqualDiff("""# Bazaar rebase plan 1 |
|
189 |
1 bla
|
|
190 |
oldrev newrev newparent1 newparent2
|
|
191 |
""", wt._control_files.get(REBASE_PLAN_FILENAME).read()) |
|
192 |
||
193 |
def test_read_rebase_plan_nonexistant(self): |
|
194 |
wt = self.make_branch_and_tree('.') |
|
195 |
self.assertRaises(NoSuchFile, read_rebase_plan, wt) |
|
196 |
||
197 |
def test_read_rebase_plan_empty(self): |
|
198 |
wt = self.make_branch_and_tree('.') |
|
199 |
wt._control_files.put_utf8(REBASE_PLAN_FILENAME, "") |
|
200 |
self.assertRaises(NoSuchFile, read_rebase_plan, wt) |
|
201 |
||
202 |
def test_read_rebase_plan(self): |
|
203 |
wt = self.make_branch_and_tree('.') |
|
204 |
wt._control_files.put_utf8(REBASE_PLAN_FILENAME, """# Bazaar rebase plan 1 |
|
205 |
1 bla
|
|
206 |
oldrev newrev newparent1 newparent2
|
|
207 |
""") |
|
208 |
self.assertEquals(((1, "bla"), {"oldrev": ("newrev", ["newparent1", "newparent2"])}), |
|
209 |
read_rebase_plan(wt)) |
|
210 |
||
|
0.436.9
by Jelmer Vernooij
Add rebase-todo command, fix rebase-continue. |
211 |
class CurrentRevidFileTests(TestCaseWithTransport): |
212 |
def test_read_nonexistant(self): |
|
213 |
wt = self.make_branch_and_tree('.') |
|
214 |
self.assertIs(None, read_active_rebase_revid(wt)) |
|
215 |
||
216 |
def test_read_null(self): |
|
217 |
wt = self.make_branch_and_tree('.') |
|
218 |
wt._control_files.put_utf8(REBASE_CURRENT_REVID_FILENAME, NULL_REVISION) |
|
219 |
self.assertIs(None, read_active_rebase_revid(wt)) |
|
220 |
||
221 |
def test_read(self): |
|
222 |
wt = self.make_branch_and_tree('.') |
|
223 |
wt._control_files.put_utf8(REBASE_CURRENT_REVID_FILENAME, "bla") |
|
224 |
self.assertEquals("bla", read_active_rebase_revid(wt)) |
|
225 |
||
226 |
def test_write(self): |
|
227 |
wt = self.make_branch_and_tree('.') |
|
228 |
write_active_rebase_revid(wt, "bloe") |
|
229 |
self.assertEquals("bloe", read_active_rebase_revid(wt)) |
|
230 |
||
231 |
def test_write_null(self): |
|
232 |
wt = self.make_branch_and_tree('.') |
|
233 |
write_active_rebase_revid(wt, None) |
|
234 |
self.assertIs(None, read_active_rebase_revid(wt)) |
|
|
0.436.18
by Jelmer Vernooij
More tests, extend MapTree a bit. |
235 |
|
236 |
class RebaseTodoTests(TestCase): |
|
237 |
def test_done(self): |
|
238 |
class Repository: |
|
239 |
def has_revision(self, revid): |
|
240 |
return revid == "bloe" |
|
241 |
self.assertEquals([], |
|
242 |
list(rebase_todo(Repository(), { "bla": ("bloe", [])}))) |
|
243 |
||
244 |
def test_notstarted(self): |
|
245 |
class Repository: |
|
246 |
def has_revision(self, revid): |
|
247 |
return False |
|
248 |
self.assertEquals(["bla"], |
|
249 |
list(rebase_todo(Repository(), { "bla": ("bloe", [])}))) |
|
250 |
||
251 |
def test_halfway(self): |
|
252 |
class Repository: |
|
253 |
def has_revision(self, revid): |
|
254 |
return revid == "bloe" |
|
255 |
self.assertEquals(["ha"], |
|
256 |
list(rebase_todo(Repository(), { "bla": ("bloe", []), |
|
257 |
"ha": ("hee", [])}))) |