61
53
from bzrlib.tests.test_http import TestWithTransport_pycurl
62
54
from bzrlib.transport import (
66
58
from bzrlib.transport.http._urllib import HttpTransport_urllib
67
59
from bzrlib.transport.nosmart import NoSmartTransportDecorator
68
60
from bzrlib.transport.readonly import ReadonlyTransportDecorator
69
from bzrlib.repofmt import knitrepo, knitpack_repo
61
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
72
64
class TestDefaultFormat(TestCase):
74
66
def test_get_set_default_format(self):
75
67
old_format = bzrdir.BzrDirFormat.get_default_format()
76
# default is BzrDirMetaFormat1
77
self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
78
controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
68
# default is BzrDirFormat6
69
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
70
bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
79
71
# creating a bzr dir should now create an instrumented dir.
81
73
result = bzrdir.BzrDir.create('memory:///')
82
self.assertIsInstance(result, SampleBzrDir)
74
self.failUnless(isinstance(result, SampleBzrDir))
84
controldir.ControlDirFormat._set_default_format(old_format)
76
bzrdir.BzrDirFormat._set_default_format(old_format)
85
77
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
88
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
89
"""A deprecated bzr dir format."""
92
80
class TestFormatRegistry(TestCase):
94
82
def make_format_registry(self):
95
my_format_registry = controldir.ControlDirFormatRegistry()
96
my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
97
'Some format. Slower and unawesome and deprecated.',
99
my_format_registry.register_lazy('lazy', 'bzrlib.tests.test_bzrdir',
100
'DeprecatedBzrDirFormat', 'Format registered lazily',
102
bzrdir.register_metadir(my_format_registry, 'knit',
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',
103
90
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
104
91
'Format using knits',
106
93
my_format_registry.set_default('knit')
107
bzrdir.register_metadir(my_format_registry,
94
my_format_registry.register_metadir(
109
96
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
110
97
'Experimental successor to knit. Use at your own risk.',
111
98
branch_format='bzrlib.branch.BzrBranchFormat6',
112
99
experimental=True)
113
bzrdir.register_metadir(my_format_registry,
100
my_format_registry.register_metadir(
115
102
'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
116
103
'Experimental successor to knit. Use at your own risk.',
117
104
branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
118
my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
119
'Old format. Slower and does not support things. ', hidden=True)
120
my_format_registry.register_lazy('hiddenlazy', 'bzrlib.tests.test_bzrdir',
121
'DeprecatedBzrDirFormat', 'Format registered lazily',
122
deprecated=True, 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,
123
111
return my_format_registry
125
113
def test_format_registry(self):
126
114
my_format_registry = self.make_format_registry()
127
115
my_bzrdir = my_format_registry.make_bzrdir('lazy')
128
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
129
my_bzrdir = my_format_registry.make_bzrdir('deprecated')
130
self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
116
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
117
my_bzrdir = my_format_registry.make_bzrdir('weave')
118
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
131
119
my_bzrdir = my_format_registry.make_bzrdir('default')
132
120
self.assertIsInstance(my_bzrdir.repository_format,
133
121
knitrepo.RepositoryFormatKnit1)
177
166
self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
178
167
bzrdir.format_registry.get('default'))
180
repository.format_registry.get_default().__class__,
169
repository.RepositoryFormat.get_default_format().__class__,
181
170
knitrepo.RepositoryFormatKnit3)
183
172
bzrdir.format_registry.set_default_repository(old_default)
185
174
def test_aliases(self):
186
a_registry = controldir.ControlDirFormatRegistry()
187
a_registry.register('deprecated', DeprecatedBzrDirFormat,
188
'Old format. Slower and does not support stuff',
190
a_registry.register('deprecatedalias', DeprecatedBzrDirFormat,
191
'Old format. Slower and does not support stuff',
192
deprecated=True, alias=True)
193
self.assertEqual(frozenset(['deprecatedalias']), a_registry.aliases())
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())
196
185
class SampleBranch(bzrlib.branch.Branch):
253
242
return "opened branch."
256
class BzrDirFormatTest1(bzrdir.BzrDirMetaFormat1):
259
def get_format_string():
260
return "Test format 1"
263
class BzrDirFormatTest2(bzrdir.BzrDirMetaFormat1):
266
def get_format_string():
267
return "Test format 2"
270
245
class TestBzrDirFormat(TestCaseWithTransport):
271
246
"""Tests for the BzrDirFormat facility."""
273
248
def test_find_format(self):
274
249
# is the right format object found for a branch?
275
250
# create a branch with a few known format objects.
276
bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
278
self.addCleanup(bzrdir.BzrProber.formats.remove,
279
BzrDirFormatTest1.get_format_string())
280
bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
282
self.addCleanup(bzrdir.BzrProber.formats.remove,
283
BzrDirFormatTest2.get_format_string())
284
t = self.get_transport()
251
# this is not quite the same as
252
t = get_transport(self.get_url())
285
253
self.build_tree(["foo/", "bar/"], transport=t)
286
254
def check_format(format, url):
287
255
format.initialize(url)
288
t = _mod_transport.get_transport(url)
256
t = get_transport(url)
289
257
found_format = bzrdir.BzrDirFormat.find_format(t)
290
self.assertIsInstance(found_format, format.__class__)
291
check_format(BzrDirFormatTest1(), "foo")
292
check_format(BzrDirFormatTest2(), "bar")
258
self.failUnless(isinstance(found_format, format.__class__))
259
check_format(bzrdir.BzrDirFormat5(), "foo")
260
check_format(bzrdir.BzrDirFormat6(), "bar")
294
262
def test_find_format_nothing_there(self):
295
263
self.assertRaises(NotBranchError,
296
264
bzrdir.BzrDirFormat.find_format,
297
_mod_transport.get_transport('.'))
299
267
def test_find_format_unknown_format(self):
300
t = self.get_transport()
268
t = get_transport(self.get_url())
302
270
t.put_bytes('.bzr/branch-format', '')
303
271
self.assertRaises(UnknownFormatError,
304
272
bzrdir.BzrDirFormat.find_format,
305
_mod_transport.get_transport('.'))
307
275
def test_register_unregister_format(self):
308
276
format = SampleBzrDirFormat()
311
279
format.initialize(url)
312
280
# register a format for it.
313
bzrdir.BzrProber.formats.register(format.get_format_string(), format)
281
bzrdir.BzrDirFormat.register_format(format)
314
282
# which bzrdir.Open will refuse (not supported)
315
283
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
316
284
# which bzrdir.open_containing will refuse (not supported)
317
285
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
318
286
# but open_downlevel will work
319
t = _mod_transport.get_transport(url)
287
t = get_transport(url)
320
288
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
321
289
# unregister the format
322
bzrdir.BzrProber.formats.remove(format.get_format_string())
290
bzrdir.BzrDirFormat.unregister_format(format)
323
291
# now open_downlevel should fail too.
324
292
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
708
676
self.assertEqual(relpath, 'baz')
710
678
def test_open_containing_from_transport(self):
711
self.assertRaises(NotBranchError,
712
bzrdir.BzrDir.open_containing_from_transport,
713
_mod_transport.get_transport(self.get_readonly_url('')))
714
self.assertRaises(NotBranchError,
715
bzrdir.BzrDir.open_containing_from_transport,
716
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
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')))
717
683
control = bzrdir.BzrDir.create(self.get_url())
718
684
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
719
_mod_transport.get_transport(self.get_readonly_url('')))
685
get_transport(self.get_readonly_url('')))
720
686
self.assertEqual('', relpath)
721
687
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
722
_mod_transport.get_transport(self.get_readonly_url('g/p/q')))
688
get_transport(self.get_readonly_url('g/p/q')))
723
689
self.assertEqual('g/p/q', relpath)
725
691
def test_open_containing_tree_or_branch(self):
769
735
# transport pointing at bzrdir should give a bzrdir with root transport
770
736
# set to the given transport
771
737
control = bzrdir.BzrDir.create(self.get_url())
772
t = self.get_transport()
773
opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
774
self.assertEqual(t.base, opened_bzrdir.root_transport.base)
738
transport = get_transport(self.get_url())
739
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
740
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
775
741
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
777
743
def test_open_from_transport_no_bzrdir(self):
778
t = self.get_transport()
779
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
744
transport = get_transport(self.get_url())
745
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
781
748
def test_open_from_transport_bzrdir_in_parent(self):
782
749
control = bzrdir.BzrDir.create(self.get_url())
783
t = self.get_transport()
785
t = t.clone('subdir')
786
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
750
transport = get_transport(self.get_url())
751
transport.mkdir('subdir')
752
transport = transport.clone('subdir')
753
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
788
756
def test_sprout_recursive(self):
789
757
tree = self.make_branch_and_tree('tree1',
819
787
self.build_tree(['tree1/subtree/file'])
820
788
sub_tree.add('file')
821
789
tree.commit('Initial commit')
822
# The following line force the orhaning to reveal bug #634470
823
tree.branch.get_config().set_user_option(
824
'bzr.transform.orphan_policy', 'move')
825
790
tree.bzrdir.destroy_workingtree()
826
# FIXME: subtree/.bzr is left here which allows the test to pass (or
827
# fail :-( ) -- vila 20100909
828
791
repo = self.make_repository('repo', shared=True,
829
792
format='dirstate-with-subtree')
830
793
repo.set_make_working_trees(False)
831
# FIXME: we just deleted the workingtree and now we want to use it ????
832
# At a minimum, we should use tree.branch below (but this fails too
833
# currently) or stop calling this test 'treeless'. Specifically, I've
834
# turn the line below into an assertRaises when 'subtree/.bzr' is
835
# orphaned and sprout tries to access the branch there (which is left
836
# by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
837
# [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
838
# #634470. -- vila 20100909
839
self.assertRaises(errors.NotBranchError,
840
tree.bzrdir.sprout, 'repo/tree2')
841
# self.assertPathExists('repo/tree2/subtree')
842
# self.assertPathDoesNotExist('repo/tree2/subtree/file')
794
tree.bzrdir.sprout('repo/tree2')
795
self.failUnlessExists('repo/tree2/subtree')
796
self.failIfExists('repo/tree2/subtree/file')
844
798
def make_foo_bar_baz(self):
845
799
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
850
804
def test_find_bzrdirs(self):
851
805
foo, bar, baz = self.make_foo_bar_baz()
852
t = self.get_transport()
853
self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
855
def make_fake_permission_denied_transport(self, transport, paths):
856
"""Create a transport that raises PermissionDenied for some paths."""
859
raise errors.PermissionDenied(path)
861
path_filter_server = pathfilter.PathFilteringServer(transport, filter)
862
path_filter_server.start_server()
863
self.addCleanup(path_filter_server.stop_server)
864
path_filter_transport = pathfilter.PathFilteringTransport(
865
path_filter_server, '.')
866
return (path_filter_server, path_filter_transport)
868
def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
869
"""Check that each branch url ends with the given suffix."""
870
for actual_bzrdir in actual_bzrdirs:
871
self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
873
def test_find_bzrdirs_permission_denied(self):
874
foo, bar, baz = self.make_foo_bar_baz()
875
t = self.get_transport()
876
path_filter_server, path_filter_transport = \
877
self.make_fake_permission_denied_transport(t, ['foo'])
879
self.assertBranchUrlsEndWith('/baz/',
880
bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
882
smart_transport = self.make_smart_server('.',
883
backing_server=path_filter_server)
884
self.assertBranchUrlsEndWith('/baz/',
885
bzrdir.BzrDir.find_bzrdirs(smart_transport))
806
transport = get_transport(self.get_url())
807
self.assertEqualBzrdirs([baz, foo, bar],
808
bzrdir.BzrDir.find_bzrdirs(transport))
887
810
def test_find_bzrdirs_list_current(self):
888
811
def list_current(transport):
889
812
return [s for s in transport.list_dir('') if s != 'baz']
891
814
foo, bar, baz = self.make_foo_bar_baz()
892
t = self.get_transport()
893
self.assertEqualBzrdirs(
895
bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
815
transport = get_transport(self.get_url())
816
self.assertEqualBzrdirs([foo, bar],
817
bzrdir.BzrDir.find_bzrdirs(transport,
818
list_current=list_current))
897
821
def test_find_bzrdirs_evaluate(self):
898
822
def evaluate(bzrdir):
919
844
root = self.make_repository('', shared=True)
920
845
foo, bar, baz = self.make_foo_bar_baz()
921
846
qux = self.make_bzrdir('foo/qux')
922
t = self.get_transport()
923
branches = bzrdir.BzrDir.find_branches(t)
847
transport = get_transport(self.get_url())
848
branches = bzrdir.BzrDir.find_branches(transport)
924
849
self.assertEqual(baz.root_transport.base, branches[0].base)
925
850
self.assertEqual(foo.root_transport.base, branches[1].base)
926
851
self.assertEqual(bar.root_transport.base, branches[2].base)
928
853
# ensure this works without a top-level repo
929
branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
854
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
930
855
self.assertEqual(foo.root_transport.base, branches[0].base)
931
856
self.assertEqual(bar.root_transport.base, branches[1].base)
934
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
936
def test_find_bzrdirs_missing_repo(self):
937
t = self.get_transport()
938
arepo = self.make_repository('arepo', shared=True)
939
abranch_url = arepo.user_url + '/abranch'
940
abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
941
t.delete_tree('arepo/.bzr')
942
self.assertRaises(errors.NoRepositoryPresent,
943
branch.Branch.open, abranch_url)
944
self.make_branch('baz')
945
for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
946
self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
949
859
class TestMeta1DirFormat(TestCaseWithTransport):
950
860
"""Tests specific to the meta1 dir format."""
958
868
dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
959
869
repository_base = t.clone('repository').base
960
870
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
961
repository_format = repository.format_registry.get_default()
962
871
self.assertEqual(repository_base,
963
dir.get_repository_transport(repository_format).base)
872
dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
964
873
checkout_base = t.clone('checkout').base
965
874
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
966
875
self.assertEqual(checkout_base,
967
dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
876
dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
969
878
def test_meta1dir_uses_lockdir(self):
970
879
"""Meta1 format uses a LockDir to guard the whole directory, not a file."""
1012
921
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)
1015
1053
class NonLocalTests(TestCaseWithTransport):
1016
1054
"""Tests for bzrdir static behaviour on non local paths."""
1324
1351
self.assertIsInstance(params, RepoInitHookParams)
1325
1352
self.assertTrue(hasattr(params, 'bzrdir'))
1326
1353
self.assertTrue(hasattr(params, 'repository'))
1328
def test_post_repo_init_hook_repr(self):
1330
bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1331
lambda params: param_reprs.append(repr(params)), None)
1332
self.make_repository('foo')
1333
self.assertLength(1, param_reprs)
1334
param_repr = param_reprs[0]
1335
self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1338
class TestGenerateBackupName(TestCaseWithMemoryTransport):
1339
# FIXME: This may need to be unified with test_osutils.TestBackupNames or
1340
# moved to per_bzrdir or per_transport for better coverage ?
1344
super(TestGenerateBackupName, self).setUp()
1345
self._transport = self.get_transport()
1346
bzrdir.BzrDir.create(self.get_url(),
1347
possible_transports=[self._transport])
1348
self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1350
def test_deprecated_generate_backup_name(self):
1351
res = self.applyDeprecated(
1352
symbol_versioning.deprecated_in((2, 3, 0)),
1353
self._bzrdir.generate_backup_name, 'whatever')
1356
self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1358
def test_exiting(self):
1359
self._transport.put_bytes("a.~1~", "some content")
1360
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))