83
77
formats = self.registry._get_all()
84
78
self.assertEquals(1, len(formats))
85
79
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
class TestProber(tests.TestCaseWithTransport):
97
"""Per-prober tests."""
100
(prober_cls.__name__, {'prober_cls': prober_cls})
101
for prober_cls in controldir.ControlDirFormat._probers]
104
super(TestProber, self).setUp()
105
self.prober = self.prober_cls()
107
def test_probe_transport_empty(self):
108
transport = self.get_transport(".")
109
self.assertRaises(errors.NotBranchError,
110
self.prober.probe_transport, transport)
112
def test_known_formats(self):
113
known_formats = self.prober_cls.known_formats()
114
self.assertIsInstance(known_formats, set)
115
for format in known_formats:
116
self.assertIsInstance(format, controldir.ControlDirFormat,
120
class NotBzrDir(controldir.ControlDir):
121
"""A non .bzr based control directory."""
123
def __init__(self, transport, format):
124
self._format = format
125
self.root_transport = transport
126
self.transport = transport.clone('.not')
129
class NotBzrDirFormat(controldir.ControlDirFormat):
130
"""A test class representing any non-.bzr based disk format."""
132
def initialize_on_transport(self, transport):
133
"""Initialize a new .not dir in the base directory of a Transport."""
134
transport.mkdir('.not')
135
return self.open(transport)
137
def open(self, transport):
138
"""Open this directory."""
139
return NotBzrDir(transport, self)
142
class NotBzrDirProber(controldir.Prober):
144
def probe_transport(self, transport):
145
"""Our format is present if the transport ends in '.not/'."""
146
if transport.has('.not'):
147
return NotBzrDirFormat()
150
def known_formats(cls):
151
return set([NotBzrDirFormat()])
154
class TestNotBzrDir(tests.TestCaseWithTransport):
155
"""Tests for using the controldir api with a non .bzr based disk format.
157
If/when one of these is in the core, we can let the implementation tests
161
def test_create_and_find_format(self):
162
# create a .notbzr dir
163
format = NotBzrDirFormat()
164
dir = format.initialize(self.get_url())
165
self.assertIsInstance(dir, NotBzrDir)
167
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
169
found = controldir.ControlDirFormat.find_format(self.get_transport())
170
self.assertIsInstance(found, NotBzrDirFormat)
172
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
174
def test_included_in_known_formats(self):
175
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
176
self.addCleanup(controldir.ControlDirFormat.unregister_prober, NotBzrDirProber)
177
formats = controldir.ControlDirFormat.known_formats()
178
self.assertIsInstance(formats, set)
179
for format in formats:
180
if isinstance(format, NotBzrDirFormat):
183
self.fail("No NotBzrDirFormat in %s" % formats)
186
class UnsupportedControlComponentFormat(controldir.ControlComponentFormat):
188
def is_supported(self):
192
class OldControlComponentFormat(controldir.ControlComponentFormat):
194
def get_format_description(self):
195
return "An old format that is slow"
197
upgrade_recommended = True
200
class DefaultControlComponentFormatTests(tests.TestCase):
201
"""Tests for default ControlComponentFormat implementation."""
203
def test_check_support_status_unsupported(self):
204
self.assertRaises(errors.UnsupportedFormatError,
205
UnsupportedControlComponentFormat().check_support_status,
206
allow_unsupported=False)
207
UnsupportedControlComponentFormat().check_support_status(
208
allow_unsupported=True)
210
def test_check_support_status_supported(self):
211
controldir.ControlComponentFormat().check_support_status(
212
allow_unsupported=False)
213
controldir.ControlComponentFormat().check_support_status(
214
allow_unsupported=True)
216
def test_recommend_upgrade_current_format(self):
217
stderr = tests.StringIOWrapper()
218
ui.ui_factory = tests.TestUIFactory(stderr=stderr)
219
format = controldir.ControlComponentFormat()
220
format.check_support_status(allow_unsupported=False,
221
recommend_upgrade=True)
222
self.assertEquals("", stderr.getvalue())
224
def test_recommend_upgrade_old_format(self):
225
stderr = tests.StringIOWrapper()
226
ui.ui_factory = tests.TestUIFactory(stderr=stderr)
227
format = OldControlComponentFormat()
228
format.check_support_status(allow_unsupported=False,
229
recommend_upgrade=False)
230
self.assertEquals("", stderr.getvalue())
231
format.check_support_status(allow_unsupported=False,
232
recommend_upgrade=True, basedir='apath')
234
'An old format that is slow is deprecated and a better format '
235
'is available.\nIt is recommended that you upgrade by running '
236
'the command\n bzr upgrade apath\n',