~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-06-13 16:26:09 UTC
  • mfrom: (1733.1.7 non-bzr-control-dirs)
  • mto: This revision was merged to the branch mainline in revision 1770.
  • Revision ID: robertc@robertcollins.net-20060613162609-779ae11bd22b2866
Merge the new ControlFormat core logic to support .hg, .svn etc formats. (Robert Collins, Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
479
479
            bzrdir.BzrDirFormat.set_default_format(old_format)
480
480
 
481
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
 
482
547
class NonLocalTests(TestCaseWithTransport):
483
548
    """Tests for bzrdir static behaviour on non local paths."""
484
549