bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
1 |
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
897
by Martin Pool
- merge john's revision-naming code |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
897
by Martin Pool
- merge john's revision-naming code |
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.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
|
897
by Martin Pool
- merge john's revision-naming code |
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 |
||
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
17 |
import datetime |
|
974.1.52
by aaron.bentley at utoronto
Merged mpool's latest changes (~0.0.7) |
18 |
import os |
|
1185.1.39
by Robert Collins
Robey Pointers before: namespace to clear up usage of dates in revision parameters |
19 |
import time |
|
1432
by Robert Collins
branch: namespace |
20 |
|
|
1948.4.1
by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers |
21 |
from bzrlib import ( |
|
2220.2.11
by mbp at sourcefrog
Get tag tests working again, stored in the Branch |
22 |
branch, |
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
23 |
bzrdir, |
|
1948.4.1
by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers |
24 |
errors, |
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
25 |
repository, |
|
1948.4.1
by John Arbash Meinel
Update number parsers to raise InvalidRevisionSpec. Update revno: itself so it supports negative numbers |
26 |
)
|
|
1988.4.5
by Robert Collins
revisions can now be specified using dotted-decimal revision numbers. |
27 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
28 |
from bzrlib.revisionspec import ( |
29 |
RevisionSpec, |
|
30 |
RevisionSpec_revno, |
|
31 |
RevisionSpec_tag, |
|
32 |
)
|
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
33 |
|
34 |
||
35 |
def spec_in_history(spec, branch): |
|
36 |
"""A simple helper to change a revision spec into a branch search""" |
|
37 |
return RevisionSpec.from_string(spec).in_history(branch) |
|
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
38 |
|
39 |
||
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
40 |
def spec_in_branch(spec, branch, *args, **kwargs): |
41 |
"""A simple helper to change a revision spec into a branch search""" |
|
42 |
return RevisionSpec.from_string(spec).in_branch(branch, *args, **kwargs) |
|
43 |
||
44 |
||
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
45 |
# Basic class, which just creates a really basic set of revisions
|
46 |
class TestRevisionSpec(TestCaseWithTransport): |
|
47 |
||
48 |
def setUp(self): |
|
49 |
super(TestRevisionSpec, self).setUp() |
|
|
1988.4.5
by Robert Collins
revisions can now be specified using dotted-decimal revision numbers. |
50 |
# this sets up a revision graph:
|
51 |
# r1: [] 1
|
|
52 |
# alt_r2: [r1] 1.1.1
|
|
53 |
# r2: [r1, alt_r2] 2
|
|
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
54 |
|
55 |
self.tree = self.make_branch_and_tree('tree') |
|
56 |
self.build_tree(['tree/a']) |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
57 |
self.tree.lock_write() |
58 |
try: |
|
59 |
self.tree.add(['a']) |
|
60 |
self.tree.commit('a', rev_id='r1') |
|
61 |
||
62 |
self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree() |
|
63 |
self.tree2.commit('alt', rev_id='alt_r2') |
|
64 |
||
65 |
self.tree.merge_from_branch(self.tree2.branch) |
|
66 |
self.tree.commit('second', rev_id='r2') |
|
67 |
finally: |
|
68 |
self.tree.unlock() |
|
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
69 |
|
70 |
def get_in_history(self, revision_spec): |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
71 |
return spec_in_history(revision_spec, self.tree.branch) |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
72 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
73 |
def get_in_branch(self, revision_spec, *args, **kwargs): |
74 |
return spec_in_branch(revision_spec, self.tree.branch, *args, **kwargs) |
|
75 |
||
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
76 |
def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec): |
77 |
rev_info = self.get_in_history(revision_spec) |
|
78 |
self.assertEqual(exp_revno, rev_info.revno, |
|
|
2325.2.1
by Marien Zwart
Make the test suite failure reporting a bit more robust. |
79 |
'Revision spec: %r returned wrong revno: %r != %r' |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
80 |
% (revision_spec, exp_revno, rev_info.revno)) |
81 |
self.assertEqual(exp_revision_id, rev_info.rev_id, |
|
|
2325.2.1
by Marien Zwart
Make the test suite failure reporting a bit more robust. |
82 |
'Revision spec: %r returned wrong revision id:' |
83 |
' %r != %r' |
|
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
84 |
% (revision_spec, exp_revision_id, rev_info.rev_id)) |
85 |
||
|
1948.4.23
by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1 |
86 |
def assertInvalid(self, revision_spec, extra=''): |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
87 |
try: |
88 |
self.get_in_history(revision_spec) |
|
89 |
except errors.InvalidRevisionSpec, e: |
|
|
1948.4.23
by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1 |
90 |
self.assertEqual(revision_spec, e.spec) |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
91 |
self.assertEqual(extra, e.extra) |
|
1948.4.5
by John Arbash Meinel
Fix tests for negative entries, and add tests for revno: |
92 |
else: |
93 |
self.fail('Expected InvalidRevisionSpec to be raised for %s' |
|
94 |
% (revision_spec,)) |
|
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
95 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
96 |
def assertInBranchSupportsNeedRevno(self, revision_spec, |
97 |
has_simple_revno=True): |
|
98 |
"""Assert that the in_branch() helper supports need_revno |
|
99 |
||
100 |
If need_revno=False, then the RevisionInfo can have None for revno.
|
|
101 |
But if it has a real number, then it should be the same as when
|
|
102 |
need_revno=True is passed.
|
|
103 |
||
104 |
:param revision_spec: The revision spec to test.
|
|
105 |
:param has_simple_revno: If true, then 'need_revno=True' must set the
|
|
106 |
.revno property to something other than None.
|
|
107 |
"""
|
|
108 |
info_true = self.get_in_branch(revision_spec, need_revno=True) |
|
109 |
if has_simple_revno: |
|
110 |
self.assertIsNot(None, info_true.revno) |
|
111 |
else: |
|
112 |
self.assertIs(None, info_true.revno) |
|
113 |
info_false = self.get_in_branch(revision_spec, need_revno=False) |
|
114 |
if info_false.revno is not None: |
|
115 |
self.assertEqual(info_true.revno, info_false.revno) |
|
116 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
117 |
def assertAsRevisionId(self, revision_id, revision_spec): |
118 |
"""Calling as_revision_id() should return the specified id.""" |
|
119 |
spec = RevisionSpec.from_string(revision_spec) |
|
120 |
self.assertEqual(revision_id, |
|
121 |
spec.as_revision_id(self.tree.branch)) |
|
122 |
||
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
123 |
|
|
1948.4.19
by John Arbash Meinel
All old tests are covered elsewhere |
124 |
class TestOddRevisionSpec(TestRevisionSpec): |
125 |
"""Test things that aren't normally thought of as revision specs""" |
|
126 |
||
127 |
def test_none(self): |
|
|
2598.5.12
by Aaron Bentley
Merge bzr.dev |
128 |
self.assertInHistoryIs(0, None, None) |
|
1948.4.19
by John Arbash Meinel
All old tests are covered elsewhere |
129 |
|
130 |
def test_object(self): |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
131 |
self.assertRaises(TypeError, RevisionSpec.from_string, object()) |
|
1948.4.19
by John Arbash Meinel
All old tests are covered elsewhere |
132 |
|
|
1948.4.25
by John Arbash Meinel
Check that invalid specs are properly handled |
133 |
def test_unregistered_spec(self): |
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
134 |
self.assertRaises(errors.NoSuchRevisionSpec, |
135 |
RevisionSpec.from_string, 'foo') |
|
136 |
self.assertRaises(errors.NoSuchRevisionSpec, |
|
137 |
RevisionSpec.from_string, '123a') |
|
|
1948.4.32
by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/ |
138 |
|
139 |
||
|
1988.4.5
by Robert Collins
revisions can now be specified using dotted-decimal revision numbers. |
140 |
|
141 |
class TestRevnoFromString(TestCase): |
|
142 |
||
143 |
def test_from_string_dotted_decimal(self): |
|
144 |
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1') |
|
145 |
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1') |
|
146 |
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1') |
|
147 |
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1') |
|
148 |
self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.') |
|
149 |
self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno) |
|
150 |
self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno) |
|
151 |
||
152 |
||
|
1948.4.32
by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/ |
153 |
class TestRevisionSpec_revno(TestRevisionSpec): |
154 |
||
155 |
def test_positive_int(self): |
|
|
2598.5.10
by Aaron Bentley
Return NULL_REVISION instead of None for the null revision |
156 |
self.assertInHistoryIs(0, 'null:', '0') |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
157 |
self.assertInHistoryIs(1, 'r1', '1') |
158 |
self.assertInHistoryIs(2, 'r2', '2') |
|
|
1948.4.23
by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1 |
159 |
self.assertInvalid('3') |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
160 |
|
|
1988.4.5
by Robert Collins
revisions can now be specified using dotted-decimal revision numbers. |
161 |
def test_dotted_decimal(self): |
162 |
self.assertInHistoryIs(None, 'alt_r2', '1.1.1') |
|
163 |
||
|
1948.4.32
by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/ |
164 |
def test_negative_int(self): |
|
1948.4.3
by John Arbash Meinel
Create direct tests for RevisionSpec_int |
165 |
self.assertInHistoryIs(2, 'r2', '-1') |
166 |
self.assertInHistoryIs(1, 'r1', '-2') |
|
167 |
||
|
1948.4.23
by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1 |
168 |
self.assertInHistoryIs(1, 'r1', '-3') |
169 |
self.assertInHistoryIs(1, 'r1', '-4') |
|
170 |
self.assertInHistoryIs(1, 'r1', '-100') |
|
|
1948.4.5
by John Arbash Meinel
Fix tests for negative entries, and add tests for revno: |
171 |
|
172 |
def test_positive(self): |
|
|
2598.5.10
by Aaron Bentley
Return NULL_REVISION instead of None for the null revision |
173 |
self.assertInHistoryIs(0, 'null:', 'revno:0') |
|
1948.4.5
by John Arbash Meinel
Fix tests for negative entries, and add tests for revno: |
174 |
self.assertInHistoryIs(1, 'r1', 'revno:1') |
175 |
self.assertInHistoryIs(2, 'r2', 'revno:2') |
|
176 |
||
177 |
self.assertInvalid('revno:3') |
|
178 |
||
179 |
def test_negative(self): |
|
180 |
self.assertInHistoryIs(2, 'r2', 'revno:-1') |
|
181 |
self.assertInHistoryIs(1, 'r1', 'revno:-2') |
|
182 |
||
|
1948.4.23
by John Arbash Meinel
Change the handling of negative numbers, to be trapped at revno 1 |
183 |
self.assertInHistoryIs(1, 'r1', 'revno:-3') |
184 |
self.assertInHistoryIs(1, 'r1', 'revno:-4') |
|
|
1948.4.6
by John Arbash Meinel
A small bugfix, and more tests for revno: |
185 |
|
186 |
def test_invalid_number(self): |
|
187 |
# Get the right exception text
|
|
188 |
try: |
|
189 |
int('X') |
|
190 |
except ValueError, e: |
|
191 |
pass
|
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
192 |
self.assertInvalid('revno:X', extra='\n' + str(e)) |
|
1948.4.6
by John Arbash Meinel
A small bugfix, and more tests for revno: |
193 |
|
194 |
def test_missing_number_and_branch(self): |
|
195 |
self.assertInvalid('revno::', |
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
196 |
extra='\ncannot have an empty revno and no branch') |
|
1948.4.7
by John Arbash Meinel
More revno: tests, now testing the branch/url parameter |
197 |
|
198 |
def test_invalid_number_with_branch(self): |
|
199 |
try: |
|
200 |
int('X') |
|
201 |
except ValueError, e: |
|
202 |
pass
|
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
203 |
self.assertInvalid('revno:X:tree2', extra='\n' + str(e)) |
|
1948.4.7
by John Arbash Meinel
More revno: tests, now testing the branch/url parameter |
204 |
|
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
205 |
def test_non_exact_branch(self): |
206 |
# It seems better to require an exact path to the branch
|
|
207 |
# Branch.open() rather than using Branch.open_containing()
|
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
208 |
spec = RevisionSpec.from_string('revno:2:tree2/a') |
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
209 |
self.assertRaises(errors.NotBranchError, |
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
210 |
spec.in_history, self.tree.branch) |
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
211 |
|
|
1948.4.7
by John Arbash Meinel
More revno: tests, now testing the branch/url parameter |
212 |
def test_with_branch(self): |
213 |
# Passing a URL overrides the supplied branch path
|
|
214 |
revinfo = self.get_in_history('revno:2:tree2') |
|
215 |
self.assertNotEqual(self.tree.branch.base, revinfo.branch.base) |
|
216 |
self.assertEqual(self.tree2.branch.base, revinfo.branch.base) |
|
217 |
self.assertEqual(2, revinfo.revno) |
|
218 |
self.assertEqual('alt_r2', revinfo.rev_id) |
|
219 |
||
|
1948.4.32
by John Arbash Meinel
Clean up __repr__, as well as add tests that we can handle -r12:branch/ |
220 |
def test_int_with_branch(self): |
221 |
revinfo = self.get_in_history('2:tree2') |
|
222 |
self.assertNotEqual(self.tree.branch.base, revinfo.branch.base) |
|
223 |
self.assertEqual(self.tree2.branch.base, revinfo.branch.base) |
|
224 |
self.assertEqual(2, revinfo.revno) |
|
225 |
self.assertEqual('alt_r2', revinfo.rev_id) |
|
226 |
||
|
1948.4.7
by John Arbash Meinel
More revno: tests, now testing the branch/url parameter |
227 |
def test_with_url(self): |
228 |
url = self.get_url() + '/tree2' |
|
229 |
revinfo = self.get_in_history('revno:2:%s' % (url,)) |
|
230 |
self.assertNotEqual(self.tree.branch.base, revinfo.branch.base) |
|
231 |
self.assertEqual(self.tree2.branch.base, revinfo.branch.base) |
|
232 |
self.assertEqual(2, revinfo.revno) |
|
233 |
self.assertEqual('alt_r2', revinfo.rev_id) |
|
234 |
||
235 |
def test_negative_with_url(self): |
|
236 |
url = self.get_url() + '/tree2' |
|
237 |
revinfo = self.get_in_history('revno:-1:%s' % (url,)) |
|
238 |
self.assertNotEqual(self.tree.branch.base, revinfo.branch.base) |
|
239 |
self.assertEqual(self.tree2.branch.base, revinfo.branch.base) |
|
240 |
self.assertEqual(2, revinfo.revno) |
|
241 |
self.assertEqual('alt_r2', revinfo.rev_id) |
|
242 |
||
|
1948.4.22
by John Arbash Meinel
Refactor common code from integer revno handlers |
243 |
def test_different_history_lengths(self): |
244 |
# Make sure we use the revisions and offsets in the supplied branch
|
|
245 |
# not the ones in the original branch.
|
|
246 |
self.tree2.commit('three', rev_id='r3') |
|
247 |
self.assertInHistoryIs(3, 'r3', 'revno:3:tree2') |
|
248 |
self.assertInHistoryIs(3, 'r3', 'revno:-1:tree2') |
|
249 |
||
|
1948.4.7
by John Arbash Meinel
More revno: tests, now testing the branch/url parameter |
250 |
def test_invalid_branch(self): |
251 |
self.assertRaises(errors.NotBranchError, |
|
252 |
self.get_in_history, 'revno:-1:tree3') |
|
253 |
||
254 |
def test_invalid_revno_in_branch(self): |
|
255 |
self.tree.commit('three', rev_id='r3') |
|
256 |
self.assertInvalid('revno:3:tree2') |
|
|
1948.4.8
by John Arbash Meinel
Testing the revid: spec |
257 |
|
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
258 |
def test_revno_n_path(self): |
259 |
"""Old revno:N:path tests""" |
|
260 |
wta = self.make_branch_and_tree('a') |
|
261 |
ba = wta.branch |
|
262 |
||
263 |
wta.commit('Commit one', rev_id='a@r-0-1') |
|
264 |
wta.commit('Commit two', rev_id='a@r-0-2') |
|
265 |
wta.commit('Commit three', rev_id='a@r-0-3') |
|
266 |
||
267 |
wtb = self.make_branch_and_tree('b') |
|
268 |
bb = wtb.branch |
|
269 |
||
270 |
wtb.commit('Commit one', rev_id='b@r-0-1') |
|
271 |
wtb.commit('Commit two', rev_id='b@r-0-2') |
|
272 |
wtb.commit('Commit three', rev_id='b@r-0-3') |
|
273 |
||
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
274 |
|
275 |
self.assertEqual((1, 'a@r-0-1'), |
|
276 |
spec_in_history('revno:1:a/', ba)) |
|
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
277 |
# The argument of in_history should be ignored since it is
|
278 |
# redundant with the path in the spec.
|
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
279 |
self.assertEqual((1, 'a@r-0-1'), |
280 |
spec_in_history('revno:1:a/', None)) |
|
281 |
self.assertEqual((1, 'a@r-0-1'), |
|
282 |
spec_in_history('revno:1:a/', bb)) |
|
283 |
self.assertEqual((2, 'b@r-0-2'), |
|
284 |
spec_in_history('revno:2:b/', None)) |
|
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
285 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
286 |
def test_supports_need_revno(self): |
287 |
self.assertInBranchSupportsNeedRevno('1') |
|
288 |
self.assertInBranchSupportsNeedRevno('2') |
|
289 |
self.assertInBranchSupportsNeedRevno('1.1.1', |
|
290 |
has_simple_revno=False) |
|
|
1948.4.16
by John Arbash Meinel
Move the tests into the associated tester, remove redundant tests, some small PEP8 changes |
291 |
|
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
292 |
def test_as_revision_id(self): |
293 |
self.assertAsRevisionId('r1', '1') |
|
294 |
self.assertAsRevisionId('r2', '2') |
|
295 |
self.assertAsRevisionId('r1', '-2') |
|
296 |
self.assertAsRevisionId('r2', '-1') |
|
297 |
self.assertAsRevisionId('alt_r2', '1.1.1') |
|
298 |
||
|
1948.4.8
by John Arbash Meinel
Testing the revid: spec |
299 |
|
300 |
class TestRevisionSpec_revid(TestRevisionSpec): |
|
301 |
||
302 |
def test_in_history(self): |
|
303 |
# We should be able to access revisions that are directly
|
|
304 |
# in the history.
|
|
305 |
self.assertInHistoryIs(1, 'r1', 'revid:r1') |
|
306 |
self.assertInHistoryIs(2, 'r2', 'revid:r2') |
|
307 |
||
308 |
def test_missing(self): |
|
309 |
self.assertInvalid('revid:r3') |
|
310 |
||
311 |
def test_merged(self): |
|
312 |
"""We can reach revisions in the ancestry""" |
|
313 |
self.assertInHistoryIs(None, 'alt_r2', 'revid:alt_r2') |
|
314 |
||
315 |
def test_not_here(self): |
|
316 |
self.tree2.commit('alt third', rev_id='alt_r3') |
|
317 |
# It exists in tree2, but not in tree
|
|
318 |
self.assertInvalid('revid:alt_r3') |
|
319 |
||
320 |
def test_in_repository(self): |
|
321 |
"""We can get any revision id in the repository""" |
|
322 |
# XXX: This may change in the future, but for now, it is true
|
|
323 |
self.tree2.commit('alt third', rev_id='alt_r3') |
|
324 |
self.tree.branch.repository.fetch(self.tree2.branch.repository, |
|
325 |
revision_id='alt_r3') |
|
326 |
self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3') |
|
|
1948.4.9
by John Arbash Meinel
Cleanup and test last: |
327 |
|
|
2325.2.2
by Marien Zwart
Make the revid RevisionSpec always return a str object, not a unicode object. |
328 |
def test_unicode(self): |
329 |
"""We correctly convert a unicode ui string to an encoded revid.""" |
|
|
2325.2.4
by Marien Zwart
Rename rev_id to revision_id because HACKING says so. |
330 |
revision_id = u'\N{SNOWMAN}'.encode('utf-8') |
331 |
self.tree.commit('unicode', rev_id=revision_id) |
|
332 |
self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}') |
|
333 |
self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id) |
|
|
2325.2.2
by Marien Zwart
Make the revid RevisionSpec always return a str object, not a unicode object. |
334 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
335 |
def test_supports_need_revno(self): |
336 |
self.assertInBranchSupportsNeedRevno('revid:r1') |
|
337 |
self.assertInBranchSupportsNeedRevno('revid:r2') |
|
338 |
self.assertInBranchSupportsNeedRevno('revid:alt_r2', |
|
339 |
has_simple_revno=False) |
|
340 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
341 |
def test_as_revision_id(self): |
342 |
self.assertAsRevisionId('r1', 'revid:r1') |
|
343 |
self.assertAsRevisionId('r2', 'revid:r2') |
|
344 |
self.assertAsRevisionId('alt_r2', 'revid:alt_r2') |
|
345 |
||
|
1948.4.9
by John Arbash Meinel
Cleanup and test last: |
346 |
|
347 |
class TestRevisionSpec_last(TestRevisionSpec): |
|
348 |
||
349 |
def test_positive(self): |
|
350 |
self.assertInHistoryIs(2, 'r2', 'last:1') |
|
351 |
self.assertInHistoryIs(1, 'r1', 'last:2') |
|
|
2598.5.10
by Aaron Bentley
Return NULL_REVISION instead of None for the null revision |
352 |
self.assertInHistoryIs(0, 'null:', 'last:3') |
|
1948.4.9
by John Arbash Meinel
Cleanup and test last: |
353 |
|
354 |
def test_empty(self): |
|
355 |
self.assertInHistoryIs(2, 'r2', 'last:') |
|
356 |
||
357 |
def test_negative(self): |
|
358 |
self.assertInvalid('last:-1', |
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
359 |
extra='\nyou must supply a positive value') |
|
1948.4.9
by John Arbash Meinel
Cleanup and test last: |
360 |
|
361 |
def test_missing(self): |
|
362 |
self.assertInvalid('last:4') |
|
363 |
||
364 |
def test_no_history(self): |
|
365 |
tree = self.make_branch_and_tree('tree3') |
|
366 |
||
367 |
self.assertRaises(errors.NoCommits, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
368 |
spec_in_history, 'last:', tree.branch) |
|
1948.4.9
by John Arbash Meinel
Cleanup and test last: |
369 |
|
370 |
def test_not_a_number(self): |
|
371 |
try: |
|
372 |
int('Y') |
|
373 |
except ValueError, e: |
|
374 |
pass
|
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
375 |
self.assertInvalid('last:Y', extra='\n' + str(e)) |
|
1948.4.10
by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior |
376 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
377 |
def test_supports_need_revno(self): |
378 |
self.assertInBranchSupportsNeedRevno('last:1') |
|
379 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
380 |
def test_as_revision_id(self): |
381 |
self.assertAsRevisionId('r2', 'last:1') |
|
382 |
self.assertAsRevisionId('r1', 'last:2') |
|
383 |
||
|
1948.4.10
by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior |
384 |
|
385 |
class TestRevisionSpec_before(TestRevisionSpec): |
|
386 |
||
387 |
def test_int(self): |
|
388 |
self.assertInHistoryIs(1, 'r1', 'before:2') |
|
389 |
self.assertInHistoryIs(1, 'r1', 'before:-1') |
|
390 |
||
391 |
def test_before_one(self): |
|
|
2598.5.10
by Aaron Bentley
Return NULL_REVISION instead of None for the null revision |
392 |
self.assertInHistoryIs(0, 'null:', 'before:1') |
|
1948.4.10
by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior |
393 |
|
394 |
def test_before_none(self): |
|
|
1948.4.13
by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent |
395 |
self.assertInvalid('before:0', |
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
396 |
extra='\ncannot go before the null: revision') |
|
1948.4.10
by John Arbash Meinel
test the before: spec, currently asserting what seems to be buggy behavior |
397 |
|
398 |
def test_revid(self): |
|
399 |
self.assertInHistoryIs(1, 'r1', 'before:revid:r2') |
|
400 |
||
401 |
def test_last(self): |
|
402 |
self.assertInHistoryIs(1, 'r1', 'before:last:1') |
|
403 |
||
404 |
def test_alt_revid(self): |
|
|
1948.4.13
by John Arbash Meinel
Going before:0 is an error, and if you are on another history, use the leftmost parent |
405 |
# This will grab the left-most ancestor for alternate histories
|
406 |
self.assertInHistoryIs(1, 'r1', 'before:revid:alt_r2') |
|
|
1948.4.11
by John Arbash Meinel
Update and test the tag: spec |
407 |
|
|
1948.4.14
by John Arbash Meinel
Test the code path for a no-parent alternate history |
408 |
def test_alt_no_parents(self): |
409 |
new_tree = self.make_branch_and_tree('new_tree') |
|
410 |
new_tree.commit('first', rev_id='new_r1') |
|
411 |
self.tree.branch.repository.fetch(new_tree.branch.repository, |
|
412 |
revision_id='new_r1') |
|
|
2598.5.10
by Aaron Bentley
Return NULL_REVISION instead of None for the null revision |
413 |
self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1') |
|
1948.4.14
by John Arbash Meinel
Test the code path for a no-parent alternate history |
414 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
415 |
def test_supports_need_revno(self): |
416 |
self.assertInBranchSupportsNeedRevno('before:2') |
|
417 |
self.assertInBranchSupportsNeedRevno('before:revid:r2') |
|
418 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
419 |
def test_as_revision_id(self): |
|
3298.2.5
by John Arbash Meinel
Start implementing everything in terms of cheaper _as_revision_id lookups. |
420 |
self.tree.lock_read() |
421 |
self.addCleanup(self.tree.unlock) |
|
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
422 |
self.assertAsRevisionId('r1', 'before:revid:r2') |
423 |
self.assertAsRevisionId('r1', 'before:2') |
|
424 |
self.assertAsRevisionId('r1', 'before:1.1.1') |
|
425 |
self.assertAsRevisionId('r1', 'before:revid:alt_r2') |
|
426 |
||
|
1948.4.11
by John Arbash Meinel
Update and test the tag: spec |
427 |
|
428 |
class TestRevisionSpec_tag(TestRevisionSpec): |
|
429 |
||
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
430 |
def make_branch_and_tree(self, relpath): |
431 |
# override format as the default one may not support tags
|
|
|
3031.3.1
by Robert Collins
Remove the unneeded ExperimentalBranch class. |
432 |
return TestRevisionSpec.make_branch_and_tree( |
433 |
self, relpath, format='dirstate-tags') |
|
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
434 |
|
435 |
def test_from_string_tag(self): |
|
436 |
spec = RevisionSpec.from_string('tag:bzr-0.14') |
|
437 |
self.assertIsInstance(spec, RevisionSpec_tag) |
|
438 |
self.assertEqual(spec.spec, 'bzr-0.14') |
|
439 |
||
440 |
def test_lookup_tag(self): |
|
|
2220.2.20
by Martin Pool
Tag methods now available through Branch.tags.add_tag, etc |
441 |
self.tree.branch.tags.set_tag('bzr-0.14', 'r1') |
|
2220.2.3
by Martin Pool
Add tag: revision namespace. |
442 |
self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14') |
443 |
||
444 |
def test_failed_lookup(self): |
|
445 |
# tags that don't exist give a specific message: arguably we should
|
|
446 |
# just give InvalidRevisionSpec but I think this is more helpful
|
|
447 |
self.assertRaises(errors.NoSuchTag, |
|
448 |
self.get_in_history, |
|
449 |
'tag:some-random-tag') |
|
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
450 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
451 |
def test_supports_need_revno(self): |
452 |
self.tree.branch.tags.set_tag('bzr-0.14', 'r1') |
|
453 |
self.assertInBranchSupportsNeedRevno('tag:bzr-0.14') |
|
454 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
455 |
def test_as_revision_id(self): |
456 |
self.tree.branch.tags.set_tag('my-tag', 'r2') |
|
457 |
self.assertAsRevisionId('r2', 'tag:my-tag') |
|
458 |
self.assertAsRevisionId('r1', 'before:tag:my-tag') |
|
459 |
||
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
460 |
|
461 |
class TestRevisionSpec_date(TestRevisionSpec): |
|
462 |
||
463 |
def setUp(self): |
|
464 |
super(TestRevisionSpec, self).setUp() |
|
465 |
||
466 |
new_tree = self.make_branch_and_tree('new_tree') |
|
467 |
new_tree.commit('Commit one', rev_id='new_r1', |
|
468 |
timestamp=time.time() - 60*60*24) |
|
469 |
new_tree.commit('Commit two', rev_id='new_r2') |
|
470 |
new_tree.commit('Commit three', rev_id='new_r3') |
|
471 |
||
472 |
self.tree = new_tree |
|
473 |
||
474 |
def test_tomorrow(self): |
|
475 |
self.assertInvalid('date:tomorrow') |
|
476 |
||
477 |
def test_today(self): |
|
478 |
self.assertInHistoryIs(2, 'new_r2', 'date:today') |
|
479 |
self.assertInHistoryIs(1, 'new_r1', 'before:date:today') |
|
480 |
||
481 |
def test_yesterday(self): |
|
482 |
self.assertInHistoryIs(1, 'new_r1', 'date:yesterday') |
|
483 |
||
484 |
def test_invalid(self): |
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
485 |
self.assertInvalid('date:foobar', extra='\ninvalid date') |
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
486 |
# You must have '-' between year/month/day
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
487 |
self.assertInvalid('date:20040404', extra='\ninvalid date') |
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
488 |
# Need 2 digits for each date piece
|
|
1948.4.15
by John Arbash Meinel
Change the InvalidRevisionSpec formatting to be more readable |
489 |
self.assertInvalid('date:2004-4-4', extra='\ninvalid date') |
|
1948.4.12
by John Arbash Meinel
Some tests for the date: spec |
490 |
|
491 |
def test_day(self): |
|
492 |
now = datetime.datetime.now() |
|
493 |
self.assertInHistoryIs(2, 'new_r2', |
|
494 |
'date:%04d-%02d-%02d' % (now.year, now.month, now.day)) |
|
|
1948.4.17
by John Arbash Meinel
Update tests for ancestor: spec |
495 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
496 |
def test_supports_need_revno(self): |
497 |
self.assertInBranchSupportsNeedRevno('date:today') |
|
498 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
499 |
def test_as_revision_id(self): |
500 |
self.assertAsRevisionId('new_r2', 'date:today') |
|
501 |
||
|
1948.4.17
by John Arbash Meinel
Update tests for ancestor: spec |
502 |
|
503 |
class TestRevisionSpec_ancestor(TestRevisionSpec): |
|
504 |
||
505 |
def test_non_exact_branch(self): |
|
506 |
# It seems better to require an exact path to the branch
|
|
507 |
# Branch.open() rather than using Branch.open_containing()
|
|
508 |
self.assertRaises(errors.NotBranchError, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
509 |
self.get_in_history, 'ancestor:tree2/a') |
|
1948.4.17
by John Arbash Meinel
Update tests for ancestor: spec |
510 |
|
511 |
def test_simple(self): |
|
512 |
# Common ancestor of trees is 'alt_r2'
|
|
513 |
self.assertInHistoryIs(None, 'alt_r2', 'ancestor:tree2') |
|
514 |
||
515 |
# Going the other way, we get a valid revno
|
|
516 |
tmp = self.tree |
|
517 |
self.tree = self.tree2 |
|
518 |
self.tree2 = tmp |
|
519 |
self.assertInHistoryIs(2, 'alt_r2', 'ancestor:tree') |
|
520 |
||
521 |
def test_self(self): |
|
522 |
self.assertInHistoryIs(2, 'r2', 'ancestor:tree') |
|
523 |
||
524 |
def test_unrelated(self): |
|
525 |
new_tree = self.make_branch_and_tree('new_tree') |
|
526 |
||
527 |
new_tree.commit('Commit one', rev_id='new_r1') |
|
528 |
new_tree.commit('Commit two', rev_id='new_r2') |
|
529 |
new_tree.commit('Commit three', rev_id='new_r3') |
|
530 |
||
531 |
# With no common ancestor, we should raise another user error
|
|
532 |
self.assertRaises(errors.NoCommonAncestor, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
533 |
self.get_in_history, 'ancestor:new_tree') |
|
1948.4.17
by John Arbash Meinel
Update tests for ancestor: spec |
534 |
|
535 |
def test_no_commits(self): |
|
536 |
new_tree = self.make_branch_and_tree('new_tree') |
|
537 |
self.assertRaises(errors.NoCommits, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
538 |
spec_in_history, 'ancestor:new_tree', |
539 |
self.tree.branch) |
|
|
1948.4.17
by John Arbash Meinel
Update tests for ancestor: spec |
540 |
|
541 |
self.assertRaises(errors.NoCommits, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
542 |
spec_in_history, 'ancestor:tree', |
543 |
new_tree.branch) |
|
|
1948.4.18
by John Arbash Meinel
Update branch: spec and tests |
544 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
545 |
def test_supports_need_revno(self): |
546 |
self.assertInBranchSupportsNeedRevno('ancestor:tree2', |
|
547 |
has_simple_revno=False) |
|
548 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
549 |
def test_as_revision_id(self): |
550 |
self.assertAsRevisionId('alt_r2', 'ancestor:tree2') |
|
551 |
||
|
1948.4.18
by John Arbash Meinel
Update branch: spec and tests |
552 |
|
553 |
class TestRevisionSpec_branch(TestRevisionSpec): |
|
554 |
||
555 |
def test_non_exact_branch(self): |
|
556 |
# It seems better to require an exact path to the branch
|
|
557 |
# Branch.open() rather than using Branch.open_containing()
|
|
558 |
self.assertRaises(errors.NotBranchError, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
559 |
self.get_in_history, 'branch:tree2/a') |
|
1948.4.18
by John Arbash Meinel
Update branch: spec and tests |
560 |
|
561 |
def test_simple(self): |
|
562 |
self.assertInHistoryIs(None, 'alt_r2', 'branch:tree2') |
|
563 |
||
564 |
def test_self(self): |
|
565 |
self.assertInHistoryIs(2, 'r2', 'branch:tree') |
|
566 |
||
567 |
def test_unrelated(self): |
|
568 |
new_tree = self.make_branch_and_tree('new_tree') |
|
569 |
||
570 |
new_tree.commit('Commit one', rev_id='new_r1') |
|
571 |
new_tree.commit('Commit two', rev_id='new_r2') |
|
572 |
new_tree.commit('Commit three', rev_id='new_r3') |
|
573 |
||
574 |
self.assertInHistoryIs(None, 'new_r3', 'branch:new_tree') |
|
575 |
||
576 |
# XXX: Right now, we use fetch() to make sure the remote revisions
|
|
577 |
# have been pulled into the local branch. We may change that
|
|
578 |
# behavior in the future.
|
|
579 |
self.failUnless(self.tree.branch.repository.has_revision('new_r3')) |
|
580 |
||
581 |
def test_no_commits(self): |
|
582 |
new_tree = self.make_branch_and_tree('new_tree') |
|
583 |
self.assertRaises(errors.NoCommits, |
|
|
1948.4.33
by John Arbash Meinel
Switch from get_revision_spec() to RevisionSpec.from_string() (as advised by Martin) |
584 |
self.get_in_history, 'branch:new_tree') |
|
1551.10.32
by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs |
585 |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
586 |
def test_supports_need_revno(self): |
587 |
self.assertInBranchSupportsNeedRevno('branch:tree2', |
|
588 |
has_simple_revno=False) |
|
589 |
||
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
590 |
def test_as_revision_id(self): |
591 |
self.assertAsRevisionId('alt_r2', 'branch:tree2') |
|
592 |
||
|
1551.10.32
by Aaron Bentley
Add submit: specifier, for merge-directive-like diffs |
593 |
|
594 |
class TestRevisionSpec_submit(TestRevisionSpec): |
|
595 |
||
596 |
def test_submit_branch(self): |
|
597 |
# Common ancestor of trees is 'alt_r2'
|
|
598 |
self.assertRaises(errors.NoSubmitBranch, self.get_in_history, |
|
599 |
'submit:') |
|
600 |
self.tree.branch.set_parent('../tree2') |
|
601 |
self.assertInHistoryIs(None, 'alt_r2', 'submit:') |
|
602 |
self.tree.branch.set_parent('bogus') |
|
603 |
self.assertRaises(errors.NotBranchError, self.get_in_history, |
|
604 |
'submit:') |
|
605 |
# submit branch overrides parent branch
|
|
606 |
self.tree.branch.set_submit_branch('tree2') |
|
607 |
self.assertInHistoryIs(None, 'alt_r2', 'submit:') |
|
|
3298.2.3
by John Arbash Meinel
Add tests that all RevisionSpecs implement in_branch(b, needs_revno) |
608 |
|
609 |
def test_supports_need_revno(self): |
|
610 |
self.tree.branch.set_submit_branch('tree2') |
|
611 |
self.assertInBranchSupportsNeedRevno('submit:', |
|
612 |
has_simple_revno=False) |
|
|
3298.2.4
by John Arbash Meinel
Introduce as_revision_id() as a function instead of in_branch(need_revno=False) |
613 |
|
614 |
def test_as_revision_id(self): |
|
615 |
self.tree.branch.set_submit_branch('tree2') |
|
616 |
self.assertAsRevisionId('alt_r2', 'branch:tree2') |