bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2011, 2016 Canonical Ltd
|
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for the ControlDir facility.
|
|
18 |
||
19 |
For interface contract tests, see tests/per_control_dir.
|
|
20 |
"""
|
|
21 |
||
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
22 |
from .. import ( |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
23 |
controldir, |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
24 |
errors, |
|
5669.3.11
by Jelmer Vernooij
review feedback from vila. |
25 |
tests, |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
26 |
ui, |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
27 |
)
|
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
28 |
from .scenarios import load_tests_apply_scenarios |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
29 |
|
30 |
||
31 |
load_tests = load_tests_apply_scenarios |
|
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
32 |
|
33 |
||
|
5669.3.10
by Jelmer Vernooij
Use ControlComponentFormat. |
34 |
class SampleComponentFormat(controldir.ControlComponentFormat): |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
35 |
|
36 |
def get_format_string(self): |
|
37 |
return "Example component format." |
|
38 |
||
39 |
||
|
5669.3.10
by Jelmer Vernooij
Use ControlComponentFormat. |
40 |
class SampleExtraComponentFormat(controldir.ControlComponentFormat): |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
41 |
"""Extra format, no format string.""" |
42 |
||
43 |
||
|
5669.3.11
by Jelmer Vernooij
review feedback from vila. |
44 |
class TestMetaComponentFormatRegistry(tests.TestCase): |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
45 |
|
46 |
def setUp(self): |
|
47 |
super(TestMetaComponentFormatRegistry, self).setUp() |
|
|
5669.3.9
by Jelmer Vernooij
Consistent naming. |
48 |
self.registry = controldir.ControlComponentFormatRegistry() |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
49 |
|
50 |
def test_register_unregister_format(self): |
|
51 |
format = SampleComponentFormat() |
|
52 |
self.registry.register(format) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
53 |
self.assertEqual(format, |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
54 |
self.registry.get("Example component format.")) |
55 |
self.registry.remove(format) |
|
56 |
self.assertRaises(KeyError, self.registry.get, |
|
57 |
"Example component format.") |
|
58 |
||
59 |
def test_get_all(self): |
|
60 |
format = SampleComponentFormat() |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
61 |
self.assertEqual([], self.registry._get_all()) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
62 |
self.registry.register(format) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
63 |
self.assertEqual([format], self.registry._get_all()) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
64 |
|
|
5676.1.7
by Jelmer Vernooij
Add test for ControlComponentFormatRegistry._get_all_modules. |
65 |
def test_get_all_modules(self): |
66 |
format = SampleComponentFormat() |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
67 |
self.assertEqual(set(), self.registry._get_all_modules()) |
|
5676.1.7
by Jelmer Vernooij
Add test for ControlComponentFormatRegistry._get_all_modules. |
68 |
self.registry.register(format) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
69 |
self.assertEqual( |
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
70 |
{"breezy.tests.test_controldir"}, |
|
5676.1.7
by Jelmer Vernooij
Add test for ControlComponentFormatRegistry._get_all_modules. |
71 |
self.registry._get_all_modules()) |
72 |
||
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
73 |
def test_register_extra(self): |
74 |
format = SampleExtraComponentFormat() |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
75 |
self.assertEqual([], self.registry._get_all()) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
76 |
self.registry.register_extra(format) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
77 |
self.assertEqual([format], self.registry._get_all()) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
78 |
|
79 |
def test_register_extra_lazy(self): |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
80 |
self.assertEqual([], self.registry._get_all()) |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
81 |
self.registry.register_extra_lazy("breezy.tests.test_controldir", |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
82 |
"SampleExtraComponentFormat") |
83 |
formats = self.registry._get_all() |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
84 |
self.assertEqual(1, len(formats)) |
|
5669.3.8
by Jelmer Vernooij
Refactor, move to bzrlib.controldir. |
85 |
self.assertIsInstance(formats[0], SampleExtraComponentFormat) |
|
5712.3.3
by Jelmer Vernooij
Support lazy registration of ControlDirFormat. |
86 |
|
87 |
||
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
88 |
class TestProber(tests.TestCaseWithTransport): |
|
5712.3.14
by Jelmer Vernooij
Add Prober.known_formats. |
89 |
"""Per-prober tests.""" |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
90 |
|
91 |
scenarios = [ |
|
92 |
(prober_cls.__name__, {'prober_cls': prober_cls}) |
|
93 |
for prober_cls in controldir.ControlDirFormat._probers] |
|
94 |
||
95 |
def setUp(self): |
|
96 |
super(TestProber, self).setUp() |
|
97 |
self.prober = self.prober_cls() |
|
98 |
||
99 |
def test_probe_transport_empty(self): |
|
100 |
transport = self.get_transport(".") |
|
101 |
self.assertRaises(errors.NotBranchError, |
|
102 |
self.prober.probe_transport, transport) |
|
103 |
||
104 |
def test_known_formats(self): |
|
|
5712.3.15
by Jelmer Vernooij
Remove unused register format functions. |
105 |
known_formats = self.prober_cls.known_formats() |
|
5712.3.13
by Jelmer Vernooij
Add Prober.known_formats(). |
106 |
self.assertIsInstance(known_formats, set) |
107 |
for format in known_formats: |
|
108 |
self.assertIsInstance(format, controldir.ControlDirFormat, |
|
109 |
repr(format)) |
|
|
5712.3.18
by Jelmer Vernooij
Some more test fixes. |
110 |
|
111 |
||
112 |
class NotBzrDir(controldir.ControlDir): |
|
113 |
"""A non .bzr based control directory.""" |
|
114 |
||
115 |
def __init__(self, transport, format): |
|
116 |
self._format = format |
|
117 |
self.root_transport = transport |
|
118 |
self.transport = transport.clone('.not') |
|
119 |
||
120 |
||
121 |
class NotBzrDirFormat(controldir.ControlDirFormat): |
|
122 |
"""A test class representing any non-.bzr based disk format.""" |
|
123 |
||
124 |
def initialize_on_transport(self, transport): |
|
125 |
"""Initialize a new .not dir in the base directory of a Transport.""" |
|
126 |
transport.mkdir('.not') |
|
127 |
return self.open(transport) |
|
128 |
||
129 |
def open(self, transport): |
|
130 |
"""Open this directory.""" |
|
131 |
return NotBzrDir(transport, self) |
|
132 |
||
133 |
||
134 |
class NotBzrDirProber(controldir.Prober): |
|
135 |
||
136 |
def probe_transport(self, transport): |
|
137 |
"""Our format is present if the transport ends in '.not/'.""" |
|
138 |
if transport.has('.not'): |
|
139 |
return NotBzrDirFormat() |
|
140 |
||
141 |
@classmethod
|
|
142 |
def known_formats(cls): |
|
|
6619.3.12
by Jelmer Vernooij
Use 2to3 set_literal fixer. |
143 |
return {NotBzrDirFormat()} |
|
5712.3.18
by Jelmer Vernooij
Some more test fixes. |
144 |
|
145 |
||
146 |
class TestNotBzrDir(tests.TestCaseWithTransport): |
|
147 |
"""Tests for using the controldir api with a non .bzr based disk format. |
|
148 |
||
149 |
If/when one of these is in the core, we can let the implementation tests
|
|
150 |
verify this works.
|
|
151 |
"""
|
|
152 |
||
153 |
def test_create_and_find_format(self): |
|
154 |
# create a .notbzr dir
|
|
155 |
format = NotBzrDirFormat() |
|
156 |
dir = format.initialize(self.get_url()) |
|
157 |
self.assertIsInstance(dir, NotBzrDir) |
|
158 |
# now probe for it.
|
|
159 |
controldir.ControlDirFormat.register_prober(NotBzrDirProber) |
|
160 |
try: |
|
161 |
found = controldir.ControlDirFormat.find_format(self.get_transport()) |
|
162 |
self.assertIsInstance(found, NotBzrDirFormat) |
|
163 |
finally: |
|
164 |
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber) |
|
165 |
||
166 |
def test_included_in_known_formats(self): |
|
167 |
controldir.ControlDirFormat.register_prober(NotBzrDirProber) |
|
168 |
self.addCleanup(controldir.ControlDirFormat.unregister_prober, NotBzrDirProber) |
|
169 |
formats = controldir.ControlDirFormat.known_formats() |
|
170 |
self.assertIsInstance(formats, set) |
|
171 |
for format in formats: |
|
172 |
if isinstance(format, NotBzrDirFormat): |
|
173 |
break
|
|
174 |
else: |
|
175 |
self.fail("No NotBzrDirFormat in %s" % formats) |
|
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
176 |
|
177 |
||
178 |
class UnsupportedControlComponentFormat(controldir.ControlComponentFormat): |
|
179 |
||
180 |
def is_supported(self): |
|
181 |
return False |
|
182 |
||
183 |
||
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
184 |
class OldControlComponentFormat(controldir.ControlComponentFormat): |
185 |
||
186 |
def get_format_description(self): |
|
187 |
return "An old format that is slow" |
|
188 |
||
189 |
upgrade_recommended = True |
|
190 |
||
191 |
||
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
192 |
class DefaultControlComponentFormatTests(tests.TestCase): |
193 |
"""Tests for default ControlComponentFormat implementation.""" |
|
194 |
||
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
195 |
def test_check_support_status_unsupported(self): |
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
196 |
self.assertRaises(errors.UnsupportedFormatError, |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
197 |
UnsupportedControlComponentFormat().check_support_status, |
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
198 |
allow_unsupported=False) |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
199 |
UnsupportedControlComponentFormat().check_support_status( |
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
200 |
allow_unsupported=True) |
201 |
||
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
202 |
def test_check_support_status_supported(self): |
203 |
controldir.ControlComponentFormat().check_support_status( |
|
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
204 |
allow_unsupported=False) |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
205 |
controldir.ControlComponentFormat().check_support_status( |
|
5717.1.4
by Jelmer Vernooij
Test default control component format implementation. |
206 |
allow_unsupported=True) |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
207 |
|
208 |
def test_recommend_upgrade_current_format(self): |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
209 |
ui.ui_factory = tests.TestUIFactory() |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
210 |
format = controldir.ControlComponentFormat() |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
211 |
format.check_support_status(allow_unsupported=False, |
212 |
recommend_upgrade=True) |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
213 |
self.assertEqual("", ui.ui_factory.stderr.getvalue()) |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
214 |
|
215 |
def test_recommend_upgrade_old_format(self): |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
216 |
ui.ui_factory = tests.TestUIFactory() |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
217 |
format = OldControlComponentFormat() |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
218 |
format.check_support_status(allow_unsupported=False, |
219 |
recommend_upgrade=False) |
|
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
220 |
self.assertEqual("", ui.ui_factory.stderr.getvalue()) |
|
5717.1.7
by Jelmer Vernooij
Rename check_status -> check_support_status. |
221 |
format.check_support_status(allow_unsupported=False, |
222 |
recommend_upgrade=True, basedir='apath') |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
223 |
self.assertEqual( |
|
5717.1.5
by Jelmer Vernooij
Use recommend_upgrade. |
224 |
'An old format that is slow is deprecated and a better format '
|
225 |
'is available.\nIt is recommended that you upgrade by running ' |
|
|
6622.1.30
by Jelmer Vernooij
Some more test fixes. |
226 |
'the command\n brz upgrade apath\n', |
|
6621.22.2
by Martin
Use BytesIO or StringIO from bzrlib.sixish |
227 |
ui.ui_factory.stderr.getvalue()) |
|
6681.2.4
by Jelmer Vernooij
More renames. |
228 |
|
229 |
||
230 |
class IsControlFilenameTest(tests.TestCase): |
|
231 |
||
232 |
def test_is_bzrdir(self): |
|
233 |
self.assertTrue(controldir.is_control_filename('.bzr')) |
|
234 |
||
235 |
def test_is_not_bzrdir(self): |
|
236 |
self.assertFalse(controldir.is_control_filename('.git')) |
|
237 |
self.assertFalse(controldir.is_control_filename('bla')) |