99
99
def make_format_registry(self):
100
100
my_format_registry = controldir.ControlDirFormatRegistry()
101
101
my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
102
'Some format. Slower and unawesome and deprecated.',
102
'Some format. Slower and unawesome and deprecated.',
104
104
my_format_registry.register_lazy('lazy', 'breezy.tests.test_bzrdir',
105
'DeprecatedBzrDirFormat', 'Format registered lazily',
105
'DeprecatedBzrDirFormat', 'Format registered lazily',
107
107
bzr.register_metadir(my_format_registry, 'knit',
108
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
109
'Format using knits',
108
'breezy.bzr.knitrepo.RepositoryFormatKnit1',
109
'Format using knits',
111
111
my_format_registry.set_default('knit')
112
112
bzr.register_metadir(my_format_registry,
114
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
115
'Experimental successor to knit. Use at your own risk.',
116
branch_format='breezy.bzr.branch.BzrBranchFormat6',
114
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
115
'Experimental successor to knit. Use at your own risk.',
116
branch_format='breezy.bzr.branch.BzrBranchFormat6',
118
118
bzr.register_metadir(my_format_registry,
120
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
121
'Experimental successor to knit. Use at your own risk.',
122
branch_format='breezy.bzr.branch.BzrBranchFormat6', hidden=True)
120
'breezy.bzr.knitrepo.RepositoryFormatKnit3',
121
'Experimental successor to knit. Use at your own risk.',
122
branch_format='breezy.bzr.branch.BzrBranchFormat6', hidden=True)
123
123
my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
124
'Old format. Slower and does not support things. ', hidden=True)
124
'Old format. Slower and does not support things. ', hidden=True)
125
125
my_format_registry.register_lazy('hiddenlazy', 'breezy.tests.test_bzrdir',
126
'DeprecatedBzrDirFormat', 'Format registered lazily',
127
deprecated=True, hidden=True)
126
'DeprecatedBzrDirFormat', 'Format registered lazily',
127
deprecated=True, hidden=True)
128
128
return my_format_registry
130
130
def test_format_registry(self):
135
135
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
136
136
my_bzrdir = my_format_registry.make_controldir('default')
137
137
self.assertIsInstance(my_bzrdir.repository_format,
138
knitrepo.RepositoryFormatKnit1)
138
knitrepo.RepositoryFormatKnit1)
139
139
my_bzrdir = my_format_registry.make_controldir('knit')
140
140
self.assertIsInstance(my_bzrdir.repository_format,
141
knitrepo.RepositoryFormatKnit1)
141
knitrepo.RepositoryFormatKnit1)
142
142
my_bzrdir = my_format_registry.make_controldir('branch6')
143
143
self.assertIsInstance(my_bzrdir.get_branch_format(),
144
144
breezy.bzr.branch.BzrBranchFormat6)
166
166
experimental, deprecated = rest.split('Deprecated formats')
167
167
self.assertContainsRe(new, 'formats-help')
168
168
self.assertContainsRe(new,
169
':knit:\n \\(native\\) \\(default\\) Format using knits\n')
169
':knit:\n \\(native\\) \\(default\\) Format using knits\n')
170
170
self.assertContainsRe(experimental,
171
':branch6:\n \\(native\\) Experimental successor to knit')
171
':branch6:\n \\(native\\) Experimental successor to knit')
172
172
self.assertContainsRe(deprecated,
173
':lazy:\n \\(native\\) Format registered lazily\n')
173
':lazy:\n \\(native\\) Format registered lazily\n')
174
174
self.assertNotContainsRe(new, 'hidden')
176
176
def test_set_default_repository(self):
177
177
default_factory = controldir.format_registry.get('default')
178
178
old_default = [k for k, v in controldir.format_registry.iteritems()
179
179
if v == default_factory and k != 'default'][0]
180
controldir.format_registry.set_default_repository('dirstate-with-subtree')
180
controldir.format_registry.set_default_repository(
181
'dirstate-with-subtree')
182
183
self.assertIs(controldir.format_registry.get('dirstate-with-subtree'),
183
184
controldir.format_registry.get('default'))
190
191
def test_aliases(self):
191
192
a_registry = controldir.ControlDirFormatRegistry()
192
193
a_registry.register('deprecated', DeprecatedBzrDirFormat,
193
'Old format. Slower and does not support stuff',
195
a_registry.register('deprecatedalias', DeprecatedBzrDirFormat,
196
'Old format. Slower and does not support stuff',
197
deprecated=True, alias=True)
198
self.assertEqual(frozenset(['deprecatedalias']), a_registry.aliases())
194
'Old format. Slower and does not support stuff',
196
a_registry.register_alias('deprecatedalias', 'deprecated')
197
self.assertEqual({'deprecatedalias': 'deprecated'},
198
a_registry.aliases())
201
201
class SampleBranch(breezy.branch.Branch):
283
283
# is the right format object found for a branch?
284
284
# create a branch with a few known format objects.
285
285
bzr.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
287
287
self.addCleanup(bzr.BzrProber.formats.remove,
288
BzrDirFormatTest1.get_format_string())
288
BzrDirFormatTest1.get_format_string())
289
289
bzr.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
291
291
self.addCleanup(bzr.BzrProber.formats.remove,
292
BzrDirFormatTest2.get_format_string())
292
BzrDirFormatTest2.get_format_string())
293
293
t = self.get_transport()
294
294
self.build_tree(["foo/", "bar/"], transport=t)
295
296
def check_format(format, url):
296
297
format.initialize(url)
297
298
t = _mod_transport.get_transport_from_path(url)
308
309
def test_find_format_unknown_format(self):
309
310
t = self.get_transport()
311
t.put_bytes('.bzr/branch-format', '')
312
t.put_bytes('.bzr/branch-format', b'')
312
313
self.assertRaises(UnknownFormatError,
313
314
bzrdir.BzrDirFormat.find_format,
314
315
_mod_transport.get_transport_from_path('.'))
317
def test_find_format_line_endings(self):
318
t = self.get_transport()
320
t.put_bytes('.bzr/branch-format', b'Corrupt line endings\r\n')
321
self.assertRaises(errors.LineEndingError,
322
bzrdir.BzrDirFormat.find_format,
323
_mod_transport.get_transport_from_path('.'))
316
325
def test_register_unregister_format(self):
317
326
format = SampleBzrDirFormat()
318
327
url = self.get_url()
323
332
# which bzrdir.Open will refuse (not supported)
324
333
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
325
334
# which bzrdir.open_containing will refuse (not supported)
326
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
335
self.assertRaises(UnsupportedFormatError,
336
bzrdir.BzrDir.open_containing, url)
327
337
# but open_downlevel will work
328
338
t = _mod_transport.get_transport_from_url(url)
329
339
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
330
340
# unregister the format
331
341
bzr.BzrProber.formats.remove(format.get_format_string())
332
342
# now open_downlevel should fail too.
333
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
343
self.assertRaises(UnknownFormatError,
344
bzrdir.BzrDir.open_unsupported, url)
335
346
def test_create_branch_and_repo_uses_default(self):
336
347
format = SampleBzrDirFormat()
426
437
format = controldir.format_registry.make_controldir('knit')
427
438
self.make_repository('.', shared=True, format=format)
428
439
branch = bzrdir.BzrDir.create_branch_convenience('child',
429
force_new_tree=False, format=format)
440
force_new_tree=False, format=format)
430
441
self.assertRaises(errors.NoWorkingTree,
431
442
branch.controldir.open_workingtree)
432
443
self.assertRaises(errors.NoRepositoryPresent,
452
463
repo = self.make_repository('.', shared=True, format=format)
453
464
repo.set_make_working_trees(False)
454
465
branch = bzrdir.BzrDir.create_branch_convenience('child',
455
force_new_tree=True, format=format)
466
force_new_tree=True, format=format)
456
467
branch.controldir.open_workingtree()
457
468
self.assertRaises(errors.NoRepositoryPresent,
458
469
branch.controldir.open_repository)
463
474
format = controldir.format_registry.make_controldir('knit')
464
475
self.make_repository('.', shared=True, format=format)
465
476
branch = bzrdir.BzrDir.create_branch_convenience('child',
466
force_new_repo=True, format=format)
477
force_new_repo=True, format=format)
467
478
branch.controldir.open_repository()
468
479
branch.controldir.open_workingtree()
532
544
# Should end up with a 1.9 format (stackable)
533
545
repo, control, require_stacking, repo_policy = \
534
546
old_fmt.initialize_on_transport_ex(t,
535
repo_format_name=repo_name, stacked_on='../trunk',
547
repo_format_name=repo_name, stacked_on='../trunk',
537
549
if repo is not None:
538
550
# Repositories are open write-locked
539
551
self.assertTrue(repo.is_write_locked())
544
556
opened = bzrdir.BzrDir.open(t.base)
545
557
if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
546
558
self.assertEqual(control._format.network_name(),
547
old_fmt.network_name())
559
old_fmt.network_name())
548
560
self.assertEqual(control._format.network_name(),
549
opened._format.network_name())
561
opened._format.network_name())
550
562
self.assertEqual(control.__class__, opened.__class__)
551
563
self.assertLength(1, repo._fallback_repositories)
559
571
def test_clone_ignores_policy_for_unsupported_formats(self):
560
572
child_branch, new_child_transport = self.prepare_default_stacking(
561
573
child_format='pack-0.92')
562
new_child = child_branch.controldir.clone_on_transport(new_child_transport)
574
new_child = child_branch.controldir.clone_on_transport(
563
576
self.assertRaises(branch.UnstackableBranchFormat,
564
577
new_child.open_branch().get_stacked_on_url)
585
598
child_branch, new_child_transport = self.prepare_default_stacking(
586
599
child_format='pack-0.92')
587
600
new_child = child_branch.controldir.clone_on_transport(new_child_transport,
588
stacked_on=child_branch.controldir.root_transport.base)
601
stacked_on=child_branch.controldir.root_transport.base)
589
602
self.assertEqual(child_branch.controldir.root_transport.base,
590
603
new_child.open_branch().get_stacked_on_url())
591
604
repo = new_child.open_repository()
625
638
stack_on = self.make_branch('stack_on', format='1.6')
626
639
stacked = self.make_branch('stack_on/stacked', format='1.6')
627
640
policy = bzrdir.UseExistingRepository(stacked.repository,
628
'.', self.get_readonly_url('stack_on'))
641
'.', self.get_readonly_url('stack_on'))
629
642
policy.configure_branch(stacked)
630
643
self.assertEqual(self.get_readonly_url('stack_on'),
631
644
stacked.get_stacked_on_url())
653
666
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
654
667
self.get_readonly_url('g/p/q'))
655
668
control = bzrdir.BzrDir.create(self.get_url())
656
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
669
branch, relpath = bzrdir.BzrDir.open_containing(
670
self.get_readonly_url(''))
657
671
self.assertEqual('', relpath)
658
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
672
branch, relpath = bzrdir.BzrDir.open_containing(
673
self.get_readonly_url('g/p/q'))
659
674
self.assertEqual('g/p/q', relpath)
661
676
def test_open_containing_tree_branch_or_repository_empty(self):
662
677
self.assertRaises(errors.NotBranchError,
663
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
664
self.get_readonly_url(''))
678
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
679
self.get_readonly_url(''))
666
681
def test_open_containing_tree_branch_or_repository_all(self):
667
682
self.make_branch_and_tree('topdir')
748
763
def test_open_containing_from_transport(self):
749
764
self.assertRaises(NotBranchError,
750
bzrdir.BzrDir.open_containing_from_transport,
751
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
765
bzrdir.BzrDir.open_containing_from_transport,
766
_mod_transport.get_transport_from_url(self.get_readonly_url('')))
752
767
self.assertRaises(NotBranchError,
753
bzrdir.BzrDir.open_containing_from_transport,
754
_mod_transport.get_transport_from_url(
755
self.get_readonly_url('g/p/q')))
768
bzrdir.BzrDir.open_containing_from_transport,
769
_mod_transport.get_transport_from_url(
770
self.get_readonly_url('g/p/q')))
756
771
control = bzrdir.BzrDir.create(self.get_url())
757
772
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
758
773
_mod_transport.get_transport_from_url(
827
842
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
829
844
def test_sprout_recursive(self):
830
tree = self.make_branch_and_tree('tree1',
831
format='development-subtree')
832
sub_tree = self.make_branch_and_tree('tree1/subtree',
833
format='development-subtree')
834
sub_tree.set_root_id('subtree-root')
845
tree = self.make_branch_and_tree('tree1')
846
sub_tree = self.make_branch_and_tree('tree1/subtree')
847
sub_tree.set_root_id(b'subtree-root')
835
848
tree.add_reference(sub_tree)
849
tree.set_reference_info('subtree', sub_tree.branch.user_url)
836
850
self.build_tree(['tree1/subtree/file'])
837
851
sub_tree.add('file')
838
852
tree.commit('Initial commit')
851
863
branch = self.make_branch('branch', format='knit')
852
864
format = branch.controldir.cloning_metadir()
853
865
self.assertIsInstance(format.workingtree_format,
854
workingtree_4.WorkingTreeFormat6)
866
workingtree_4.WorkingTreeFormat6)
856
868
def test_sprout_recursive_treeless(self):
857
869
tree = self.make_branch_and_tree('tree1',
858
format='development-subtree')
870
format='development-subtree')
859
871
sub_tree = self.make_branch_and_tree('tree1/subtree',
860
format='development-subtree')
872
format='development-subtree')
861
873
tree.add_reference(sub_tree)
874
tree.set_reference_info('subtree', sub_tree.branch.user_url)
862
875
self.build_tree(['tree1/subtree/file'])
863
876
sub_tree.add('file')
864
877
tree.commit('Initial commit')
865
878
# The following line force the orhaning to reveal bug #634470
866
tree.branch.get_config_stack().set(
867
'bzr.transform.orphan_policy', 'move')
879
tree.branch.get_config_stack().set('transform.orphan_policy', 'move')
868
880
tree.controldir.destroy_workingtree()
869
881
# FIXME: subtree/.bzr is left here which allows the test to pass (or
870
882
# fail :-( ) -- vila 20100909
871
883
repo = self.make_repository('repo', shared=True,
872
format='development-subtree')
884
format='development-subtree')
873
885
repo.set_make_working_trees(False)
874
886
# FIXME: we just deleted the workingtree and now we want to use it ????
875
887
# At a minimum, we should use tree.branch below (but this fails too
879
891
# by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
880
892
# [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
881
893
# #634470. -- vila 20100909
882
self.assertRaises(errors.NotBranchError,
883
tree.controldir.sprout, 'repo/tree2')
884
# self.assertPathExists('repo/tree2/subtree')
885
# self.assertPathDoesNotExist('repo/tree2/subtree/file')
894
tree.controldir.sprout('repo/tree2')
895
self.assertPathExists('repo/tree2/subtree')
896
self.assertPathDoesNotExist('repo/tree2/subtree/file')
887
898
def make_foo_bar_baz(self):
888
899
foo = bzrdir.BzrDir.create_branch_convenience('foo').controldir
893
904
def test_find_controldirs(self):
894
905
foo, bar, baz = self.make_foo_bar_baz()
895
906
t = self.get_transport()
896
self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_controldirs(t))
907
self.assertEqualBzrdirs(
908
[baz, foo, bar], bzrdir.BzrDir.find_controldirs(t))
898
910
def make_fake_permission_denied_transport(self, transport, paths):
899
911
"""Create a transport that raises PermissionDenied for some paths."""
920
932
self.make_fake_permission_denied_transport(t, ['foo'])
921
933
# local transport
922
934
self.assertBranchUrlsEndWith('/baz/',
923
bzrdir.BzrDir.find_controldirs(path_filter_transport))
935
bzrdir.BzrDir.find_controldirs(path_filter_transport))
925
937
smart_transport = self.make_smart_server('.',
926
backing_server=path_filter_server)
938
backing_server=path_filter_server)
927
939
self.assertBranchUrlsEndWith('/baz/',
928
bzrdir.BzrDir.find_controldirs(smart_transport))
940
bzrdir.BzrDir.find_controldirs(smart_transport))
930
942
def test_find_controldirs_list_current(self):
931
943
def list_current(transport):
983
995
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
984
996
t.delete_tree('arepo/.bzr')
985
997
self.assertRaises(errors.NoRepositoryPresent,
986
branch.Branch.open, abranch_url)
998
branch.Branch.open, abranch_url)
987
999
self.make_branch('baz')
988
1000
for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
989
1001
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
1000
1012
self.assertEqual(branch_base,
1001
1013
dir.get_branch_transport(BzrBranchFormat5()).base)
1002
1014
repository_base = t.clone('repository').base
1003
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
1016
repository_base, dir.get_repository_transport(None).base)
1004
1017
repository_format = repository.format_registry.get_default()
1005
1018
self.assertEqual(repository_base,
1006
1019
dir.get_repository_transport(repository_format).base)
1007
1020
checkout_base = t.clone('checkout').base
1008
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
1022
checkout_base, dir.get_workingtree_transport(None).base)
1009
1023
self.assertEqual(checkout_base,
1010
1024
dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
1027
1041
otherdir = controldir.format_registry.make_controldir('knit')
1028
1042
self.assertEqual(otherdir, mydir)
1029
1043
self.assertFalse(otherdir != mydir)
1030
otherdir2 = controldir.format_registry.make_controldir('development-subtree')
1044
otherdir2 = controldir.format_registry.make_controldir(
1045
'development-subtree')
1031
1046
self.assertNotEqual(otherdir2, mydir)
1032
1047
self.assertFalse(otherdir2 == mydir)
1034
1049
def test_with_features(self):
1035
1050
tree = self.make_branch_and_tree('tree', format='2a')
1036
tree.controldir.update_feature_flags({"bar": "required"})
1051
tree.controldir.update_feature_flags({b"bar": b"required"})
1037
1052
self.assertRaises(bzrdir.MissingFeature, bzrdir.BzrDir.open, 'tree')
1038
bzrdir.BzrDirMetaFormat1.register_feature('bar')
1039
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
1053
bzrdir.BzrDirMetaFormat1.register_feature(b'bar')
1054
self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, b'bar')
1040
1055
dir = bzrdir.BzrDir.open('tree')
1041
self.assertEqual("required", dir._format.features.get("bar"))
1042
tree.controldir.update_feature_flags({"bar": None, "nonexistant": None})
1056
self.assertEqual(b"required", dir._format.features.get(b"bar"))
1057
tree.controldir.update_feature_flags({
1059
b"nonexistant": None})
1043
1060
dir = bzrdir.BzrDir.open('tree')
1044
1061
self.assertEqual({}, dir._format.features)
1170
1187
self.assertIsInstance(bdir.root_transport, type(start))
1173
class TestHTTPRedirections_urllib(TestHTTPRedirections,
1174
http_utils.TestCaseWithTwoWebservers):
1190
class TestHTTPRedirections(TestHTTPRedirectionsBase,
1191
http_utils.TestCaseWithTwoWebservers):
1175
1192
"""Tests redirections for urllib implementation"""
1177
_transport = HttpTransport_urllib
1194
_transport = HttpTransport
1179
1196
def _qualified_url(self, host, port):
1180
result = 'http+urllib://%s:%s' % (host, port)
1197
result = 'http://%s:%s' % (host, port)
1181
1198
self.permit_url(result)
1186
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1187
http_utils.TestCaseWithTwoWebservers):
1202
class TestHTTPRedirections_nosmart(TestHTTPRedirectionsBase,
1203
http_utils.TestCaseWithTwoWebservers):
1188
1204
"""Tests redirections for the nosmart decorator"""
1190
1206
_transport = NoSmartTransportDecorator
1216
1232
def get_ls(self):
1217
1233
f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
1218
stderr=subprocess.PIPE)
1234
stderr=subprocess.PIPE)
1219
1235
out, err = f.communicate()
1220
1236
self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1221
1237
% (self.ls, err))
1222
1238
return out.splitlines()
1224
1240
def test_dot_bzr_hidden(self):
1225
if sys.platform == 'win32' and not win32utils.has_win32file:
1226
raise TestSkipped('unable to make file hidden without pywin32 library')
1227
1241
b = bzrdir.BzrDir.create('.')
1228
1242
self.build_tree(['a'])
1229
self.assertEqual(['a'], self.get_ls())
1243
self.assertEqual([b'a'], self.get_ls())
1231
1245
def test_dot_bzr_hidden_with_url(self):
1232
if sys.platform == 'win32' and not win32utils.has_win32file:
1233
raise TestSkipped('unable to make file hidden without pywin32 library')
1234
1246
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1235
1247
self.build_tree(['a'])
1236
self.assertEqual(['a'], self.get_ls())
1248
self.assertEqual([b'a'], self.get_ls())
1239
1251
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1380
1393
def test_post_repo_init_hook_repr(self):
1381
1394
param_reprs = []
1382
1395
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1383
lambda params: param_reprs.append(repr(params)), None)
1396
lambda params: param_reprs.append(repr(params)), None)
1384
1397
self.make_repository('foo')
1385
1398
self.assertLength(1, param_reprs)
1386
1399
param_repr = param_reprs[0]
1396
1409
super(TestGenerateBackupName, self).setUp()
1397
1410
self._transport = self.get_transport()
1398
1411
bzrdir.BzrDir.create(self.get_url(),
1399
possible_transports=[self._transport])
1412
possible_transports=[self._transport])
1400
1413
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1402
1415
def test_new(self):
1403
1416
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1405
1418
def test_exiting(self):
1406
self._transport.put_bytes("a.~1~", "some content")
1419
self._transport.put_bytes("a.~1~", b"some content")
1407
1420
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1456
1469
errors.AlreadyBranchError, tree.controldir.create_branch,
1472
def test_supports_relative_reference(self):
1473
tree = self.make_branch_and_tree('.', format='development-colo')
1474
target1 = tree.controldir.create_branch(name='target1')
1475
target2 = tree.controldir.create_branch(name='target2')
1476
source = tree.controldir.set_branch_reference(target1, name='source')
1478
target1.user_url, tree.controldir.open_branch('source').user_url)
1479
source.controldir.get_branch_transport(None, 'source').put_bytes(
1480
'location', b'file:,branch=target2')
1482
target2.user_url, tree.controldir.open_branch('source').user_url)
1460
1485
class SampleBzrFormat(bzrdir.BzrFormat):
1463
1488
def get_format_string(cls):
1464
return "First line\n"
1489
return b"First line\n"
1467
1492
class TestBzrFormat(TestCase):
1470
1495
def test_as_string(self):
1471
1496
format = SampleBzrFormat()
1472
format.features = {"foo": "required"}
1473
self.assertEqual(format.as_string(),
1476
format.features["another"] = "optional"
1477
self.assertEqual(format.as_string(),
1480
"optional another\n")
1497
format.features = {b"foo": b"required"}
1498
self.assertEqual(format.as_string(),
1501
format.features[b"another"] = b"optional"
1502
self.assertEqual(format.as_string(),
1504
b"optional another\n"
1482
1507
def test_network_name(self):
1483
1508
# The network string should include the feature info
1484
1509
format = SampleBzrFormat()
1485
format.features = {"foo": "required"}
1510
format.features = {b"foo": b"required"}
1486
1511
self.assertEqual(
1487
"First line\nrequired foo\n",
1512
b"First line\nrequired foo\n",
1488
1513
format.network_name())
1490
1515
def test_from_string_no_features(self):
1492
1517
format = SampleBzrFormat.from_string(
1494
1519
self.assertEqual({}, format.features)
1496
1521
def test_from_string_with_feature(self):
1497
1522
# Proper feature
1498
1523
format = SampleBzrFormat.from_string(
1499
"First line\nrequired foo\n")
1500
self.assertEqual("required", format.features.get("foo"))
1524
b"First line\nrequired foo\n")
1525
self.assertEqual(b"required", format.features.get(b"foo"))
1502
1527
def test_from_string_format_string_mismatch(self):
1503
1528
# The first line has to match the format string
1504
1529
self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1505
"Second line\nrequired foo\n")
1530
b"Second line\nrequired foo\n")
1507
1532
def test_from_string_missing_space(self):
1508
1533
# At least one space is required in the feature lines
1509
1534
self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1510
"First line\nfoo\n")
1535
b"First line\nfoo\n")
1512
1537
def test_from_string_with_spaces(self):
1513
1538
# Feature with spaces (in case we add stuff like this in the future)
1514
1539
format = SampleBzrFormat.from_string(
1515
"First line\nrequired foo with spaces\n")
1516
self.assertEqual("required", format.features.get("foo with spaces"))
1540
b"First line\nrequired foo with spaces\n")
1541
self.assertEqual(b"required", format.features.get(b"foo with spaces"))
1518
1543
def test_eq(self):
1519
1544
format1 = SampleBzrFormat()
1520
format1.features = {"nested-trees": "optional"}
1545
format1.features = {b"nested-trees": b"optional"}
1521
1546
format2 = SampleBzrFormat()
1522
format2.features = {"nested-trees": "optional"}
1547
format2.features = {b"nested-trees": b"optional"}
1523
1548
self.assertEqual(format1, format1)
1524
1549
self.assertEqual(format1, format2)
1525
1550
format3 = SampleBzrFormat()
1528
1553
def test_check_support_status_optional(self):
1529
1554
# Optional, so silently ignore
1530
1555
format = SampleBzrFormat()
1531
format.features = {"nested-trees": "optional"}
1556
format.features = {b"nested-trees": b"optional"}
1532
1557
format.check_support_status(True)
1533
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1534
SampleBzrFormat.register_feature("nested-trees")
1558
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1559
SampleBzrFormat.register_feature(b"nested-trees")
1535
1560
format.check_support_status(True)
1537
1562
def test_check_support_status_required(self):
1538
1563
# Optional, so trigger an exception
1539
1564
format = SampleBzrFormat()
1540
format.features = {"nested-trees": "required"}
1565
format.features = {b"nested-trees": b"required"}
1541
1566
self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1543
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1544
SampleBzrFormat.register_feature("nested-trees")
1568
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1569
SampleBzrFormat.register_feature(b"nested-trees")
1545
1570
format.check_support_status(True)
1547
1572
def test_check_support_status_unknown(self):
1548
1573
# treat unknown necessity as required
1549
1574
format = SampleBzrFormat()
1550
format.features = {"nested-trees": "unknown"}
1575
format.features = {b"nested-trees": b"unknown"}
1551
1576
self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1553
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1554
SampleBzrFormat.register_feature("nested-trees")
1578
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1579
SampleBzrFormat.register_feature(b"nested-trees")
1555
1580
format.check_support_status(True)
1557
1582
def test_feature_already_registered(self):
1558
1583
# a feature can only be registered once
1559
self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
1560
SampleBzrFormat.register_feature("nested-trees")
1584
self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1585
SampleBzrFormat.register_feature(b"nested-trees")
1561
1586
self.assertRaises(bzrdir.FeatureAlreadyRegistered,
1562
SampleBzrFormat.register_feature, "nested-trees")
1587
SampleBzrFormat.register_feature, b"nested-trees")
1564
1589
def test_feature_with_space(self):
1565
1590
# spaces are not allowed in feature names
1566
1591
self.assertRaises(ValueError, SampleBzrFormat.register_feature,