bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
1 |
# Copyright (C) 2008 Canonical Ltd
|
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 |
||
18 |
"""Tests for foreign VCS utility code."""
|
|
19 |
||
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
20 |
from bzrlib import ( |
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
21 |
branch, |
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
22 |
errors, |
23 |
foreign, |
|
24 |
lockable_files, |
|
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
25 |
lockdir, |
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
26 |
)
|
27 |
from bzrlib.bzrdir import ( |
|
28 |
BzrDir, |
|
29 |
BzrDirFormat, |
|
30 |
BzrDirMeta1, |
|
31 |
BzrDirMetaFormat1, |
|
|
3920.2.17
by Jelmer Vernooij
Override BzrDir.sprout() to avoid accelerator_tree's from being used. |
32 |
format_registry, |
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
33 |
)
|
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
34 |
from bzrlib.inventory import Inventory |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
35 |
from bzrlib.revision import Revision |
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
36 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
37 |
|
|
3920.2.7
by Jelmer Vernooij
Add comments about dummy vcs. |
38 |
# This is the dummy foreign revision control system, used
|
39 |
# mainly here in the testsuite to test the foreign VCS infrastructure.
|
|
40 |
# It is basically standard Bazaar with some minor modifications to
|
|
41 |
# make it "foreign".
|
|
42 |
#
|
|
43 |
# It has the following differences to "regular" Bazaar:
|
|
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
44 |
# - The control directory is named ".dummy", not ".bzr".
|
|
3920.2.7
by Jelmer Vernooij
Add comments about dummy vcs. |
45 |
# - The revision ids are tuples, not strings.
|
|
3920.2.20
by Jelmer Vernooij
Fix dpush tests. |
46 |
# - Doesn't support more than one parent natively
|
|
3920.2.7
by Jelmer Vernooij
Add comments about dummy vcs. |
47 |
|
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
48 |
|
49 |
class DummyForeignVcsMapping(foreign.VcsMapping): |
|
50 |
"""A simple mapping for the dummy Foreign VCS, for use with testing.""" |
|
51 |
||
52 |
def __eq__(self, other): |
|
53 |
return type(self) == type(other) |
|
54 |
||
55 |
def revision_id_bzr_to_foreign(self, bzr_revid): |
|
56 |
return tuple(bzr_revid[len("dummy-v1:"):].split("-")), self |
|
57 |
||
58 |
def revision_id_foreign_to_bzr(self, foreign_revid): |
|
59 |
return "dummy-v1:%s-%s-%s" % foreign_revid |
|
60 |
||
61 |
||
62 |
class DummyForeignVcsMappingRegistry(foreign.VcsMappingRegistry): |
|
63 |
||
64 |
def revision_id_bzr_to_foreign(self, revid): |
|
65 |
if not revid.startswith("dummy-"): |
|
66 |
raise errors.InvalidRevisionId(revid, None) |
|
67 |
mapping_version = revid[len("dummy-"):len("dummy-vx")] |
|
68 |
mapping = self.get(mapping_version) |
|
69 |
return mapping.revision_id_bzr_to_foreign(revid) |
|
70 |
||
71 |
||
72 |
class DummyForeignVcs(foreign.ForeignVcs): |
|
73 |
"""A dummy Foreign VCS, for use with testing. |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
74 |
|
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
75 |
It has revision ids that are a tuple with three strings.
|
76 |
"""
|
|
77 |
||
78 |
def __init__(self): |
|
79 |
self.mapping_registry = DummyForeignVcsMappingRegistry() |
|
|
4032.1.1
by John Arbash Meinel
Merge the removal of all trailing whitespace, and resolve conflicts. |
80 |
self.mapping_registry.register("v1", DummyForeignVcsMapping(self), |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
81 |
"Version 1") |
82 |
||
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
83 |
def show_foreign_revid(self, foreign_revid): |
84 |
return { "dummy ding": "%s/%s\\%s" % foreign_revid } |
|
85 |
||
86 |
||
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
87 |
class DummyForeignVcsBranch(branch.BzrBranch6,foreign.ForeignBranch): |
88 |
"""A Dummy VCS Branch.""" |
|
89 |
||
90 |
def __init__(self, _format, _control_files, a_bzrdir, *args, **kwargs): |
|
91 |
self._format = _format |
|
92 |
self._base = a_bzrdir.transport.base |
|
93 |
foreign.ForeignBranch.__init__(self, DummyForeignVcsMapping(DummyForeignVcs())) |
|
94 |
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir, *args, **kwargs) |
|
95 |
||
96 |
def dpull(self, source, stop_revision=None): |
|
|
3920.2.20
by Jelmer Vernooij
Fix dpush tests. |
97 |
# This just handles simple cases, but that's good enough for tests
|
98 |
my_history = self.revision_history() |
|
99 |
their_history = source.revision_history() |
|
100 |
if their_history[:min(len(my_history), len(their_history))] != my_history: |
|
101 |
raise errors.DivergedBranches(self, source) |
|
102 |
todo = their_history[len(my_history):] |
|
103 |
revidmap = {} |
|
104 |
for revid in todo: |
|
105 |
rev = source.repository.get_revision(revid) |
|
106 |
tree = source.repository.revision_tree(revid) |
|
107 |
builder = self.get_commit_builder([self.last_revision()], |
|
108 |
self.get_config(), rev.timestamp, |
|
109 |
rev.timezone, rev.committer, rev.properties) |
|
110 |
for path, ie in tree.inventory.iter_entries(): |
|
111 |
builder.record_entry_contents(ie.copy(), |
|
112 |
[self.repository.get_inventory(self.last_revision())], |
|
113 |
path, tree, None) |
|
114 |
builder.finish_inventory() |
|
115 |
revidmap[revid] = builder.commit(rev.message) |
|
116 |
return revidmap |
|
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
117 |
|
118 |
||
119 |
class DummyForeignVcsBranchFormat(branch.BzrBranchFormat6): |
|
120 |
||
121 |
def get_format_string(self): |
|
122 |
return "Branch for Testing" |
|
123 |
||
124 |
def __init__(self): |
|
125 |
super(DummyForeignVcsBranchFormat, self).__init__() |
|
126 |
self._matchingbzrdir = DummyForeignVcsDirFormat() |
|
127 |
||
128 |
def open(self, a_bzrdir, _found=False): |
|
129 |
if not _found: |
|
130 |
raise NotImplementedError |
|
131 |
try: |
|
132 |
transport = a_bzrdir.get_branch_transport(None) |
|
133 |
control_files = lockable_files.LockableFiles(transport, 'lock', |
|
134 |
lockdir.LockDir) |
|
135 |
return DummyForeignVcsBranch(_format=self, |
|
136 |
_control_files=control_files, |
|
137 |
a_bzrdir=a_bzrdir, |
|
138 |
_repository=a_bzrdir.find_repository()) |
|
139 |
except errors.NoSuchFile: |
|
140 |
raise errors.NotBranchError(path=transport.base) |
|
141 |
||
142 |
||
|
3920.2.15
by Jelmer Vernooij
Add a DummyForeignVcsDir class. |
143 |
class DummyForeignVcsDirFormat(BzrDirMetaFormat1): |
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
144 |
"""BzrDirFormat for the dummy foreign VCS.""" |
145 |
||
|
3920.2.15
by Jelmer Vernooij
Add a DummyForeignVcsDir class. |
146 |
@classmethod
|
147 |
def get_format_string(cls): |
|
148 |
return "A Dummy VCS Dir" |
|
149 |
||
150 |
@classmethod
|
|
151 |
def get_format_description(cls): |
|
152 |
return "A Dummy VCS Dir" |
|
153 |
||
154 |
@classmethod
|
|
155 |
def is_supported(cls): |
|
156 |
return True |
|
157 |
||
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
158 |
def get_branch_format(self): |
159 |
return DummyForeignVcsBranchFormat() |
|
160 |
||
|
3920.2.15
by Jelmer Vernooij
Add a DummyForeignVcsDir class. |
161 |
@classmethod
|
162 |
def probe_transport(klass, transport): |
|
163 |
"""Return the .bzrdir style format present in a directory.""" |
|
164 |
if not transport.has('.dummy'): |
|
165 |
raise errors.NotBranchError(path=transport.base) |
|
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
166 |
return klass() |
|
3920.2.15
by Jelmer Vernooij
Add a DummyForeignVcsDir class. |
167 |
|
168 |
def initialize_on_transport(self, transport): |
|
169 |
"""Initialize a new bzrdir in the base directory of a Transport.""" |
|
170 |
# Since we don't have a .bzr directory, inherit the
|
|
171 |
# mode from the root directory
|
|
172 |
temp_control = lockable_files.LockableFiles(transport, |
|
173 |
'', lockable_files.TransportLock) |
|
174 |
temp_control._transport.mkdir('.dummy', |
|
175 |
# FIXME: RBC 20060121 don't peek under
|
|
176 |
# the covers
|
|
177 |
mode=temp_control._dir_mode) |
|
178 |
del temp_control |
|
179 |
bzrdir_transport = transport.clone('.dummy') |
|
180 |
# NB: no need to escape relative paths that are url safe.
|
|
181 |
control_files = lockable_files.LockableFiles(bzrdir_transport, |
|
182 |
self._lock_file_name, self._lock_class) |
|
183 |
control_files.create_lock() |
|
184 |
return self.open(transport, _found=True) |
|
185 |
||
186 |
def _open(self, transport): |
|
187 |
return DummyForeignVcsDir(transport, self) |
|
188 |
||
189 |
||
190 |
class DummyForeignVcsDir(BzrDirMeta1): |
|
191 |
||
192 |
def __init__(self, _transport, _format): |
|
193 |
self._format = _format |
|
194 |
self.transport = _transport.clone('.dummy') |
|
195 |
self.root_transport = _transport |
|
196 |
self._mode_check_done = False |
|
|
3920.2.19
by Jelmer Vernooij
Get everything except dpull itself working. |
197 |
self._control_files = lockable_files.LockableFiles(self.transport, |
198 |
"lock", lockable_files.TransportLock) |
|
199 |
||
200 |
def open_branch(self): |
|
201 |
return self._format.get_branch_format().open(self, _found=True) |
|
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
202 |
|
|
3920.2.17
by Jelmer Vernooij
Override BzrDir.sprout() to avoid accelerator_tree's from being used. |
203 |
def cloning_metadir(self, stacked=False): |
204 |
"""Produce a metadir suitable for cloning with.""" |
|
205 |
return format_registry.make_bzrdir("default") |
|
206 |
||
207 |
def sprout(self, url, revision_id=None, force_new_repo=False, |
|
208 |
recurse='down', possible_transports=None, |
|
209 |
accelerator_tree=None, hardlink=False, stacked=False, |
|
210 |
source_branch=None): |
|
211 |
# dirstate doesn't cope with accelerator_trees well
|
|
212 |
# that have a different control dir
|
|
213 |
return super(DummyForeignVcsDir, self).sprout(url=url, |
|
214 |
revision_id=revision_id, force_new_repo=force_new_repo, |
|
215 |
recurse=recurse, possible_transports=possible_transports, |
|
216 |
hardlink=hardlink, stacked=stacked, source_branch=source_branch) |
|
217 |
||
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
218 |
|
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
219 |
class ForeignVcsRegistryTests(TestCase): |
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
220 |
"""Tests for the ForeignVcsRegistry class.""" |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
221 |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
222 |
def test_parse_revision_id_no_dash(self): |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
223 |
reg = foreign.ForeignVcsRegistry() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
224 |
self.assertRaises(errors.InvalidRevisionId, |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
225 |
reg.parse_revision_id, "invalid") |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
226 |
|
227 |
def test_parse_revision_id_unknown_mapping(self): |
|
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
228 |
reg = foreign.ForeignVcsRegistry() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
229 |
self.assertRaises(errors.InvalidRevisionId, |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
230 |
reg.parse_revision_id, "unknown-foreignrevid") |
231 |
||
232 |
def test_parse_revision_id(self): |
|
233 |
reg = foreign.ForeignVcsRegistry() |
|
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
234 |
vcs = DummyForeignVcs() |
235 |
reg.register("dummy", vcs, "Dummy VCS") |
|
236 |
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping(vcs)), |
|
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
237 |
reg.parse_revision_id("dummy-v1:some-foreign-revid")) |
238 |
||
239 |
||
240 |
class ForeignRevisionTests(TestCase): |
|
241 |
"""Tests for the ForeignRevision class.""" |
|
242 |
||
243 |
def test_create(self): |
|
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
244 |
mapp = DummyForeignVcsMapping(DummyForeignVcs()) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
245 |
rev = foreign.ForeignRevision(("a", "foreign", "revid"), |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
246 |
mapp, "roundtripped-revid") |
247 |
self.assertEquals("", rev.inventory_sha1) |
|
248 |
self.assertEquals(("a", "foreign", "revid"), rev.foreign_revid) |
|
249 |
self.assertEquals(mapp, rev.mapping) |
|
250 |
||
251 |
||
252 |
class ShowForeignPropertiesTests(TestCase): |
|
253 |
"""Tests for the show_foreign_properties() function.""" |
|
254 |
||
255 |
def setUp(self): |
|
256 |
super(ShowForeignPropertiesTests, self).setUp() |
|
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
257 |
self.vcs = DummyForeignVcs() |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
258 |
foreign.foreign_vcs_registry.register("dummy", |
|
3949.5.1
by Jelmer Vernooij
Move ForeignVcsMapping.show_foreign_revid to ForeignVcs. |
259 |
self.vcs, "Dummy VCS") |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
260 |
|
261 |
def tearDown(self): |
|
262 |
super(ShowForeignPropertiesTests, self).tearDown() |
|
263 |
foreign.foreign_vcs_registry.remove("dummy") |
|
264 |
||
265 |
def test_show_non_foreign(self): |
|
266 |
"""Test use with a native (non-foreign) bzr revision.""" |
|
267 |
self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid"))) |
|
268 |
||
269 |
def test_show_imported(self): |
|
270 |
rev = Revision("dummy-v1:my-foreign-revid") |
|
271 |
self.assertEquals({ "dummy ding": "my/foreign\\revid" }, |
|
272 |
foreign.show_foreign_properties(rev)) |
|
273 |
||
274 |
def test_show_direct(self): |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
275 |
rev = foreign.ForeignRevision(("some", "foreign", "revid"), |
|
4032.1.1
by John Arbash Meinel
Merge the removal of all trailing whitespace, and resolve conflicts. |
276 |
DummyForeignVcsMapping(self.vcs), |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
277 |
"roundtrip-revid") |
278 |
self.assertEquals({ "dummy ding": "some/foreign\\revid" }, |
|
279 |
foreign.show_foreign_properties(rev)) |
|
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
280 |
|
281 |
||
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
282 |
class WorkingTreeFileUpdateTests(TestCaseWithTransport): |
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
283 |
"""Tests for determine_fileid_renames().""" |
284 |
||
285 |
def test_det_renames_same(self): |
|
286 |
a = Inventory() |
|
287 |
a.add_path("bla", "directory", "bla-a") |
|
288 |
b = Inventory() |
|
289 |
b.add_path("bla", "directory", "bla-a") |
|
290 |
self.assertEquals( {}, foreign.determine_fileid_renames(a, b)) |
|
291 |
||
292 |
def test_det_renames_simple(self): |
|
293 |
a = Inventory() |
|
294 |
a.add_path("bla", "directory", "bla-a") |
|
295 |
b = Inventory() |
|
296 |
b.add_path("bla", "directory", "bla-b") |
|
297 |
self.assertEquals( |
|
298 |
{"bla": ("bla-a", "bla-b")}, |
|
299 |
foreign.determine_fileid_renames(a, b)) |
|
300 |
||
301 |
def test_det_renames_root(self): |
|
302 |
a = Inventory() |
|
303 |
a.add_path("", "directory", "bla-a") |
|
304 |
b = Inventory() |
|
305 |
b.add_path("", "directory", "bla-b") |
|
306 |
self.assertEquals( |
|
307 |
{"": ("bla-a", "bla-b")}, |
|
308 |
foreign.determine_fileid_renames(a, b)) |
|
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
309 |
|
310 |
def test_update_workinginv(self): |
|
311 |
a = Inventory() |
|
312 |
a.add_path("bla", "directory", "bla-a") |
|
313 |
b = Inventory() |
|
314 |
b.add_path("bla", "directory", "bla-b") |
|
315 |
wt = self.make_branch_and_tree('br1') |
|
316 |
self.build_tree_contents([('br1/bla', 'original contents\n')]) |
|
317 |
wt.add('bla', 'bla-a') |
|
318 |
foreign.update_workinginv_fileids(wt, a, b) |
|
319 |
wt.lock_read() |
|
320 |
try: |
|
321 |
self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory)) |
|
322 |
finally: |
|
323 |
wt.unlock() |
|
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
324 |
|
325 |
||
326 |
class DummyForeignVcsTests(TestCaseWithTransport): |
|
327 |
"""Very basic test for DummyForeignVcs.""" |
|
328 |
||
329 |
def setUp(self): |
|
330 |
BzrDirFormat.register_control_format(DummyForeignVcsDirFormat) |
|
331 |
self.addCleanup(self.unregister) |
|
332 |
super(DummyForeignVcsTests, self).setUp() |
|
333 |
||
334 |
def unregister(self): |
|
335 |
try: |
|
336 |
BzrDirFormat.unregister_control_format(DummyForeignVcsDirFormat) |
|
337 |
except ValueError: |
|
338 |
pass
|
|
339 |
||
340 |
def test_create(self): |
|
341 |
"""Test we can create dummies.""" |
|
342 |
self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat()) |
|
343 |
dir = BzrDir.open("d") |
|
344 |
self.assertEquals("A Dummy VCS Dir", dir._format.get_format_string()) |
|
345 |
dir.open_repository() |
|
346 |
dir.open_branch() |
|
347 |
dir.open_workingtree() |
|
348 |
||
349 |
def test_sprout(self): |
|
|
3920.2.17
by Jelmer Vernooij
Override BzrDir.sprout() to avoid accelerator_tree's from being used. |
350 |
"""Test we can clone dummies and that the format is not preserved.""" |
|
3920.2.16
by Jelmer Vernooij
Add tests for DummyForeignVcs. |
351 |
self.make_branch_and_tree("d", format=DummyForeignVcsDirFormat()) |
352 |
dir = BzrDir.open("d") |
|
353 |
newdir = dir.sprout("e") |
|
|
3920.2.17
by Jelmer Vernooij
Override BzrDir.sprout() to avoid accelerator_tree's from being used. |
354 |
self.assertNotEquals("A Dummy VCS Dir", newdir._format.get_format_string()) |