~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Martin Pool
  • Date: 2006-06-20 07:55:43 UTC
  • mfrom: (1798 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1799.
  • Revision ID: mbp@sourcefrog.net-20060620075543-b10f6575d4a4fa32
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        bzrdir.BzrDirFormat.set_default_format(SampleBzrDirFormat())
46
46
        # creating a bzr dir should now create an instrumented dir.
47
47
        try:
48
 
            result = bzrdir.BzrDir.create('memory:/')
 
48
            result = bzrdir.BzrDir.create('memory:///')
49
49
            self.failUnless(isinstance(result, SampleBzrDir))
50
50
        finally:
51
51
            bzrdir.BzrDirFormat.set_default_format(old_format)
254
254
        finally:
255
255
            bzrdir.BzrDirFormat.set_default_format(old_format)
256
256
 
 
257
    def test_create_branch_convenience_root(self):
 
258
        """Creating a branch at the root of a fs should work."""
 
259
        self.transport_server = MemoryServer
 
260
        # outside a repo the default convenience output is a repo+branch_tree
 
261
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
262
        bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
 
263
        try:
 
264
            branch = bzrdir.BzrDir.create_branch_convenience(self.get_url())
 
265
            self.assertRaises(errors.NoWorkingTree,
 
266
                              branch.bzrdir.open_workingtree)
 
267
            branch.bzrdir.open_repository()
 
268
        finally:
 
269
            bzrdir.BzrDirFormat.set_default_format(old_format)
 
270
 
257
271
    def test_create_branch_convenience_under_shared_repo(self):
258
272
        # inside a repo the default convenience output is a branch+ follow the
259
273
        # repo tree policy
465
479
            bzrdir.BzrDirFormat.set_default_format(old_format)
466
480
 
467
481
 
 
482
class NotBzrDir(bzrlib.bzrdir.BzrDir):
 
483
    """A non .bzr based control directory."""
 
484
 
 
485
    def __init__(self, transport, format):
 
486
        self._format = format
 
487
        self.root_transport = transport
 
488
        self.transport = transport.clone('.not')
 
489
 
 
490
 
 
491
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
 
492
    """A test class representing any non-.bzr based disk format."""
 
493
 
 
494
    def initialize_on_transport(self, transport):
 
495
        """Initialize a new .not dir in the base directory of a Transport."""
 
496
        transport.mkdir('.not')
 
497
        return self.open(transport)
 
498
 
 
499
    def open(self, transport):
 
500
        """Open this directory."""
 
501
        return NotBzrDir(transport, self)
 
502
 
 
503
    @classmethod
 
504
    def _known_formats(self):
 
505
        return set([NotBzrDirFormat()])
 
506
 
 
507
    @classmethod
 
508
    def probe_transport(self, transport):
 
509
        """Our format is present if the transport ends in '.not/'."""
 
510
        if transport.has('.not'):
 
511
            return NotBzrDirFormat()
 
512
 
 
513
 
 
514
class TestNotBzrDir(TestCaseWithTransport):
 
515
    """Tests for using the bzrdir api with a non .bzr based disk format.
 
516
    
 
517
    If/when one of these is in the core, we can let the implementation tests
 
518
    verify this works.
 
519
    """
 
520
 
 
521
    def test_create_and_find_format(self):
 
522
        # create a .notbzr dir 
 
523
        format = NotBzrDirFormat()
 
524
        dir = format.initialize(self.get_url())
 
525
        self.assertIsInstance(dir, NotBzrDir)
 
526
        # now probe for it.
 
527
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
 
528
        try:
 
529
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
 
530
                get_transport(self.get_url()))
 
531
            self.assertIsInstance(found, NotBzrDirFormat)
 
532
        finally:
 
533
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
 
534
 
 
535
    def test_included_in_known_formats(self):
 
536
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
 
537
        try:
 
538
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
 
539
            for format in formats:
 
540
                if isinstance(format, NotBzrDirFormat):
 
541
                    return
 
542
            self.fail("No NotBzrDirFormat in %s" % formats)
 
543
        finally:
 
544
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
 
545
 
 
546
 
468
547
class NonLocalTests(TestCaseWithTransport):
469
548
    """Tests for bzrdir static behaviour on non local paths."""
470
549