53
62
from bzrlib.tests.test_http import TestWithTransport_pycurl
54
63
from bzrlib.transport import (
58
67
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
68
from bzrlib.transport.nosmart import NoSmartTransportDecorator
60
69
from bzrlib.transport.readonly import ReadonlyTransportDecorator
61
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
70
from bzrlib.repofmt import knitrepo, knitpack_repo
64
73
class TestDefaultFormat(TestCase):
66
75
def test_get_set_default_format(self):
67
76
old_format = bzrdir.BzrDirFormat.get_default_format()
68
# default is BzrDirFormat6
69
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
70
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
77
# default is BzrDirMetaFormat1
78
self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
79
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
71
80
# creating a bzr dir should now create an instrumented dir.
73
82
result = bzrdir.BzrDir.create('memory:///')
74
self.failUnless(isinstance(result, SampleBzrDir))
83
self.assertIsInstance(result, SampleBzrDir)
76
bzrdir.BzrDirFormat._set_default_format(old_format)
85
controldir.ControlDirFormat._set_default_format(old_format)
77
86
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
89
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
90
"""A deprecated bzr dir format."""
80
93
class TestFormatRegistry(TestCase):
82
95
def make_format_registry(self):
83
my_format_registry = bzrdir.BzrDirFormatRegistry()
84
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
'Pre-0.8 format. Slower and does not support checkouts or shared'
86
' repositories', deprecated=True)
87
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
my_format_registry.register_metadir('knit',
96
my_format_registry = controldir.ControlDirFormatRegistry()
97
my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
98
'Some format. Slower and unawesome and deprecated.',
100
my_format_registry.register_lazy('lazy', 'bzrlib.tests.test_bzrdir',
101
'DeprecatedBzrDirFormat', 'Format registered lazily',
103
bzrdir.register_metadir(my_format_registry, 'knit',
90
104
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
91
105
'Format using knits',
93
107
my_format_registry.set_default('knit')
94
my_format_registry.register_metadir(
108
bzrdir.register_metadir(my_format_registry,
96
110
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
97
111
'Experimental successor to knit. Use at your own risk.',
98
112
branch_format='bzrlib.branch.BzrBranchFormat6',
99
113
experimental=True)
100
my_format_registry.register_metadir(
114
bzrdir.register_metadir(my_format_registry,
102
116
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
103
117
'Experimental successor to knit. Use at your own risk.',
104
118
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
105
my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
106
'Pre-0.8 format. Slower and does not support checkouts or shared'
107
' repositories', hidden=True)
108
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
109
'BzrDirFormat6', 'Format registered lazily', deprecated=True,
119
my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
120
'Old format. Slower and does not support things. ', hidden=True)
121
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.tests.test_bzrdir',
122
'DeprecatedBzrDirFormat', 'Format registered lazily',
123
deprecated=True, hidden=True)
111
124
return my_format_registry
113
126
def test_format_registry(self):
114
127
my_format_registry = self.make_format_registry()
115
128
my_bzrdir = my_format_registry.make_bzrdir('lazy')
116
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
117
my_bzrdir = my_format_registry.make_bzrdir('weave')
118
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
129
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
130
my_bzrdir = my_format_registry.make_bzrdir('deprecated')
131
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
119
132
my_bzrdir = my_format_registry.make_bzrdir('default')
120
133
self.assertIsInstance(my_bzrdir.repository_format,
121
134
knitrepo.RepositoryFormatKnit1)
166
178
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
167
179
bzrdir.format_registry.get('default'))
169
repository.RepositoryFormat.get_default_format().__class__,
181
repository.format_registry.get_default().__class__,
170
182
knitrepo.RepositoryFormatKnit3)
172
184
bzrdir.format_registry.set_default_repository(old_default)
174
186
def test_aliases(self):
175
a_registry = bzrdir.BzrDirFormatRegistry()
176
a_registry.register('weave', bzrdir.BzrDirFormat6,
177
'Pre-0.8 format. Slower and does not support checkouts or shared'
178
' repositories', deprecated=True)
179
a_registry.register('weavealias', bzrdir.BzrDirFormat6,
180
'Pre-0.8 format. Slower and does not support checkouts or shared'
181
' repositories', deprecated=True, alias=True)
182
self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
187
a_registry = controldir.ControlDirFormatRegistry()
188
a_registry.register('deprecated', DeprecatedBzrDirFormat,
189
'Old format. Slower and does not support stuff',
191
a_registry.register('deprecatedalias', DeprecatedBzrDirFormat,
192
'Old format. Slower and does not support stuff',
193
deprecated=True, alias=True)
194
self.assertEqual(frozenset(['deprecatedalias']), a_registry.aliases())
185
197
class SampleBranch(bzrlib.branch.Branch):
248
278
def test_find_format(self):
249
279
# is the right format object found for a branch?
250
280
# create a branch with a few known format objects.
251
# this is not quite the same as
252
t = get_transport(self.get_url())
281
bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
283
self.addCleanup(bzrdir.BzrProber.formats.remove,
284
BzrDirFormatTest1.get_format_string())
285
bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
287
self.addCleanup(bzrdir.BzrProber.formats.remove,
288
BzrDirFormatTest2.get_format_string())
289
t = self.get_transport()
253
290
self.build_tree(["foo/", "bar/"], transport=t)
254
291
def check_format(format, url):
255
292
format.initialize(url)
256
t = get_transport(url)
293
t = _mod_transport.get_transport_from_path(url)
257
294
found_format = bzrdir.BzrDirFormat.find_format(t)
258
self.failUnless(isinstance(found_format, format.__class__))
259
check_format(bzrdir.BzrDirFormat5(), "foo")
260
check_format(bzrdir.BzrDirFormat6(), "bar")
295
self.assertIsInstance(found_format, format.__class__)
296
check_format(BzrDirFormatTest1(), "foo")
297
check_format(BzrDirFormatTest2(), "bar")
262
299
def test_find_format_nothing_there(self):
263
300
self.assertRaises(NotBranchError,
264
301
bzrdir.BzrDirFormat.find_format,
302
_mod_transport.get_transport_from_path('.'))
267
304
def test_find_format_unknown_format(self):
268
t = get_transport(self.get_url())
305
t = self.get_transport()
270
307
t.put_bytes('.bzr/branch-format', '')
271
308
self.assertRaises(UnknownFormatError,
272
309
bzrdir.BzrDirFormat.find_format,
310
_mod_transport.get_transport_from_path('.'))
275
312
def test_register_unregister_format(self):
276
313
format = SampleBzrDirFormat()
480
517
# Clone source into directory
481
518
target = source_bzrdir.clone(self.get_url('parent/target'))
520
def test_format_initialize_on_transport_ex_stacked_on(self):
521
# trunk is a stackable format. Note that its in the same server area
522
# which is what launchpad does, but not sufficient to exercise the
524
trunk = self.make_branch('trunk', format='1.9')
525
t = self.get_transport('stacked')
526
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
527
repo_name = old_fmt.repository_format.network_name()
528
# Should end up with a 1.9 format (stackable)
529
repo, control, require_stacking, repo_policy = \
530
old_fmt.initialize_on_transport_ex(t,
531
repo_format_name=repo_name, stacked_on='../trunk',
534
# Repositories are open write-locked
535
self.assertTrue(repo.is_write_locked())
536
self.addCleanup(repo.unlock)
538
repo = control.open_repository()
539
self.assertIsInstance(control, bzrdir.BzrDir)
540
opened = bzrdir.BzrDir.open(t.base)
541
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
542
self.assertEqual(control._format.network_name(),
543
old_fmt.network_name())
544
self.assertEqual(control._format.network_name(),
545
opened._format.network_name())
546
self.assertEqual(control.__class__, opened.__class__)
547
self.assertLength(1, repo._fallback_repositories)
483
549
def test_sprout_obeys_stacking_policy(self):
484
550
child_branch, new_child_transport = self.prepare_default_stacking()
485
551
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
676
742
self.assertEqual(relpath, 'baz')
678
744
def test_open_containing_from_transport(self):
679
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
680
get_transport(self.get_readonly_url('')))
681
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
682
get_transport(self.get_readonly_url('g/p/q')))
745
self.assertRaises(NotBranchError,
746
bzrdir.BzrDir.open_containing_from_transport,
747
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
748
self.assertRaises(NotBranchError,
749
bzrdir.BzrDir.open_containing_from_transport,
750
_mod_transport.get_transport_from_url(
751
self.get_readonly_url('g/p/q')))
683
752
control = bzrdir.BzrDir.create(self.get_url())
684
753
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
685
get_transport(self.get_readonly_url('')))
754
_mod_transport.get_transport_from_url(
755
self.get_readonly_url('')))
686
756
self.assertEqual('', relpath)
687
757
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
688
get_transport(self.get_readonly_url('g/p/q')))
758
_mod_transport.get_transport_from_url(
759
self.get_readonly_url('g/p/q')))
689
760
self.assertEqual('g/p/q', relpath)
691
762
def test_open_containing_tree_or_branch(self):
787
856
self.build_tree(['tree1/subtree/file'])
788
857
sub_tree.add('file')
789
858
tree.commit('Initial commit')
859
# The following line force the orhaning to reveal bug #634470
860
tree.branch.get_config().set_user_option(
861
'bzr.transform.orphan_policy', 'move')
790
862
tree.bzrdir.destroy_workingtree()
863
# FIXME: subtree/.bzr is left here which allows the test to pass (or
864
# fail :-( ) -- vila 20100909
791
865
repo = self.make_repository('repo', shared=True,
792
866
format='dirstate-with-subtree')
793
867
repo.set_make_working_trees(False)
794
tree.bzrdir.sprout('repo/tree2')
795
self.failUnlessExists('repo/tree2/subtree')
796
self.failIfExists('repo/tree2/subtree/file')
868
# FIXME: we just deleted the workingtree and now we want to use it ????
869
# At a minimum, we should use tree.branch below (but this fails too
870
# currently) or stop calling this test 'treeless'. Specifically, I've
871
# turn the line below into an assertRaises when 'subtree/.bzr' is
872
# orphaned and sprout tries to access the branch there (which is left
873
# by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
874
# [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
875
# #634470. -- vila 20100909
876
self.assertRaises(errors.NotBranchError,
877
tree.bzrdir.sprout, 'repo/tree2')
878
# self.assertPathExists('repo/tree2/subtree')
879
# self.assertPathDoesNotExist('repo/tree2/subtree/file')
798
881
def make_foo_bar_baz(self):
799
882
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
804
887
def test_find_bzrdirs(self):
805
888
foo, bar, baz = self.make_foo_bar_baz()
806
transport = get_transport(self.get_url())
807
self.assertEqualBzrdirs([baz, foo, bar],
808
bzrdir.BzrDir.find_bzrdirs(transport))
889
t = self.get_transport()
890
self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
892
def make_fake_permission_denied_transport(self, transport, paths):
893
"""Create a transport that raises PermissionDenied for some paths."""
896
raise errors.PermissionDenied(path)
898
path_filter_server = pathfilter.PathFilteringServer(transport, filter)
899
path_filter_server.start_server()
900
self.addCleanup(path_filter_server.stop_server)
901
path_filter_transport = pathfilter.PathFilteringTransport(
902
path_filter_server, '.')
903
return (path_filter_server, path_filter_transport)
905
def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
906
"""Check that each branch url ends with the given suffix."""
907
for actual_bzrdir in actual_bzrdirs:
908
self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
910
def test_find_bzrdirs_permission_denied(self):
911
foo, bar, baz = self.make_foo_bar_baz()
912
t = self.get_transport()
913
path_filter_server, path_filter_transport = \
914
self.make_fake_permission_denied_transport(t, ['foo'])
916
self.assertBranchUrlsEndWith('/baz/',
917
bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
919
smart_transport = self.make_smart_server('.',
920
backing_server=path_filter_server)
921
self.assertBranchUrlsEndWith('/baz/',
922
bzrdir.BzrDir.find_bzrdirs(smart_transport))
810
924
def test_find_bzrdirs_list_current(self):
811
925
def list_current(transport):
812
926
return [s for s in transport.list_dir('') if s != 'baz']
814
928
foo, bar, baz = self.make_foo_bar_baz()
815
transport = get_transport(self.get_url())
816
self.assertEqualBzrdirs([foo, bar],
817
bzrdir.BzrDir.find_bzrdirs(transport,
818
list_current=list_current))
929
t = self.get_transport()
930
self.assertEqualBzrdirs(
932
bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
821
934
def test_find_bzrdirs_evaluate(self):
822
935
def evaluate(bzrdir):
824
937
repo = bzrdir.open_repository()
825
except NoRepositoryPresent:
938
except errors.NoRepositoryPresent:
826
939
return True, bzrdir.root_transport.base
828
941
return False, bzrdir.root_transport.base
830
943
foo, bar, baz = self.make_foo_bar_baz()
831
transport = get_transport(self.get_url())
944
t = self.get_transport()
832
945
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
833
list(bzrdir.BzrDir.find_bzrdirs(transport,
946
list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
836
948
def assertEqualBzrdirs(self, first, second):
837
949
first = list(first)
844
956
root = self.make_repository('', shared=True)
845
957
foo, bar, baz = self.make_foo_bar_baz()
846
958
qux = self.make_bzrdir('foo/qux')
847
transport = get_transport(self.get_url())
848
branches = bzrdir.BzrDir.find_branches(transport)
959
t = self.get_transport()
960
branches = bzrdir.BzrDir.find_branches(t)
849
961
self.assertEqual(baz.root_transport.base, branches[0].base)
850
962
self.assertEqual(foo.root_transport.base, branches[1].base)
851
963
self.assertEqual(bar.root_transport.base, branches[2].base)
853
965
# ensure this works without a top-level repo
854
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
966
branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
855
967
self.assertEqual(foo.root_transport.base, branches[0].base)
856
968
self.assertEqual(bar.root_transport.base, branches[1].base)
971
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
973
def test_find_bzrdirs_missing_repo(self):
974
t = self.get_transport()
975
arepo = self.make_repository('arepo', shared=True)
976
abranch_url = arepo.user_url + '/abranch'
977
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
978
t.delete_tree('arepo/.bzr')
979
self.assertRaises(errors.NoRepositoryPresent,
980
branch.Branch.open, abranch_url)
981
self.make_branch('baz')
982
for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
983
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
859
986
class TestMeta1DirFormat(TestCaseWithTransport):
860
987
"""Tests specific to the meta1 dir format."""
921
1061
self.assertEqual(2, rpc_count)
924
class TestFormat5(TestCaseWithTransport):
925
"""Tests specific to the version 5 bzrdir format."""
927
def test_same_lockfiles_between_tree_repo_branch(self):
928
# this checks that only a single lockfiles instance is created
929
# for format 5 objects
930
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
931
def check_dir_components_use_same_lock(dir):
932
ctrl_1 = dir.open_repository().control_files
933
ctrl_2 = dir.open_branch().control_files
934
ctrl_3 = dir.open_workingtree()._control_files
935
self.assertTrue(ctrl_1 is ctrl_2)
936
self.assertTrue(ctrl_2 is ctrl_3)
937
check_dir_components_use_same_lock(dir)
938
# and if we open it normally.
939
dir = bzrdir.BzrDir.open(self.get_url())
940
check_dir_components_use_same_lock(dir)
942
def test_can_convert(self):
943
# format 5 dirs are convertable
944
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
945
self.assertTrue(dir.can_convert_format())
947
def test_needs_conversion(self):
948
# format 5 dirs need a conversion if they are not the default,
950
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
951
# don't need to convert it to itself
952
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
953
# do need to convert it to the current default
954
self.assertTrue(dir.needs_format_conversion(
955
bzrdir.BzrDirFormat.get_default_format()))
958
class TestFormat6(TestCaseWithTransport):
959
"""Tests specific to the version 6 bzrdir format."""
961
def test_same_lockfiles_between_tree_repo_branch(self):
962
# this checks that only a single lockfiles instance is created
963
# for format 6 objects
964
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
965
def check_dir_components_use_same_lock(dir):
966
ctrl_1 = dir.open_repository().control_files
967
ctrl_2 = dir.open_branch().control_files
968
ctrl_3 = dir.open_workingtree()._control_files
969
self.assertTrue(ctrl_1 is ctrl_2)
970
self.assertTrue(ctrl_2 is ctrl_3)
971
check_dir_components_use_same_lock(dir)
972
# and if we open it normally.
973
dir = bzrdir.BzrDir.open(self.get_url())
974
check_dir_components_use_same_lock(dir)
976
def test_can_convert(self):
977
# format 6 dirs are convertable
978
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
979
self.assertTrue(dir.can_convert_format())
981
def test_needs_conversion(self):
982
# format 6 dirs need an conversion if they are not the default.
983
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
984
self.assertTrue(dir.needs_format_conversion(
985
bzrdir.BzrDirFormat.get_default_format()))
988
class NotBzrDir(bzrlib.bzrdir.BzrDir):
989
"""A non .bzr based control directory."""
991
def __init__(self, transport, format):
992
self._format = format
993
self.root_transport = transport
994
self.transport = transport.clone('.not')
997
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
998
"""A test class representing any non-.bzr based disk format."""
1000
def initialize_on_transport(self, transport):
1001
"""Initialize a new .not dir in the base directory of a Transport."""
1002
transport.mkdir('.not')
1003
return self.open(transport)
1005
def open(self, transport):
1006
"""Open this directory."""
1007
return NotBzrDir(transport, self)
1010
def _known_formats(self):
1011
return set([NotBzrDirFormat()])
1014
def probe_transport(self, transport):
1015
"""Our format is present if the transport ends in '.not/'."""
1016
if transport.has('.not'):
1017
return NotBzrDirFormat()
1020
class TestNotBzrDir(TestCaseWithTransport):
1021
"""Tests for using the bzrdir api with a non .bzr based disk format.
1023
If/when one of these is in the core, we can let the implementation tests
1027
def test_create_and_find_format(self):
1028
# create a .notbzr dir
1029
format = NotBzrDirFormat()
1030
dir = format.initialize(self.get_url())
1031
self.assertIsInstance(dir, NotBzrDir)
1033
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
1035
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1036
get_transport(self.get_url()))
1037
self.assertIsInstance(found, NotBzrDirFormat)
1039
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
1041
def test_included_in_known_formats(self):
1042
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
1044
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1045
for format in formats:
1046
if isinstance(format, NotBzrDirFormat):
1048
self.fail("No NotBzrDirFormat in %s" % formats)
1050
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
1053
1064
class NonLocalTests(TestCaseWithTransport):
1054
1065
"""Tests for bzrdir static behaviour on non local paths."""
1351
1381
self.assertIsInstance(params, RepoInitHookParams)
1352
1382
self.assertTrue(hasattr(params, 'bzrdir'))
1353
1383
self.assertTrue(hasattr(params, 'repository'))
1385
def test_post_repo_init_hook_repr(self):
1387
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1388
lambda params: param_reprs.append(repr(params)), None)
1389
self.make_repository('foo')
1390
self.assertLength(1, param_reprs)
1391
param_repr = param_reprs[0]
1392
self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1395
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1396
# FIXME: This may need to be unified with test_osutils.TestBackupNames or
1397
# moved to per_bzrdir or per_transport for better coverage ?
1401
super(TestGenerateBackupName, self).setUp()
1402
self._transport = self.get_transport()
1403
bzrdir.BzrDir.create(self.get_url(),
1404
possible_transports=[self._transport])
1405
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1407
def test_deprecated_generate_backup_name(self):
1408
res = self.applyDeprecated(
1409
symbol_versioning.deprecated_in((2, 3, 0)),
1410
self._bzrdir.generate_backup_name, 'whatever')
1413
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1415
def test_exiting(self):
1416
self._transport.put_bytes("a.~1~", "some content")
1417
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1420
class TestMeta1DirColoFormat(TestCaseWithTransport):
1421
"""Tests specific to the meta1 dir with colocated branches format."""
1423
def test_supports_colo(self):
1424
format = bzrdir.BzrDirMetaFormat1Colo()
1425
self.assertTrue(format.colocated_branches)
1427
def test_upgrade_from_2a(self):
1428
tree = self.make_branch_and_tree('.', format='2a')
1429
format = bzrdir.BzrDirMetaFormat1Colo()
1430
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1431
converter = tree.bzrdir._format.get_converter(format)
1432
result = converter.convert(tree.bzrdir, None)
1433
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1434
self.assertFalse(result.needs_format_conversion(format))
1436
def test_downgrade_to_2a(self):
1437
tree = self.make_branch_and_tree('.', format='development-colo')
1438
format = bzrdir.BzrDirMetaFormat1()
1439
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1440
converter = tree.bzrdir._format.get_converter(format)
1441
result = converter.convert(tree.bzrdir, None)
1442
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1443
self.assertFalse(result.needs_format_conversion(format))
1445
def test_downgrade_to_2a_too_many_branches(self):
1446
tree = self.make_branch_and_tree('.', format='development-colo')
1447
tree.bzrdir.create_branch(name="another-colocated-branch")
1448
converter = tree.bzrdir._format.get_converter(
1449
bzrdir.BzrDirMetaFormat1())
1450
result = converter.convert(tree.bzrdir, bzrdir.BzrDirMetaFormat1())
1451
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1453
def test_nested(self):
1454
tree = self.make_branch_and_tree('.', format='development-colo')
1455
tree.bzrdir.create_branch(name='foo')
1456
tree.bzrdir.create_branch(name='fool/bla')
1458
errors.ParentBranchExists, tree.bzrdir.create_branch,
1461
def test_parent(self):
1462
tree = self.make_branch_and_tree('.', format='development-colo')
1463
tree.bzrdir.create_branch(name='fool/bla')
1464
tree.bzrdir.create_branch(name='foo/bar')
1466
errors.AlreadyBranchError, tree.bzrdir.create_branch,
1470
class SampleBzrFormat(bzrdir.BzrFormat):
1473
def get_format_string(cls):
1474
return "First line\n"
1477
class TestBzrFormat(TestCase):
1478
"""Tests for BzrFormat."""
1480
def test_as_string(self):
1481
format = SampleBzrFormat()
1482
format.features = {"foo": "required"}
1483
self.assertEquals(format.as_string(),
1486
format.features["another"] = "optional"
1487
self.assertEquals(format.as_string(),
1490
"optional another\n")
1492
def test_network_name(self):
1493
# The network string should include the feature info
1494
format = SampleBzrFormat()
1495
format.features = {"foo": "required"}
1497
"First line\nrequired foo\n",
1498
format.network_name())
1500
def test_from_string_no_features(self):
1502
format = SampleBzrFormat.from_string(
1504
self.assertEquals({}, format.features)
1506
def test_from_string_with_feature(self):
1508
format = SampleBzrFormat.from_string(
1509
"First line\nrequired foo\n")
1510
self.assertEquals("required", format.features.get("foo"))
1512
def test_from_string_format_string_mismatch(self):
1513
# The first line has to match the format string
1514
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1515
"Second line\nrequired foo\n")
1517
def test_from_string_missing_space(self):
1518
# At least one space is required in the feature lines
1519
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1520
"First line\nfoo\n")
1522
def test_from_string_with_spaces(self):
1523
# Feature with spaces (in case we add stuff like this in the future)
1524
format = SampleBzrFormat.from_string(
1525
"First line\nrequired foo with spaces\n")
1526
self.assertEquals("required", format.features.get("foo with spaces"))
1529
format1 = SampleBzrFormat()
1530
format1.features = {"nested-trees": "optional"}
1531
format2 = SampleBzrFormat()
1532
format2.features = {"nested-trees": "optional"}
1533
self.assertEquals(format1, format1)
1534
self.assertEquals(format1, format2)
1535
format3 = SampleBzrFormat()
1536
self.assertNotEquals(format1, format3)
1538
def test_check_support_status_optional(self):
1539
# Optional, so silently ignore
1540
format = SampleBzrFormat()
1541
format.features = {"nested-trees": "optional"}
1542
format.check_support_status(True)
1543
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1544
SampleBzrFormat.register_feature("nested-trees")
1545
format.check_support_status(True)
1547
def test_check_support_status_required(self):
1548
# Optional, so trigger an exception
1549
format = SampleBzrFormat()
1550
format.features = {"nested-trees": "required"}
1551
self.assertRaises(errors.MissingFeature, format.check_support_status,
1553
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1554
SampleBzrFormat.register_feature("nested-trees")
1555
format.check_support_status(True)
1557
def test_check_support_status_unknown(self):
1558
# treat unknown necessity as required
1559
format = SampleBzrFormat()
1560
format.features = {"nested-trees": "unknown"}
1561
self.assertRaises(errors.MissingFeature, format.check_support_status,
1563
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1564
SampleBzrFormat.register_feature("nested-trees")
1565
format.check_support_status(True)
1567
def test_feature_already_registered(self):
1568
# a feature can only be registered once
1569
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1570
SampleBzrFormat.register_feature("nested-trees")
1571
self.assertRaises(errors.FeatureAlreadyRegistered,
1572
SampleBzrFormat.register_feature, "nested-trees")
1574
def test_feature_with_space(self):
1575
# spaces are not allowed in feature names
1576
self.assertRaises(ValueError, SampleBzrFormat.register_feature,