bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
1 |
# bisect plugin for Bazaar (bzr), test module.
|
2 |
# Copyright 2006-2007 Jeff Licquia.
|
|
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 |
import os |
|
|
0.54.41
by Jeff Licquia
Add a merged subtree to the repo the tests create. |
19 |
import shutil |
20 |
import bzrlib.bzrdir |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
21 |
import bzrlib.tests |
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
22 |
import bzrlib.revisionspec |
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
23 |
import bzrlib.plugins.bisect as bisect |
24 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
25 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
26 |
class BisectTestCase(bzrlib.tests.TestCaseWithTransport): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
27 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
28 |
def assertRevno(self, rev): |
29 |
"Make sure we're at the right revision."
|
|
30 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
31 |
rev_contents = {1: "one", 1.1: "one dot one", 1.2: "one dot two", |
32 |
1.3: "one dot three", 2: "two", 3: "three", |
|
33 |
4: "four", 5: "five"} |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
34 |
|
35 |
f = open("test_file") |
|
|
0.54.50
by Jeff Licquia
Better diagnostics when an assertRevno() call fails. |
36 |
content = f.read().strip() |
37 |
if content != rev_contents[rev]: |
|
38 |
rev_ids = dict((rev_contents[k], k) for k in rev_contents.keys()) |
|
39 |
found_rev = rev_ids[content] |
|
40 |
raise AssertionError("expected rev %0.1f, found rev %0.1f" |
|
41 |
% (rev, found_rev)) |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
42 |
|
43 |
def setUp(self): |
|
44 |
bzrlib.tests.TestCaseWithTransport.setUp(self) |
|
45 |
||
|
0.54.41
by Jeff Licquia
Add a merged subtree to the repo the tests create. |
46 |
# These tests assume a branch with five revisions, and
|
47 |
# a branch from version 1 containing three revisions
|
|
48 |
# merged at version 2.
|
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
49 |
|
50 |
self.tree = self.make_branch_and_tree(".") |
|
51 |
||
52 |
f = open("test_file", "w") |
|
53 |
f.write("one") |
|
54 |
f.close() |
|
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
55 |
self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), |
56 |
'test_file'))) |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
57 |
self.tree.commit(message = "add test file") |
58 |
||
|
0.54.41
by Jeff Licquia
Add a merged subtree to the repo the tests create. |
59 |
bzrlib.bzrdir.BzrDir.open(".").sprout("../temp-clone") |
60 |
clone_bzrdir = bzrlib.bzrdir.BzrDir.open("../temp-clone") |
|
61 |
clone_tree = clone_bzrdir.open_workingtree() |
|
62 |
for content in ["one dot one", "one dot two", "one dot three"]: |
|
63 |
f = open("../temp-clone/test_file", "w") |
|
64 |
f.write(content) |
|
65 |
f.close() |
|
66 |
clone_tree.commit(message = "make branch test change") |
|
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
67 |
saved_subtree_revid = clone_tree.branch.last_revision() |
|
0.54.41
by Jeff Licquia
Add a merged subtree to the repo the tests create. |
68 |
|
69 |
self.tree.merge_from_branch(clone_tree.branch) |
|
70 |
f = open("test_file", "w") |
|
71 |
f.write("two") |
|
72 |
f.close() |
|
73 |
self.tree.commit(message = "merge external branch") |
|
74 |
shutil.rmtree("../temp-clone") |
|
75 |
||
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
76 |
self.subtree_rev = saved_subtree_revid |
77 |
||
|
0.54.41
by Jeff Licquia
Add a merged subtree to the repo the tests create. |
78 |
file_contents = ["three", "four", "five"] |
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
79 |
for content in file_contents: |
80 |
f = open("test_file", "w") |
|
81 |
f.write(content) |
|
82 |
f.close() |
|
83 |
self.tree.commit(message = "make test change") |
|
84 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
85 |
|
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
86 |
class BisectHarnessTests(BisectTestCase): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
87 |
|
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
88 |
def testLastRev(self): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
89 |
repo = self.tree.branch.repository |
90 |
top_revtree = repo.revision_tree(self.tree.last_revision()) |
|
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
91 |
top_revtree.lock_read() |
92 |
top_file = top_revtree.get_file(top_revtree.path2id("test_file")) |
|
93 |
test_content = top_file.read().strip() |
|
94 |
top_file.close() |
|
95 |
top_revtree.unlock() |
|
96 |
assert test_content == "five" |
|
97 |
||
98 |
def testSubtreeRev(self): |
|
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
99 |
repo = self.tree.branch.repository |
100 |
sub_revtree = repo.revision_tree(self.subtree_rev) |
|
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
101 |
sub_revtree.lock_read() |
102 |
sub_file = sub_revtree.get_file(sub_revtree.path2id("test_file")) |
|
103 |
test_content = sub_file.read().strip() |
|
104 |
sub_file.close() |
|
105 |
sub_revtree.unlock() |
|
106 |
assert test_content == "one dot three" |
|
107 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
108 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
109 |
class BisectCurrentUnitTests(BisectTestCase): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
110 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
111 |
def testShowLog(self): |
112 |
# Not a very good test; just makes sure the code doesn't fail,
|
|
113 |
# not that the output makes any sense.
|
|
114 |
bisect.BisectCurrent().show_rev_log() |
|
115 |
||
|
0.54.49
by Jeff Licquia
Add subtree and harness tests. |
116 |
def testShowLogSubtree(self): |
117 |
bc = bisect.BisectCurrent() |
|
118 |
bc.switch(self.subtree_rev) |
|
119 |
bc.show_rev_log() |
|
120 |
||
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
121 |
def testSwitchVersions(self): |
122 |
bc = bisect.BisectCurrent() |
|
123 |
self.assertRevno(5) |
|
124 |
bc.switch(4) |
|
125 |
self.assertRevno(4) |
|
126 |
||
127 |
def testReset(self): |
|
128 |
bc = bisect.BisectCurrent() |
|
129 |
bc.switch(4) |
|
130 |
bc.reset() |
|
131 |
self.assertRevno(5) |
|
132 |
assert not os.path.exists(bisect.bisect_rev_path) |
|
133 |
||
|
0.54.43
by Jeff Licquia
Add non-functioning is_merge_point() method to BisectCurrent. |
134 |
def testIsMergePoint(self): |
135 |
bc = bisect.BisectCurrent() |
|
136 |
self.assertRevno(5) |
|
137 |
assert not bc.is_merge_point() |
|
138 |
bc.switch(2) |
|
139 |
assert bc.is_merge_point() |
|
140 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
141 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
142 |
class BisectLogUnitTests(BisectTestCase): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
143 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
144 |
def testCreateBlank(self): |
145 |
bl = bisect.BisectLog() |
|
146 |
bl.save() |
|
147 |
assert os.path.exists(bisect.bisect_info_path) |
|
148 |
||
149 |
def testLoad(self): |
|
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
150 |
f = open(bisect.bisect_info_path, "w") |
151 |
f.write("rev1 yes\nrev2 no\nrev3 yes\n") |
|
152 |
f.close() |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
153 |
|
154 |
bl = bisect.BisectLog() |
|
155 |
assert len(bl._items) == 3 |
|
156 |
assert bl._items[0] == ("rev1", "yes") |
|
157 |
assert bl._items[1] == ("rev2", "no") |
|
158 |
assert bl._items[2] == ("rev3", "yes") |
|
159 |
||
160 |
def testSave(self): |
|
161 |
bl = bisect.BisectLog() |
|
162 |
bl._items = [("rev1", "yes"), ("rev2", "no"), ("rev3", "yes")] |
|
163 |
bl.save() |
|
164 |
||
165 |
f = open(bisect.bisect_info_path) |
|
166 |
assert f.read() == "rev1 yes\nrev2 no\nrev3 yes\n" |
|
167 |
||
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
168 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
169 |
class BisectFuncTests(BisectTestCase): |
|
0.54.52
by Jeff Licquia
PEP 8 fixes. |
170 |
|
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
171 |
def testWorkflow(self): |
172 |
# Start up the bisection. When the two ends are set, we should
|
|
173 |
# end up in the middle.
|
|
174 |
||
175 |
self.run_bzr(['bisect', 'start']) |
|
176 |
self.run_bzr(['bisect', 'yes']) |
|
177 |
self.run_bzr(['bisect', 'no', '-r', '1']) |
|
178 |
self.assertRevno(3) |
|
179 |
||
180 |
# Mark feature as present in the middle. Should move us
|
|
181 |
# halfway back between the current middle and the start.
|
|
182 |
||
183 |
self.run_bzr(['bisect', 'yes']) |
|
184 |
self.assertRevno(2) |
|
185 |
||
186 |
# Mark feature as not present. Since this is only one
|
|
187 |
# rev back from the lowest marked revision with the feature,
|
|
188 |
# the process should end, with the current rev set to the
|
|
189 |
# rev following.
|
|
190 |
||
191 |
self.run_bzr(['bisect', 'no']) |
|
192 |
self.assertRevno(3) |
|
193 |
||
|
0.54.42
by Jeff Licquia
Add functional test for subtree functionality (not passing). |
194 |
def testWorkflowSubtree(self): |
195 |
# Similar to testWorkflow, but make sure the plugin traverses
|
|
196 |
# subtrees when the "final" revision is a merge point.
|
|
197 |
||
198 |
# This part is similar to testWorkflow.
|
|
199 |
||
200 |
self.run_bzr(['bisect', 'start']) |
|
201 |
self.run_bzr(['bisect', 'yes']) |
|
202 |
self.run_bzr(['bisect', 'no', '-r', '1']) |
|
203 |
self.run_bzr(['bisect', 'yes']) |
|
204 |
||
205 |
# Check to make sure we're where we expect to be.
|
|
206 |
||
207 |
self.assertRevno(2) |
|
208 |
||
209 |
# Now, mark the merge point revno, meaning the feature
|
|
210 |
# appeared at a merge point.
|
|
211 |
||
212 |
self.run_bzr(['bisect', 'yes']) |
|
213 |
self.assertRevno(1.2) |
|
214 |
||
215 |
# Continue bisecting along the subtree to the real conclusion.
|
|
216 |
||
217 |
self.run_bzr(['bisect', 'yes']) |
|
218 |
self.assertRevno(1.1) |
|
219 |
self.run_bzr(['bisect', 'yes']) |
|
220 |
self.assertRevno(1.1) |
|
221 |
||
|
0.54.40
by Jeff Licquia
Move the tests to their own module. |
222 |
def testMove(self): |
223 |
# Set up a bisection in progress.
|
|
224 |
||
225 |
self.run_bzr(['bisect', 'start']) |
|
226 |
self.run_bzr(['bisect', 'yes']) |
|
227 |
self.run_bzr(['bisect', 'no', '-r', '1']) |
|
228 |
||
229 |
# Move.
|
|
230 |
||
231 |
self.run_bzr(['bisect', 'move', '-r', '2']) |
|
232 |
self.assertRevno(2) |
|
233 |
||
234 |
def testReset(self): |
|
235 |
# Set up a bisection in progress.
|
|
236 |
||
237 |
self.run_bzr(['bisect', 'start']) |
|
238 |
self.run_bzr(['bisect', 'yes']) |
|
239 |
self.run_bzr(['bisect', 'no', '-r', '1']) |
|
240 |
self.run_bzr(['bisect', 'yes']) |
|
241 |
||
242 |
# Now reset.
|
|
243 |
||
244 |
self.run_bzr(['bisect', 'reset']) |
|
245 |
self.assertRevno(5) |
|
246 |
||
247 |
def testLog(self): |
|
248 |
# Set up a bisection in progress.
|
|
249 |
||
250 |
self.run_bzr(['bisect', 'start']) |
|
251 |
self.run_bzr(['bisect', 'yes']) |
|
252 |
self.run_bzr(['bisect', 'no', '-r', '1']) |
|
253 |
self.run_bzr(['bisect', 'yes']) |
|
254 |
||
255 |
# Now save the log.
|
|
256 |
||
257 |
self.run_bzr(['bisect', 'log', '-o', 'bisect_log']) |
|
258 |
||
259 |
# Reset.
|
|
260 |
||
261 |
self.run_bzr(['bisect', 'reset']) |
|
262 |
||
263 |
# Read it back in.
|
|
264 |
||
265 |
self.run_bzr(['bisect', 'replay', 'bisect_log']) |
|
266 |
self.assertRevno(2) |
|
267 |
||
268 |
# Mark another state, and see if the bisect moves in the
|
|
269 |
# right way.
|
|
270 |
||
271 |
self.run_bzr(['bisect', 'no']) |
|
272 |
self.assertRevno(3) |
|
|
0.54.53
by Jeff Licquia
Move test suite detection function to the test module. |
273 |
|
274 |
||
275 |
def test_suite(): |
|
276 |
from bzrlib.tests.TestUtil import TestLoader, TestSuite |
|
277 |
from bzrlib.plugins.bisect import tests |
|
278 |
suite = TestSuite() |
|
279 |
suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectHarnessTests)) |
|
280 |
suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectFuncTests)) |
|
281 |
suite.addTest(TestLoader().loadTestsFromTestCase( |
|
282 |
tests.BisectCurrentUnitTests)) |
|
283 |
suite.addTest(TestLoader().loadTestsFromTestCase(tests.BisectLogUnitTests)) |
|
284 |
return suite |