~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_bzrdir/test_bzrdir.py

(jelmer) Move get_{workingtree, branch,
 repository}_transport methods from ControlDir to BzrDir. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import bzrlib.branch
23
23
from bzrlib import (
24
24
    errors,
 
25
    repository,
25
26
    revision as _mod_revision,
26
27
    transport,
 
28
    workingtree,
27
29
    )
28
30
from bzrlib.tests import (
29
31
    TestSkipped,
34
36
    )
35
37
 
36
38
 
 
39
class AnonymousTestBranchFormat(bzrlib.branch.BranchFormat):
 
40
    """An anonymous branch format (does not have a format string)"""
 
41
 
 
42
    def get_format_string(self):
 
43
        raise NotImplementedError(self.get_format_string)
 
44
 
 
45
 
 
46
class IdentifiableTestBranchFormat(bzrlib.branch.BranchFormat):
 
47
    """An identifable branch format (has a format string)"""
 
48
 
 
49
    def get_format_string(self):
 
50
        return "I have an identity"
 
51
 
 
52
 
 
53
class AnonymousTestRepositoryFormat(repository.RepositoryFormat):
 
54
    """An anonymous branch format (does not have a format string)"""
 
55
 
 
56
    def get_format_string(self):
 
57
        raise NotImplementedError(self.get_format_string)
 
58
 
 
59
 
 
60
class IdentifiableTestRepositoryFormat(repository.RepositoryFormat):
 
61
    """An identifable branch format (has a format string)"""
 
62
 
 
63
    def get_format_string(self):
 
64
        return "I have an identity"
 
65
 
 
66
 
 
67
class AnonymousTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
 
68
    """An anonymous branch format (does not have a format string)"""
 
69
 
 
70
    def get_format_string(self):
 
71
        raise NotImplementedError(self.get_format_string)
 
72
 
 
73
 
 
74
class IdentifiableTestWorkingTreeFormat(workingtree.WorkingTreeFormat):
 
75
    """An identifable branch format (has a format string)"""
 
76
 
 
77
    def get_format_string(self):
 
78
        return "I have an identity"
 
79
 
 
80
 
37
81
class TestBzrDir(TestCaseWithBzrDir):
38
82
 
39
83
    # Many of these tests test for disk equality rather than checking
490
534
        self.failUnless(transport.has('.bzr'))
491
535
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
492
536
            bd.retire_bzrdir, limit=0)
 
537
 
 
538
    def test_get_branch_transport(self):
 
539
        dir = self.make_bzrdir('.')
 
540
        # without a format, get_branch_transport gives use a transport
 
541
        # which -may- point to an existing dir.
 
542
        self.assertTrue(isinstance(dir.get_branch_transport(None),
 
543
                                   transport.Transport))
 
544
        # with a given format, either the bzr dir supports identifiable
 
545
        # branches, or it supports anonymous branch formats, but not both.
 
546
        anonymous_format = AnonymousTestBranchFormat()
 
547
        identifiable_format = IdentifiableTestBranchFormat()
 
548
        try:
 
549
            found_transport = dir.get_branch_transport(anonymous_format)
 
550
            self.assertRaises(errors.IncompatibleFormat,
 
551
                              dir.get_branch_transport,
 
552
                              identifiable_format)
 
553
        except errors.IncompatibleFormat:
 
554
            found_transport = dir.get_branch_transport(identifiable_format)
 
555
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
556
        # and the dir which has been initialized for us must exist.
 
557
        found_transport.list_dir('.')
 
558
 
 
559
    def test_get_repository_transport(self):
 
560
        dir = self.make_bzrdir('.')
 
561
        # without a format, get_repository_transport gives use a transport
 
562
        # which -may- point to an existing dir.
 
563
        self.assertTrue(isinstance(dir.get_repository_transport(None),
 
564
                                   transport.Transport))
 
565
        # with a given format, either the bzr dir supports identifiable
 
566
        # repositories, or it supports anonymous repository formats, but not both.
 
567
        anonymous_format = AnonymousTestRepositoryFormat()
 
568
        identifiable_format = IdentifiableTestRepositoryFormat()
 
569
        try:
 
570
            found_transport = dir.get_repository_transport(anonymous_format)
 
571
            self.assertRaises(errors.IncompatibleFormat,
 
572
                              dir.get_repository_transport,
 
573
                              identifiable_format)
 
574
        except errors.IncompatibleFormat:
 
575
            found_transport = dir.get_repository_transport(identifiable_format)
 
576
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
577
        # and the dir which has been initialized for us must exist.
 
578
        found_transport.list_dir('.')
 
579
 
 
580
    def test_get_workingtree_transport(self):
 
581
        dir = self.make_bzrdir('.')
 
582
        # without a format, get_workingtree_transport gives use a transport
 
583
        # which -may- point to an existing dir.
 
584
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
 
585
                                   transport.Transport))
 
586
        # with a given format, either the bzr dir supports identifiable
 
587
        # trees, or it supports anonymous tree formats, but not both.
 
588
        anonymous_format = AnonymousTestWorkingTreeFormat()
 
589
        identifiable_format = IdentifiableTestWorkingTreeFormat()
 
590
        try:
 
591
            found_transport = dir.get_workingtree_transport(anonymous_format)
 
592
            self.assertRaises(errors.IncompatibleFormat,
 
593
                              dir.get_workingtree_transport,
 
594
                              identifiable_format)
 
595
        except errors.IncompatibleFormat:
 
596
            found_transport = dir.get_workingtree_transport(identifiable_format)
 
597
        self.assertTrue(isinstance(found_transport, transport.Transport))
 
598
        # and the dir which has been initialized for us must exist.
 
599
        found_transport.list_dir('.')