~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
also see this file.
23
23
"""
24
24
 
 
25
from StringIO import StringIO
25
26
 
26
27
import bzrlib.branch as branch
27
 
from bzrlib.errors import NotBranchError
 
28
from bzrlib.errors import (NotBranchError,
 
29
                           UnknownFormatError,
 
30
                           UnsupportedFormatError,
 
31
                           )
 
32
 
28
33
from bzrlib.tests import TestCase, TestCaseInTempDir
29
34
from bzrlib.transport import get_transport
30
35
 
45
50
        self.assertEqual(old_initializer, branch.Branch.get_default_initializer())
46
51
 
47
52
 
 
53
class SampleBranchFormat(branch.BzrBranchFormat):
 
54
    """A sample format
 
55
 
 
56
    this format is initializable, unsupported to aid in testing the 
 
57
    open and open_downlevel routines.
 
58
    """
 
59
 
 
60
    def get_format_string(self):
 
61
        """See BzrBranchFormat.get_format_string()."""
 
62
        return "Sample branch format."
 
63
 
 
64
    def initialize(self, url):
 
65
        """Format 4 branches cannot be created."""
 
66
        t = get_transport(url)
 
67
        t.mkdir('.bzr')
 
68
        t.put('.bzr/branch-format', StringIO(self.get_format_string()))
 
69
        return 'A branch'
 
70
 
 
71
    def is_supported(self):
 
72
        return False
 
73
 
 
74
    def open(self, transport):
 
75
        return "opened branch."
 
76
 
 
77
 
48
78
class TestBzrBranchFormat(TestCaseInTempDir):
49
79
    """Tests for the BzrBranchFormat facility."""
50
80
 
65
95
        self.assertRaises(NotBranchError,
66
96
                          branch.BzrBranchFormat.find_format,
67
97
                          get_transport('.'))
 
98
 
 
99
    def test_find_format_unknown_format(self):
 
100
        t = get_transport('.')
 
101
        t.mkdir('.bzr')
 
102
        t.put('.bzr/branch-format', StringIO())
 
103
        self.assertRaises(UnknownFormatError,
 
104
                          branch.BzrBranchFormat.find_format,
 
105
                          get_transport('.'))
 
106
 
 
107
    def test_register_unregister_format(self):
 
108
        format = SampleBranchFormat()
 
109
        # make a branch
 
110
        format.initialize('.')
 
111
        # register a format for it.
 
112
        branch.BzrBranchFormat.register_format(format)
 
113
        # which branch.Open will refuse (not supported)
 
114
        self.assertRaises(UnsupportedFormatError, branch.Branch.open, '.')
 
115
        # but open_downlevel will work
 
116
        t = get_transport('.')
 
117
        self.assertEqual(format.open(t), branch.Branch.open_downlevel('.'))
 
118
        # unregister the format
 
119
        branch.BzrBranchFormat.unregister_format(format)
 
120
        # now open_downlevel should fail too.
 
121
        self.assertRaises(UnknownFormatError, branch.Branch.open_downlevel, '.')