~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Robert Collins
  • Date: 2006-08-08 23:19:29 UTC
  • mfrom: (1884 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: robertc@robertcollins.net-20060808231929-4e3e298190214b3a
current status

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
class SampleBzrDir(bzrdir.BzrDir):
63
63
    """A sample BzrDir implementation to allow testing static methods."""
64
64
 
65
 
    def create_repository(self):
 
65
    def create_repository(self, shared=False):
66
66
        """See BzrDir.create_repository."""
67
67
        return "A repository"
68
68
 
163
163
        finally:
164
164
            bzrdir.BzrDirFormat.set_default_format(old_format)
165
165
 
 
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())
 
170
 
 
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())
 
175
 
166
176
    def test_create_repository_under_shared(self):
167
177
        # an explicit create_repository always does so.
168
178
        # we trust the format is right from the 'create_repository test'
479
489
            bzrdir.BzrDirFormat.set_default_format(old_format)
480
490
 
481
491
 
 
492
class NotBzrDir(bzrlib.bzrdir.BzrDir):
 
493
    """A non .bzr based control directory."""
 
494
 
 
495
    def __init__(self, transport, format):
 
496
        self._format = format
 
497
        self.root_transport = transport
 
498
        self.transport = transport.clone('.not')
 
499
 
 
500
 
 
501
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
 
502
    """A test class representing any non-.bzr based disk format."""
 
503
 
 
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)
 
508
 
 
509
    def open(self, transport):
 
510
        """Open this directory."""
 
511
        return NotBzrDir(transport, self)
 
512
 
 
513
    @classmethod
 
514
    def _known_formats(self):
 
515
        return set([NotBzrDirFormat()])
 
516
 
 
517
    @classmethod
 
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()
 
522
 
 
523
 
 
524
class TestNotBzrDir(TestCaseWithTransport):
 
525
    """Tests for using the bzrdir api with a non .bzr based disk format.
 
526
    
 
527
    If/when one of these is in the core, we can let the implementation tests
 
528
    verify this works.
 
529
    """
 
530
 
 
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)
 
536
        # now probe for it.
 
537
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
 
538
        try:
 
539
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
 
540
                get_transport(self.get_url()))
 
541
            self.assertIsInstance(found, NotBzrDirFormat)
 
542
        finally:
 
543
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
 
544
 
 
545
    def test_included_in_known_formats(self):
 
546
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
 
547
        try:
 
548
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
 
549
            for format in formats:
 
550
                if isinstance(format, NotBzrDirFormat):
 
551
                    return
 
552
            self.fail("No NotBzrDirFormat in %s" % formats)
 
553
        finally:
 
554
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
 
555
 
 
556
 
482
557
class NonLocalTests(TestCaseWithTransport):
483
558
    """Tests for bzrdir static behaviour on non local paths."""
484
559