33
34
from bzrlib.tests import TestCase, TestCaseInTempDir
34
35
from bzrlib.transport import get_transport
36
class TestDefaultFormat(TestCase):
38
def test_get_set_default_initializer(self):
39
old_initializer = branch.Branch.get_default_initializer()
40
# default is BzrBranch._initialize
41
self.assertEqual(branch.BzrBranch._initialize, old_initializer)
43
return "a branch %s" % url
44
branch.Branch.set_default_initializer(recorder)
46
b = branch.Branch.create("memory:/")
47
self.assertEqual("a branch memory:/", b)
49
branch.Branch.set_default_initializer(old_initializer)
50
self.assertEqual(old_initializer, branch.Branch.get_default_initializer())
53
class SampleBranchFormat(branch.BzrBranchFormat):
56
this format is initializable, unsupported to aid in testing the
57
open and open_downlevel routines.
60
def get_format_string(self):
61
"""See BzrBranchFormat.get_format_string()."""
62
return "Sample branch format."
64
def initialize(self, url):
65
"""Format 4 branches cannot be created."""
66
t = get_transport(url)
68
t.put('.bzr/branch-format', StringIO(self.get_format_string()))
71
def is_supported(self):
74
def open(self, transport):
75
return "opened branch."
78
class TestBzrBranchFormat(TestCaseInTempDir):
79
"""Tests for the BzrBranchFormat facility."""
81
def test_find_format(self):
82
# is the right format object found for a branch?
83
# create a branch with a few known format objects.
84
# this is not quite the same as
85
self.build_tree(["foo/", "bar/"])
86
def check_format(format, url):
87
format.initialize(url)
88
t = get_transport(url)
89
found_format = branch.BzrBranchFormat.find_format(t)
90
self.failUnless(isinstance(found_format, format.__class__))
91
check_format(branch.BzrBranchFormat5(), "foo")
92
check_format(branch.BzrBranchFormat6(), "bar")
94
def test_find_format_not_branch(self):
95
self.assertRaises(NotBranchError,
96
branch.BzrBranchFormat.find_format,
99
def test_find_format_unknown_format(self):
100
t = get_transport('.')
102
t.put('.bzr/branch-format', StringIO())
103
self.assertRaises(UnknownFormatError,
104
branch.BzrBranchFormat.find_format,
107
def test_register_unregister_format(self):
108
format = SampleBranchFormat()
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, '.')
37
#class TestDefaultFormat(TestCase):
39
# def test_get_set_default_format(self):
40
# old_format = branch.BranchFormat.get_default_format()
41
# # default is None - we cannot create a Branch independently yet
42
# self.assertEqual(old_format, None)
43
# branch.BranchFormat.set_default_format(SampleBranchFormat())
45
# """default branch formats make no sense until we have
46
# multiple formats per bzrdir format."""
48
# #result = branch.Branch.create('memory:/')
49
# #self.assertEqual(result, 'A bzr branch dir')
51
# branch.BranchFormat.set_default_format(old_format)
52
# self.assertEqual(old_format, branch.BranchFormat.get_default_format())