45
45
bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
46
46
# creating a bzr dir should now create an instrumented dir.
48
result = bzrdir.BzrDir.create('memory:///')
48
result = bzrdir.BzrDir.create('memory:/')
49
49
self.failUnless(isinstance(result, SampleBzrDir))
51
51
bzrdir.BzrDirFormat.set_default_format(old_format)
62
62
class SampleBzrDir(bzrdir.BzrDir):
63
63
"""A sample BzrDir implementation to allow testing static methods."""
65
def create_repository(self, shared=False):
65
def create_repository(self):
66
66
"""See BzrDir.create_repository."""
67
67
return "A repository"
164
164
bzrdir.BzrDirFormat.set_default_format(old_format)
166
def test_create_repository_shared(self):
167
old_format = bzrdir.BzrDirFormat.get_default_format()
168
repo = bzrdir.BzrDir.create_repository('.', shared=True)
169
self.assertTrue(repo.is_shared())
171
def test_create_repository_nonshared(self):
172
old_format = bzrdir.BzrDirFormat.get_default_format()
173
repo = bzrdir.BzrDir.create_repository('.')
174
self.assertFalse(repo.is_shared())
176
166
def test_create_repository_under_shared(self):
177
167
# an explicit create_repository always does so.
178
168
# we trust the format is right from the 'create_repository test'
265
255
bzrdir.BzrDirFormat.set_default_format(old_format)
267
def test_create_branch_convenience_root(self):
268
"""Creating a branch at the root of a fs should work."""
269
self.transport_server = MemoryServer
270
# outside a repo the default convenience output is a repo+branch_tree
271
old_format = bzrdir.BzrDirFormat.get_default_format()
272
bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
274
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url())
275
self.assertRaises(errors.NoWorkingTree,
276
branch.bzrdir.open_workingtree)
277
branch.bzrdir.open_repository()
279
bzrdir.BzrDirFormat.set_default_format(old_format)
281
257
def test_create_branch_convenience_under_shared_repo(self):
282
258
# inside a repo the default convenience output is a branch+ follow the
283
259
# repo tree policy
489
465
bzrdir.BzrDirFormat.set_default_format(old_format)
492
class NotBzrDir(bzrlib.bzrdir.BzrDir):
493
"""A non .bzr based control directory."""
495
def __init__(self, transport, format):
496
self._format = format
497
self.root_transport = transport
498
self.transport = transport.clone('.not')
501
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
502
"""A test class representing any non-.bzr based disk format."""
504
def initialize_on_transport(self, transport):
505
"""Initialize a new .not dir in the base directory of a Transport."""
506
transport.mkdir('.not')
507
return self.open(transport)
509
def open(self, transport):
510
"""Open this directory."""
511
return NotBzrDir(transport, self)
514
def _known_formats(self):
515
return set([NotBzrDirFormat()])
518
def probe_transport(self, transport):
519
"""Our format is present if the transport ends in '.not/'."""
520
if transport.has('.not'):
521
return NotBzrDirFormat()
524
class TestNotBzrDir(TestCaseWithTransport):
525
"""Tests for using the bzrdir api with a non .bzr based disk format.
527
If/when one of these is in the core, we can let the implementation tests
531
def test_create_and_find_format(self):
532
# create a .notbzr dir
533
format = NotBzrDirFormat()
534
dir = format.initialize(self.get_url())
535
self.assertIsInstance(dir, NotBzrDir)
537
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
539
found = bzrlib.bzrdir.BzrDirFormat.find_format(
540
get_transport(self.get_url()))
541
self.assertIsInstance(found, NotBzrDirFormat)
543
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
545
def test_included_in_known_formats(self):
546
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
548
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
549
for format in formats:
550
if isinstance(format, NotBzrDirFormat):
552
self.fail("No NotBzrDirFormat in %s" % formats)
554
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
557
468
class NonLocalTests(TestCaseWithTransport):
558
469
"""Tests for bzrdir static behaviour on non local paths."""