19
19
For interface contract tests, see tests/per_control_dir.
28
from .scenarios import load_tests_apply_scenarios
28
from brzlib.tests.scenarios import load_tests_apply_scenarios
31
31
load_tests = load_tests_apply_scenarios
34
class TestErrors(tests.TestCase):
36
def test_must_have_working_tree(self):
37
err = controldir.MustHaveWorkingTree('foo', 'bar')
38
self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
42
34
class SampleComponentFormat(controldir.ControlComponentFormat):
44
36
def get_format_string(self):
45
return b"Example component format."
37
return "Example component format."
48
40
class SampleExtraComponentFormat(controldir.ControlComponentFormat):
59
51
format = SampleComponentFormat()
60
52
self.registry.register(format)
61
53
self.assertEqual(format,
62
self.registry.get(b"Example component format."))
54
self.registry.get("Example component format."))
63
55
self.registry.remove(format)
64
56
self.assertRaises(KeyError, self.registry.get,
65
b"Example component format.")
57
"Example component format.")
67
59
def test_get_all(self):
68
60
format = SampleComponentFormat()
75
67
self.assertEqual(set(), self.registry._get_all_modules())
76
68
self.registry.register(format)
78
{"breezy.tests.test_controldir"},
70
set(["brzlib.tests.test_controldir"]),
79
71
self.registry._get_all_modules())
81
73
def test_register_extra(self):
87
79
def test_register_extra_lazy(self):
88
80
self.assertEqual([], self.registry._get_all())
89
self.registry.register_extra_lazy("breezy.tests.test_controldir",
90
"SampleExtraComponentFormat")
81
self.registry.register_extra_lazy("brzlib.tests.test_controldir",
82
"SampleExtraComponentFormat")
91
83
formats = self.registry._get_all()
92
84
self.assertEqual(1, len(formats))
93
85
self.assertIsInstance(formats[0], SampleExtraComponentFormat)
88
class TestControlDirFormatDeprecated(tests.TestCaseWithTransport):
89
"""Tests for removed registration method in the ControlDirFormat facility."""
91
def test_register_format(self):
92
self.assertRaises(errors.BzrError,
93
controldir.ControlDirFormat.register_format, object())
96
96
class TestProber(tests.TestCaseWithTransport):
97
97
"""Per-prober tests."""
104
104
super(TestProber, self).setUp()
105
105
self.prober = self.prober_cls()
107
def test_priority(self):
108
transport = self.get_transport(".")
109
self.assertIsInstance(self.prober.priority(transport), int)
111
107
def test_probe_transport_empty(self):
112
108
transport = self.get_transport(".")
113
109
self.assertRaises(errors.NotBranchError,
114
self.prober.probe_transport, transport)
110
self.prober.probe_transport, transport)
116
112
def test_known_formats(self):
117
113
known_formats = self.prober_cls.known_formats()
118
self.assertIsInstance(known_formats, list)
114
self.assertIsInstance(known_formats, set)
119
115
for format in known_formats:
120
116
self.assertIsInstance(format, controldir.ControlDirFormat,
124
120
class NotBzrDir(controldir.ControlDir):
170
166
# now probe for it.
171
167
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
173
found = controldir.ControlDirFormat.find_format(
174
self.get_transport())
169
found = controldir.ControlDirFormat.find_format(self.get_transport())
175
170
self.assertIsInstance(found, NotBzrDirFormat)
177
172
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
179
174
def test_included_in_known_formats(self):
180
175
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
182
controldir.ControlDirFormat.unregister_prober, NotBzrDirProber)
176
self.addCleanup(controldir.ControlDirFormat.unregister_prober, NotBzrDirProber)
183
177
formats = controldir.ControlDirFormat.known_formats()
184
self.assertIsInstance(formats, list)
178
self.assertIsInstance(formats, set)
185
179
for format in formats:
186
180
if isinstance(format, NotBzrDirFormat):
209
203
def test_check_support_status_unsupported(self):
210
204
self.assertRaises(errors.UnsupportedFormatError,
211
UnsupportedControlComponentFormat().check_support_status,
212
allow_unsupported=False)
205
UnsupportedControlComponentFormat().check_support_status,
206
allow_unsupported=False)
213
207
UnsupportedControlComponentFormat().check_support_status(
214
208
allow_unsupported=True)
220
214
allow_unsupported=True)
222
216
def test_recommend_upgrade_current_format(self):
223
ui.ui_factory = tests.TestUIFactory()
217
stderr = tests.StringIOWrapper()
218
ui.ui_factory = tests.TestUIFactory(stderr=stderr)
224
219
format = controldir.ControlComponentFormat()
225
220
format.check_support_status(allow_unsupported=False,
226
recommend_upgrade=True)
227
self.assertEqual("", ui.ui_factory.stderr.getvalue())
221
recommend_upgrade=True)
222
self.assertEqual("", stderr.getvalue())
229
224
def test_recommend_upgrade_old_format(self):
230
ui.ui_factory = tests.TestUIFactory()
225
stderr = tests.StringIOWrapper()
226
ui.ui_factory = tests.TestUIFactory(stderr=stderr)
231
227
format = OldControlComponentFormat()
232
228
format.check_support_status(allow_unsupported=False,
233
recommend_upgrade=False)
234
self.assertEqual("", ui.ui_factory.stderr.getvalue())
229
recommend_upgrade=False)
230
self.assertEqual("", stderr.getvalue())
235
231
format.check_support_status(allow_unsupported=False,
236
recommend_upgrade=True, basedir='apath')
232
recommend_upgrade=True, basedir='apath')
237
233
self.assertEqual(
238
234
'An old format that is slow is deprecated and a better format '
239
235
'is available.\nIt is recommended that you upgrade by running '
240
'the command\n brz upgrade apath\n',
241
ui.ui_factory.stderr.getvalue())
244
class IsControlFilenameTest(tests.TestCase):
246
def test_is_bzrdir(self):
247
self.assertTrue(controldir.is_control_filename('.bzr'))
248
self.assertTrue(controldir.is_control_filename('.git'))
250
def test_is_not_bzrdir(self):
251
self.assertFalse(controldir.is_control_filename('bla'))
236
'the command\n bzr upgrade apath\n',