55
62
from bzrlib.tests.test_http import TestWithTransport_pycurl
56
63
from bzrlib.transport import (
61
67
from bzrlib.transport.http._urllib import HttpTransport_urllib
62
68
from bzrlib.transport.nosmart import NoSmartTransportDecorator
63
69
from bzrlib.transport.readonly import ReadonlyTransportDecorator
64
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
70
from bzrlib.repofmt import knitrepo, knitpack_repo
67
73
class TestDefaultFormat(TestCase):
69
75
def test_get_set_default_format(self):
70
76
old_format = bzrdir.BzrDirFormat.get_default_format()
71
# default is BzrDirFormat6
72
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
77
# default is BzrDirMetaFormat1
78
self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
73
79
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
74
80
# creating a bzr dir should now create an instrumented dir.
76
82
result = bzrdir.BzrDir.create('memory:///')
77
self.failUnless(isinstance(result, SampleBzrDir))
83
self.assertIsInstance(result, SampleBzrDir)
79
85
controldir.ControlDirFormat._set_default_format(old_format)
80
86
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
89
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
90
"""A deprecated bzr dir format."""
83
93
class TestFormatRegistry(TestCase):
85
95
def make_format_registry(self):
86
96
my_format_registry = controldir.ControlDirFormatRegistry()
87
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
88
'Pre-0.8 format. Slower and does not support checkouts or shared'
89
' repositories', deprecated=True)
90
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
91
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
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',
92
103
bzrdir.register_metadir(my_format_registry, 'knit',
93
104
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
94
105
'Format using knits',
105
116
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
106
117
'Experimental successor to knit. Use at your own risk.',
107
118
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
108
my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
109
'Pre-0.8 format. Slower and does not support checkouts or shared'
110
' repositories', hidden=True)
111
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
112
'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)
114
124
return my_format_registry
116
126
def test_format_registry(self):
117
127
my_format_registry = self.make_format_registry()
118
128
my_bzrdir = my_format_registry.make_bzrdir('lazy')
119
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
120
my_bzrdir = my_format_registry.make_bzrdir('weave')
121
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)
122
132
my_bzrdir = my_format_registry.make_bzrdir('default')
123
133
self.assertIsInstance(my_bzrdir.repository_format,
124
134
knitrepo.RepositoryFormatKnit1)
169
178
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
170
179
bzrdir.format_registry.get('default'))
172
repository.RepositoryFormat.get_default_format().__class__,
181
repository.format_registry.get_default().__class__,
173
182
knitrepo.RepositoryFormatKnit3)
175
184
bzrdir.format_registry.set_default_repository(old_default)
177
186
def test_aliases(self):
178
187
a_registry = controldir.ControlDirFormatRegistry()
179
a_registry.register('weave', bzrdir.BzrDirFormat6,
180
'Pre-0.8 format. Slower and does not support checkouts or shared'
181
' repositories', deprecated=True)
182
a_registry.register('weavealias', bzrdir.BzrDirFormat6,
183
'Pre-0.8 format. Slower and does not support checkouts or shared'
184
' repositories', deprecated=True, alias=True)
185
self.assertEqual(frozenset(['weavealias']), a_registry.aliases())
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())
188
197
class SampleBranch(bzrlib.branch.Branch):
251
278
def test_find_format(self):
252
279
# is the right format object found for a branch?
253
280
# create a branch with a few known format objects.
254
# this is not quite the same as
255
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()
256
290
self.build_tree(["foo/", "bar/"], transport=t)
257
291
def check_format(format, url):
258
292
format.initialize(url)
259
t = get_transport(url)
293
t = _mod_transport.get_transport_from_path(url)
260
294
found_format = bzrdir.BzrDirFormat.find_format(t)
261
self.failUnless(isinstance(found_format, format.__class__))
262
check_format(bzrdir.BzrDirFormat5(), "foo")
263
check_format(bzrdir.BzrDirFormat6(), "bar")
295
self.assertIsInstance(found_format, format.__class__)
296
check_format(BzrDirFormatTest1(), "foo")
297
check_format(BzrDirFormatTest2(), "bar")
265
299
def test_find_format_nothing_there(self):
266
300
self.assertRaises(NotBranchError,
267
301
bzrdir.BzrDirFormat.find_format,
302
_mod_transport.get_transport_from_path('.'))
270
304
def test_find_format_unknown_format(self):
271
t = get_transport(self.get_url())
305
t = self.get_transport()
273
307
t.put_bytes('.bzr/branch-format', '')
274
308
self.assertRaises(UnknownFormatError,
275
309
bzrdir.BzrDirFormat.find_format,
310
_mod_transport.get_transport_from_path('.'))
278
312
def test_register_unregister_format(self):
279
313
format = SampleBzrDirFormat()
282
316
format.initialize(url)
283
317
# register a format for it.
284
bzrdir.BzrDirFormat.register_format(format)
318
bzrdir.BzrProber.formats.register(format.get_format_string(), format)
285
319
# which bzrdir.Open will refuse (not supported)
286
320
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
287
321
# which bzrdir.open_containing will refuse (not supported)
288
322
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
289
323
# but open_downlevel will work
290
t = get_transport(url)
324
t = _mod_transport.get_transport_from_url(url)
291
325
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
292
326
# unregister the format
293
bzrdir.BzrDirFormat.unregister_format(format)
327
bzrdir.BzrProber.formats.remove(format.get_format_string())
294
328
# now open_downlevel should fail too.
295
329
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
483
517
# Clone source into directory
484
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)
486
549
def test_sprout_obeys_stacking_policy(self):
487
550
child_branch, new_child_transport = self.prepare_default_stacking()
488
551
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
679
742
self.assertEqual(relpath, 'baz')
681
744
def test_open_containing_from_transport(self):
682
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
683
get_transport(self.get_readonly_url('')))
684
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
685
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')))
686
752
control = bzrdir.BzrDir.create(self.get_url())
687
753
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
688
get_transport(self.get_readonly_url('')))
754
_mod_transport.get_transport_from_url(
755
self.get_readonly_url('')))
689
756
self.assertEqual('', relpath)
690
757
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
691
get_transport(self.get_readonly_url('g/p/q')))
758
_mod_transport.get_transport_from_url(
759
self.get_readonly_url('g/p/q')))
692
760
self.assertEqual('g/p/q', relpath)
694
762
def test_open_containing_tree_or_branch(self):
738
806
# transport pointing at bzrdir should give a bzrdir with root transport
739
807
# set to the given transport
740
808
control = bzrdir.BzrDir.create(self.get_url())
741
transport = get_transport(self.get_url())
742
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
743
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
809
t = self.get_transport()
810
opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
811
self.assertEqual(t.base, opened_bzrdir.root_transport.base)
744
812
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
746
814
def test_open_from_transport_no_bzrdir(self):
747
transport = get_transport(self.get_url())
748
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
815
t = self.get_transport()
816
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
751
818
def test_open_from_transport_bzrdir_in_parent(self):
752
819
control = bzrdir.BzrDir.create(self.get_url())
753
transport = get_transport(self.get_url())
754
transport.mkdir('subdir')
755
transport = transport.clone('subdir')
756
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
820
t = self.get_transport()
822
t = t.clone('subdir')
823
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
759
825
def test_sprout_recursive(self):
760
826
tree = self.make_branch_and_tree('tree1',
790
856
self.build_tree(['tree1/subtree/file'])
791
857
sub_tree.add('file')
792
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')
793
862
tree.bzrdir.destroy_workingtree()
863
# FIXME: subtree/.bzr is left here which allows the test to pass (or
864
# fail :-( ) -- vila 20100909
794
865
repo = self.make_repository('repo', shared=True,
795
866
format='dirstate-with-subtree')
796
867
repo.set_make_working_trees(False)
797
tree.bzrdir.sprout('repo/tree2')
798
self.failUnlessExists('repo/tree2/subtree')
799
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')
801
881
def make_foo_bar_baz(self):
802
882
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
847
926
return [s for s in transport.list_dir('') if s != 'baz']
849
928
foo, bar, baz = self.make_foo_bar_baz()
850
transport = get_transport(self.get_url())
851
self.assertEqualBzrdirs([foo, bar],
852
bzrdir.BzrDir.find_bzrdirs(transport,
853
list_current=list_current))
929
t = self.get_transport()
930
self.assertEqualBzrdirs(
932
bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
855
934
def test_find_bzrdirs_evaluate(self):
856
935
def evaluate(bzrdir):
858
937
repo = bzrdir.open_repository()
859
except NoRepositoryPresent:
938
except errors.NoRepositoryPresent:
860
939
return True, bzrdir.root_transport.base
862
941
return False, bzrdir.root_transport.base
864
943
foo, bar, baz = self.make_foo_bar_baz()
865
transport = get_transport(self.get_url())
944
t = self.get_transport()
866
945
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
867
list(bzrdir.BzrDir.find_bzrdirs(transport,
946
list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
870
948
def assertEqualBzrdirs(self, first, second):
871
949
first = list(first)
878
956
root = self.make_repository('', shared=True)
879
957
foo, bar, baz = self.make_foo_bar_baz()
880
958
qux = self.make_bzrdir('foo/qux')
881
transport = get_transport(self.get_url())
882
branches = bzrdir.BzrDir.find_branches(transport)
959
t = self.get_transport()
960
branches = bzrdir.BzrDir.find_branches(t)
883
961
self.assertEqual(baz.root_transport.base, branches[0].base)
884
962
self.assertEqual(foo.root_transport.base, branches[1].base)
885
963
self.assertEqual(bar.root_transport.base, branches[2].base)
887
965
# ensure this works without a top-level repo
888
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
966
branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
889
967
self.assertEqual(foo.root_transport.base, branches[0].base)
890
968
self.assertEqual(bar.root_transport.base, branches[1].base)
917
995
dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
918
996
repository_base = t.clone('repository').base
919
997
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
998
repository_format = repository.format_registry.get_default()
920
999
self.assertEqual(repository_base,
921
dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
1000
dir.get_repository_transport(repository_format).base)
922
1001
checkout_base = t.clone('checkout').base
923
1002
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
924
1003
self.assertEqual(checkout_base,
925
dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
1004
dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
927
1006
def test_meta1dir_uses_lockdir(self):
928
1007
"""Meta1 format uses a LockDir to guard the whole directory, not a file."""
970
1049
self.assertEqual(2, rpc_count)
973
class TestFormat5(TestCaseWithTransport):
974
"""Tests specific to the version 5 bzrdir format."""
976
def test_same_lockfiles_between_tree_repo_branch(self):
977
# this checks that only a single lockfiles instance is created
978
# for format 5 objects
979
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
980
def check_dir_components_use_same_lock(dir):
981
ctrl_1 = dir.open_repository().control_files
982
ctrl_2 = dir.open_branch().control_files
983
ctrl_3 = dir.open_workingtree()._control_files
984
self.assertTrue(ctrl_1 is ctrl_2)
985
self.assertTrue(ctrl_2 is ctrl_3)
986
check_dir_components_use_same_lock(dir)
987
# and if we open it normally.
988
dir = bzrdir.BzrDir.open(self.get_url())
989
check_dir_components_use_same_lock(dir)
991
def test_can_convert(self):
992
# format 5 dirs are convertable
993
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
994
self.assertTrue(dir.can_convert_format())
996
def test_needs_conversion(self):
997
# format 5 dirs need a conversion if they are not the default,
999
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1000
# don't need to convert it to itself
1001
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
1002
# do need to convert it to the current default
1003
self.assertTrue(dir.needs_format_conversion(
1004
bzrdir.BzrDirFormat.get_default_format()))
1007
class TestFormat6(TestCaseWithTransport):
1008
"""Tests specific to the version 6 bzrdir format."""
1010
def test_same_lockfiles_between_tree_repo_branch(self):
1011
# this checks that only a single lockfiles instance is created
1012
# for format 6 objects
1013
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1014
def check_dir_components_use_same_lock(dir):
1015
ctrl_1 = dir.open_repository().control_files
1016
ctrl_2 = dir.open_branch().control_files
1017
ctrl_3 = dir.open_workingtree()._control_files
1018
self.assertTrue(ctrl_1 is ctrl_2)
1019
self.assertTrue(ctrl_2 is ctrl_3)
1020
check_dir_components_use_same_lock(dir)
1021
# and if we open it normally.
1022
dir = bzrdir.BzrDir.open(self.get_url())
1023
check_dir_components_use_same_lock(dir)
1025
def test_can_convert(self):
1026
# format 6 dirs are convertable
1027
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1028
self.assertTrue(dir.can_convert_format())
1030
def test_needs_conversion(self):
1031
# format 6 dirs need an conversion if they are not the default.
1032
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1033
self.assertTrue(dir.needs_format_conversion(
1034
bzrdir.BzrDirFormat.get_default_format()))
1037
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1038
"""A non .bzr based control directory."""
1040
def __init__(self, transport, format):
1041
self._format = format
1042
self.root_transport = transport
1043
self.transport = transport.clone('.not')
1046
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1047
"""A test class representing any non-.bzr based disk format."""
1049
def initialize_on_transport(self, transport):
1050
"""Initialize a new .not dir in the base directory of a Transport."""
1051
transport.mkdir('.not')
1052
return self.open(transport)
1054
def open(self, transport):
1055
"""Open this directory."""
1056
return NotBzrDir(transport, self)
1059
def _known_formats(self):
1060
return set([NotBzrDirFormat()])
1063
class NotBzrDirProber(controldir.Prober):
1065
def probe_transport(self, transport):
1066
"""Our format is present if the transport ends in '.not/'."""
1067
if transport.has('.not'):
1068
return NotBzrDirFormat()
1071
class TestNotBzrDir(TestCaseWithTransport):
1072
"""Tests for using the bzrdir api with a non .bzr based disk format.
1074
If/when one of these is in the core, we can let the implementation tests
1078
def test_create_and_find_format(self):
1079
# create a .notbzr dir
1080
format = NotBzrDirFormat()
1081
dir = format.initialize(self.get_url())
1082
self.assertIsInstance(dir, NotBzrDir)
1084
controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1086
found = bzrlib.bzrdir.BzrDirFormat.find_format(
1087
get_transport(self.get_url()))
1088
self.assertIsInstance(found, NotBzrDirFormat)
1090
controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1092
def test_included_in_known_formats(self):
1093
not_format = NotBzrDirFormat()
1094
bzrlib.controldir.ControlDirFormat.register_format(not_format)
1096
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1097
for format in formats:
1098
if isinstance(format, NotBzrDirFormat):
1100
self.fail("No NotBzrDirFormat in %s" % formats)
1102
bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1105
1052
class NonLocalTests(TestCaseWithTransport):
1106
1053
"""Tests for bzrdir static behaviour on non local paths."""
1315
1262
class _TestBranch(bzrlib.branch.Branch):
1316
1263
"""Test Branch implementation for TestBzrDirSprout."""
1318
def __init__(self, *args, **kwargs):
1265
def __init__(self, transport, *args, **kwargs):
1319
1266
self._format = _TestBranchFormat()
1267
self._transport = transport
1268
self.base = transport.base
1320
1269
super(_TestBranch, self).__init__(*args, **kwargs)
1321
1270
self.calls = []
1322
1271
self._parent = None
1324
1273
def sprout(self, *args, **kwargs):
1325
1274
self.calls.append('sprout')
1326
return _TestBranch()
1275
return _TestBranch(self._transport)
1328
1277
def copy_content_into(self, destination, revision_id=None):
1329
1278
self.calls.append('copy_content_into')
1280
def last_revision(self):
1281
return _mod_revision.NULL_REVISION
1331
1283
def get_parent(self):
1332
1284
return self._parent
1286
def _get_config(self):
1287
return config.TransportConfig(self._transport, 'branch.conf')
1334
1289
def set_parent(self, parent):
1335
1290
self._parent = parent
1292
def lock_read(self):
1293
return lock.LogicalLockResult(self.unlock)
1338
1299
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1419
1380
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1381
# FIXME: This may need to be unified with test_osutils.TestBackupNames or
1382
# moved to per_bzrdir or per_transport for better coverage ?
1421
1385
def setUp(self):
1422
1386
super(TestGenerateBackupName, self).setUp()
1423
self._transport = get_transport(self.get_url())
1387
self._transport = self.get_transport()
1424
1388
bzrdir.BzrDir.create(self.get_url(),
1425
1389
possible_transports=[self._transport])
1426
1390
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1392
def test_deprecated_generate_backup_name(self):
1393
res = self.applyDeprecated(
1394
symbol_versioning.deprecated_in((2, 3, 0)),
1395
self._bzrdir.generate_backup_name, 'whatever')
1428
1397
def test_new(self):
1429
self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
1398
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1431
1400
def test_exiting(self):
1432
1401
self._transport.put_bytes("a.~1~", "some content")
1433
self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))
1402
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1405
class TestMeta1DirColoFormat(TestCaseWithTransport):
1406
"""Tests specific to the meta1 dir with colocated branches format."""
1408
def test_supports_colo(self):
1409
format = bzrdir.BzrDirMetaFormat1Colo()
1410
self.assertTrue(format.colocated_branches)
1412
def test_upgrade_from_2a(self):
1413
tree = self.make_branch_and_tree('.', format='2a')
1414
format = bzrdir.BzrDirMetaFormat1Colo()
1415
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1416
converter = tree.bzrdir._format.get_converter(format)
1417
result = converter.convert(tree.bzrdir, None)
1418
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1419
self.assertFalse(result.needs_format_conversion(format))
1421
def test_downgrade_to_2a(self):
1422
tree = self.make_branch_and_tree('.', format='development-colo')
1423
format = bzrdir.BzrDirMetaFormat1()
1424
self.assertTrue(tree.bzrdir.needs_format_conversion(format))
1425
converter = tree.bzrdir._format.get_converter(format)
1426
result = converter.convert(tree.bzrdir, None)
1427
self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1428
self.assertFalse(result.needs_format_conversion(format))
1430
def test_downgrade_to_2a_too_many_branches(self):
1431
tree = self.make_branch_and_tree('.', format='development-colo')
1432
tree.bzrdir.create_branch(name="another-colocated-branch")
1433
converter = tree.bzrdir._format.get_converter(
1434
bzrdir.BzrDirMetaFormat1())
1435
self.assertRaises(errors.BzrError, converter.convert, tree.bzrdir,