272
272
def test_find_format(self):
273
273
# is the right format object found for a branch?
274
274
# create a branch with a few known format objects.
275
bzrdir.BzrDirFormat.register_format(BzrDirFormatTest1())
276
self.addCleanup(bzrdir.BzrDirFormat.unregister_format, BzrDirFormatTest1())
277
bzrdir.BzrDirFormat.register_format(BzrDirFormatTest2())
278
self.addCleanup(bzrdir.BzrDirFormat.unregister_format, BzrDirFormatTest2())
275
bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
277
self.addCleanup(bzrdir.BzrProber.formats.remove,
278
BzrDirFormatTest1.get_format_string())
279
bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
281
self.addCleanup(bzrdir.BzrProber.formats.remove,
282
BzrDirFormatTest2.get_format_string())
279
283
t = self.get_transport()
280
284
self.build_tree(["foo/", "bar/"], transport=t)
281
285
def check_format(format, url):
1007
1011
self.assertEqual(2, rpc_count)
1010
class TestFormat5(TestCaseWithTransport):
1011
"""Tests specific to the version 5 bzrdir format."""
1013
def test_same_lockfiles_between_tree_repo_branch(self):
1014
# this checks that only a single lockfiles instance is created
1015
# for format 5 objects
1016
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1017
def check_dir_components_use_same_lock(dir):
1018
ctrl_1 = dir.open_repository().control_files
1019
ctrl_2 = dir.open_branch().control_files
1020
ctrl_3 = dir.open_workingtree()._control_files
1021
self.assertTrue(ctrl_1 is ctrl_2)
1022
self.assertTrue(ctrl_2 is ctrl_3)
1023
check_dir_components_use_same_lock(dir)
1024
# and if we open it normally.
1025
dir = bzrdir.BzrDir.open(self.get_url())
1026
check_dir_components_use_same_lock(dir)
1028
def test_can_convert(self):
1029
# format 5 dirs are convertable
1030
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1031
self.assertTrue(dir.can_convert_format())
1033
def test_needs_conversion(self):
1034
# format 5 dirs need a conversion if they are not the default,
1036
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1037
# don't need to convert it to itself
1038
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
1039
# do need to convert it to the current default
1040
self.assertTrue(dir.needs_format_conversion(
1041
bzrdir.BzrDirFormat.get_default_format()))
1044
class TestFormat6(TestCaseWithTransport):
1045
"""Tests specific to the version 6 bzrdir format."""
1047
def test_same_lockfiles_between_tree_repo_branch(self):
1048
# this checks that only a single lockfiles instance is created
1049
# for format 6 objects
1050
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1051
def check_dir_components_use_same_lock(dir):
1052
ctrl_1 = dir.open_repository().control_files
1053
ctrl_2 = dir.open_branch().control_files
1054
ctrl_3 = dir.open_workingtree()._control_files
1055
self.assertTrue(ctrl_1 is ctrl_2)
1056
self.assertTrue(ctrl_2 is ctrl_3)
1057
check_dir_components_use_same_lock(dir)
1058
# and if we open it normally.
1059
dir = bzrdir.BzrDir.open(self.get_url())
1060
check_dir_components_use_same_lock(dir)
1062
def test_can_convert(self):
1063
# format 6 dirs are convertable
1064
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1065
self.assertTrue(dir.can_convert_format())
1067
def test_needs_conversion(self):
1068
# format 6 dirs need an conversion if they are not the default.
1069
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1070
self.assertTrue(dir.needs_format_conversion(
1071
bzrdir.BzrDirFormat.get_default_format()))
1074
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1075
"""A non .bzr based control directory."""
1077
def __init__(self, transport, format):
1078
self._format = format
1079
self.root_transport = transport
1080
self.transport = transport.clone('.not')
1083
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1084
"""A test class representing any non-.bzr based disk format."""
1086
def initialize_on_transport(self, transport):
1087
"""Initialize a new .not dir in the base directory of a Transport."""
1088
transport.mkdir('.not')
1089
return self.open(transport)
1091
def open(self, transport):
1092
"""Open this directory."""
1093
return NotBzrDir(transport, self)
1096
def _known_formats(self):
1097
return set([NotBzrDirFormat()])
1100
class NotBzrDirProber(controldir.Prober):
1102
def probe_transport(self, transport):
1103
"""Our format is present if the transport ends in '.not/'."""
1104
if transport.has('.not'):
1105
return NotBzrDirFormat()
1108
class TestNotBzrDir(TestCaseWithTransport):
1109
"""Tests for using the bzrdir api with a non .bzr based disk format.
1111
If/when one of these is in the core, we can let the implementation tests
1115
def test_create_and_find_format(self):
1116
# create a .notbzr dir
1117
format = NotBzrDirFormat()
1118
dir = format.initialize(self.get_url())
1119
self.assertIsInstance(dir, NotBzrDir)
1121
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1123
found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1124
self.assertIsInstance(found, NotBzrDirFormat)
1126
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1128
def test_included_in_known_formats(self):
1129
not_format = NotBzrDirFormat()
1130
bzrlib.controldir.ControlDirFormat.register_format(not_format)
1132
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1133
for format in formats:
1134
if isinstance(format, NotBzrDirFormat):
1136
self.fail("No NotBzrDirFormat in %s" % formats)
1138
bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1141
1014
class NonLocalTests(TestCaseWithTransport):
1142
1015
"""Tests for bzrdir static behaviour on non local paths."""