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 |
||
20 |
from bzrlib import errors, foreign |
|
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
21 |
from bzrlib.bzrdir import BzrDirFormat, BzrDirMeta1 |
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
22 |
from bzrlib.inventory import Inventory |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
23 |
from bzrlib.revision import Revision |
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
24 |
from bzrlib.tests import TestCase, TestCaseWithTransport |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
25 |
|
|
3920.2.7
by Jelmer Vernooij
Add comments about dummy vcs. |
26 |
# This is the dummy foreign revision control system, used
|
27 |
# mainly here in the testsuite to test the foreign VCS infrastructure.
|
|
28 |
# It is basically standard Bazaar with some minor modifications to
|
|
29 |
# make it "foreign".
|
|
30 |
#
|
|
31 |
# It has the following differences to "regular" Bazaar:
|
|
32 |
# - The revision ids are tuples, not strings.
|
|
33 |
||
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
34 |
|
35 |
class DummyForeignVcsMapping(foreign.VcsMapping): |
|
36 |
"""A simple mapping for the dummy Foreign VCS, for use with testing.""" |
|
37 |
||
38 |
def __eq__(self, other): |
|
39 |
return type(self) == type(other) |
|
40 |
||
41 |
def show_foreign_revid(self, foreign_revid): |
|
42 |
return { "dummy ding": "%s/%s\\%s" % foreign_revid } |
|
43 |
||
44 |
def revision_id_bzr_to_foreign(self, bzr_revid): |
|
45 |
return tuple(bzr_revid[len("dummy-v1:"):].split("-")), self |
|
46 |
||
47 |
def revision_id_foreign_to_bzr(self, foreign_revid): |
|
48 |
return "dummy-v1:%s-%s-%s" % foreign_revid |
|
49 |
||
50 |
||
51 |
class DummyForeignVcsMappingRegistry(foreign.VcsMappingRegistry): |
|
52 |
||
53 |
def revision_id_bzr_to_foreign(self, revid): |
|
54 |
if not revid.startswith("dummy-"): |
|
55 |
raise errors.InvalidRevisionId(revid, None) |
|
56 |
mapping_version = revid[len("dummy-"):len("dummy-vx")] |
|
57 |
mapping = self.get(mapping_version) |
|
58 |
return mapping.revision_id_bzr_to_foreign(revid) |
|
59 |
||
60 |
||
61 |
class DummyForeignVcs(foreign.ForeignVcs): |
|
62 |
"""A dummy Foreign VCS, for use with testing. |
|
63 |
|
|
64 |
It has revision ids that are a tuple with three strings.
|
|
65 |
"""
|
|
66 |
||
67 |
def __init__(self): |
|
68 |
self.mapping_registry = DummyForeignVcsMappingRegistry() |
|
69 |
self.mapping_registry.register("v1", DummyForeignVcsMapping(), |
|
70 |
"Version 1") |
|
71 |
||
72 |
||
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
73 |
class DummyForeignVcsBzrDirFormat(BzrDirMeta1): |
74 |
"""BzrDirFormat for the dummy foreign VCS.""" |
|
75 |
||
76 |
def get_format_string(self): |
|
77 |
return "A Dummy VCS Dir" |
|
78 |
||
79 |
def get_description_string(self): |
|
80 |
return "A Dummy VCS Dir" |
|
81 |
||
82 |
||
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
83 |
class ForeignVcsRegistryTests(TestCase): |
|
3920.2.10
by Jelmer Vernooij
More work trying to implement a dummy version control system. |
84 |
"""Tests for the ForeignVcsRegistry class.""" |
|
3830.4.5
by Jelmer Vernooij
add tests for VCS infrastructure classes. |
85 |
|
86 |
def test_parse_revision_id_no_dash(self): |
|
87 |
reg = foreign.ForeignVcsRegistry() |
|
88 |
self.assertRaises(errors.InvalidRevisionId, |
|
89 |
reg.parse_revision_id, "invalid") |
|
90 |
||
91 |
def test_parse_revision_id_unknown_mapping(self): |
|
92 |
reg = foreign.ForeignVcsRegistry() |
|
93 |
self.assertRaises(errors.InvalidRevisionId, |
|
94 |
reg.parse_revision_id, "unknown-foreignrevid") |
|
95 |
||
96 |
def test_parse_revision_id(self): |
|
97 |
reg = foreign.ForeignVcsRegistry() |
|
98 |
reg.register("dummy", DummyForeignVcs(), "Dummy VCS") |
|
99 |
self.assertEquals((("some", "foreign", "revid"), DummyForeignVcsMapping()), |
|
100 |
reg.parse_revision_id("dummy-v1:some-foreign-revid")) |
|
101 |
||
102 |
||
103 |
class ForeignRevisionTests(TestCase): |
|
104 |
"""Tests for the ForeignRevision class.""" |
|
105 |
||
106 |
def test_create(self): |
|
107 |
mapp = DummyForeignVcsMapping() |
|
108 |
rev = foreign.ForeignRevision(("a", "foreign", "revid"), |
|
109 |
mapp, "roundtripped-revid") |
|
110 |
self.assertEquals("", rev.inventory_sha1) |
|
111 |
self.assertEquals(("a", "foreign", "revid"), rev.foreign_revid) |
|
112 |
self.assertEquals(mapp, rev.mapping) |
|
113 |
||
114 |
||
115 |
class ShowForeignPropertiesTests(TestCase): |
|
116 |
"""Tests for the show_foreign_properties() function.""" |
|
117 |
||
118 |
def setUp(self): |
|
119 |
super(ShowForeignPropertiesTests, self).setUp() |
|
120 |
foreign.foreign_vcs_registry.register("dummy", |
|
121 |
DummyForeignVcs(), "Dummy VCS") |
|
122 |
||
123 |
def tearDown(self): |
|
124 |
super(ShowForeignPropertiesTests, self).tearDown() |
|
125 |
foreign.foreign_vcs_registry.remove("dummy") |
|
126 |
||
127 |
def test_show_non_foreign(self): |
|
128 |
"""Test use with a native (non-foreign) bzr revision.""" |
|
129 |
self.assertEquals({}, foreign.show_foreign_properties(Revision("arevid"))) |
|
130 |
||
131 |
def test_show_imported(self): |
|
132 |
rev = Revision("dummy-v1:my-foreign-revid") |
|
133 |
self.assertEquals({ "dummy ding": "my/foreign\\revid" }, |
|
134 |
foreign.show_foreign_properties(rev)) |
|
135 |
||
136 |
def test_show_direct(self): |
|
137 |
rev = foreign.ForeignRevision(("some", "foreign", "revid"), |
|
138 |
DummyForeignVcsMapping(), |
|
139 |
"roundtrip-revid") |
|
140 |
self.assertEquals({ "dummy ding": "some/foreign\\revid" }, |
|
141 |
foreign.show_foreign_properties(rev)) |
|
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
142 |
|
143 |
||
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
144 |
class WorkingTreeFileUpdateTests(TestCaseWithTransport): |
|
3920.2.3
by Jelmer Vernooij
Make determine_fileid_renames() return a dictionary. |
145 |
"""Tests for determine_fileid_renames().""" |
146 |
||
147 |
def test_det_renames_same(self): |
|
148 |
a = Inventory() |
|
149 |
a.add_path("bla", "directory", "bla-a") |
|
150 |
b = Inventory() |
|
151 |
b.add_path("bla", "directory", "bla-a") |
|
152 |
self.assertEquals( {}, foreign.determine_fileid_renames(a, b)) |
|
153 |
||
154 |
def test_det_renames_simple(self): |
|
155 |
a = Inventory() |
|
156 |
a.add_path("bla", "directory", "bla-a") |
|
157 |
b = Inventory() |
|
158 |
b.add_path("bla", "directory", "bla-b") |
|
159 |
self.assertEquals( |
|
160 |
{"bla": ("bla-a", "bla-b")}, |
|
161 |
foreign.determine_fileid_renames(a, b)) |
|
162 |
||
163 |
def test_det_renames_root(self): |
|
164 |
a = Inventory() |
|
165 |
a.add_path("", "directory", "bla-a") |
|
166 |
b = Inventory() |
|
167 |
b.add_path("", "directory", "bla-b") |
|
168 |
self.assertEquals( |
|
169 |
{"": ("bla-a", "bla-b")}, |
|
170 |
foreign.determine_fileid_renames(a, b)) |
|
|
3920.2.4
by Jelmer Vernooij
Add tests for update_workinginv_fileids. |
171 |
|
172 |
def test_update_workinginv(self): |
|
173 |
a = Inventory() |
|
174 |
a.add_path("bla", "directory", "bla-a") |
|
175 |
b = Inventory() |
|
176 |
b.add_path("bla", "directory", "bla-b") |
|
177 |
wt = self.make_branch_and_tree('br1') |
|
178 |
self.build_tree_contents([('br1/bla', 'original contents\n')]) |
|
179 |
wt.add('bla', 'bla-a') |
|
180 |
foreign.update_workinginv_fileids(wt, a, b) |
|
181 |
wt.lock_read() |
|
182 |
try: |
|
183 |
self.assertEquals(["TREE_ROOT", "bla-b"], list(wt.inventory)) |
|
184 |
finally: |
|
185 |
wt.unlock() |