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