~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
29
29
    controldir,
30
30
    errors,
31
31
    help_topics,
 
32
    lock,
32
33
    repository,
 
34
    revision as _mod_revision,
33
35
    osutils,
34
36
    remote,
 
37
    symbol_versioning,
 
38
    transport as _mod_transport,
35
39
    urlutils,
36
40
    win32utils,
37
 
    workingtree,
 
41
    workingtree_3,
 
42
    workingtree_4,
38
43
    )
39
44
import bzrlib.branch
40
 
from bzrlib.errors import (NotBranchError,
41
 
                           NoColocatedBranchSupport,
42
 
                           UnknownFormatError,
43
 
                           UnsupportedFormatError,
44
 
                           )
 
45
from bzrlib.errors import (
 
46
    NotBranchError,
 
47
    NoColocatedBranchSupport,
 
48
    UnknownFormatError,
 
49
    UnsupportedFormatError,
 
50
    )
45
51
from bzrlib.tests import (
46
52
    TestCase,
47
53
    TestCaseWithMemoryTransport,
54
60
    )
55
61
from bzrlib.tests.test_http import TestWithTransport_pycurl
56
62
from bzrlib.transport import (
57
 
    get_transport,
58
63
    memory,
59
64
    pathfilter,
60
65
    )
61
66
from bzrlib.transport.http._urllib import HttpTransport_urllib
62
67
from bzrlib.transport.nosmart import NoSmartTransportDecorator
63
68
from bzrlib.transport.readonly import ReadonlyTransportDecorator
64
 
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
 
69
from bzrlib.repofmt import knitrepo, knitpack_repo
65
70
 
66
71
 
67
72
class TestDefaultFormat(TestCase):
68
73
 
69
74
    def test_get_set_default_format(self):
70
75
        old_format = bzrdir.BzrDirFormat.get_default_format()
71
 
        # default is BzrDirFormat6
72
 
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
 
76
        # default is BzrDirMetaFormat1
 
77
        self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
73
78
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
74
79
        # creating a bzr dir should now create an instrumented dir.
75
80
        try:
76
81
            result = bzrdir.BzrDir.create('memory:///')
77
 
            self.failUnless(isinstance(result, SampleBzrDir))
 
82
            self.assertIsInstance(result, SampleBzrDir)
78
83
        finally:
79
84
            controldir.ControlDirFormat._set_default_format(old_format)
80
85
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
81
86
 
82
87
 
 
88
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
 
89
    """A deprecated bzr dir format."""
 
90
 
 
91
 
83
92
class TestFormatRegistry(TestCase):
84
93
 
85
94
    def make_format_registry(self):
86
95
        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)
 
96
        my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
 
97
            'Some format.  Slower and unawesome and deprecated.',
 
98
            deprecated=True)
 
99
        my_format_registry.register_lazy('lazy', 'bzrlib.tests.test_bzrdir',
 
100
            'DeprecatedBzrDirFormat', 'Format registered lazily',
 
101
            deprecated=True)
92
102
        bzrdir.register_metadir(my_format_registry, 'knit',
93
103
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
94
104
            'Format using knits',
105
115
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
106
116
            'Experimental successor to knit.  Use at your own risk.',
107
117
            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,
113
 
            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)
114
123
        return my_format_registry
115
124
 
116
125
    def test_format_registry(self):
117
126
        my_format_registry = self.make_format_registry()
118
127
        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)
 
128
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
 
129
        my_bzrdir = my_format_registry.make_bzrdir('deprecated')
 
130
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
122
131
        my_bzrdir = my_format_registry.make_bzrdir('default')
123
132
        self.assertIsInstance(my_bzrdir.repository_format,
124
133
            knitrepo.RepositoryFormatKnit1)
137
146
                         my_format_registry.get_help('knit'))
138
147
        self.assertEqual('Format using knits',
139
148
                         my_format_registry.get_help('default'))
140
 
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
141
 
                         ' checkouts or shared repositories',
142
 
                         my_format_registry.get_help('weave'))
 
149
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
 
150
                         my_format_registry.get_help('deprecated'))
143
151
 
144
152
    def test_help_topic(self):
145
153
        topics = help_topics.HelpTopicRegistry()
169
177
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
170
178
                          bzrdir.format_registry.get('default'))
171
179
            self.assertIs(
172
 
                repository.RepositoryFormat.get_default_format().__class__,
 
180
                repository.format_registry.get_default().__class__,
173
181
                knitrepo.RepositoryFormatKnit3)
174
182
        finally:
175
183
            bzrdir.format_registry.set_default_repository(old_default)
176
184
 
177
185
    def test_aliases(self):
178
186
        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())
 
187
        a_registry.register('deprecated', DeprecatedBzrDirFormat,
 
188
            'Old format.  Slower and does not support stuff',
 
189
            deprecated=True)
 
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())
186
194
 
187
195
 
188
196
class SampleBranch(bzrlib.branch.Branch):
245
253
        return "opened branch."
246
254
 
247
255
 
 
256
class BzrDirFormatTest1(bzrdir.BzrDirMetaFormat1):
 
257
 
 
258
    @staticmethod
 
259
    def get_format_string():
 
260
        return "Test format 1"
 
261
 
 
262
 
 
263
class BzrDirFormatTest2(bzrdir.BzrDirMetaFormat1):
 
264
 
 
265
    @staticmethod
 
266
    def get_format_string():
 
267
        return "Test format 2"
 
268
 
 
269
 
248
270
class TestBzrDirFormat(TestCaseWithTransport):
249
271
    """Tests for the BzrDirFormat facility."""
250
272
 
251
273
    def test_find_format(self):
252
274
        # is the right format object found for a branch?
253
275
        # create a branch with a few known format objects.
254
 
        # this is not quite the same as
255
 
        t = get_transport(self.get_url())
 
276
        bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
 
277
            BzrDirFormatTest1())
 
278
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
279
            BzrDirFormatTest1.get_format_string())
 
280
        bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
 
281
            BzrDirFormatTest2())
 
282
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
283
            BzrDirFormatTest2.get_format_string())
 
284
        t = self.get_transport()
256
285
        self.build_tree(["foo/", "bar/"], transport=t)
257
286
        def check_format(format, url):
258
287
            format.initialize(url)
259
 
            t = get_transport(url)
 
288
            t = _mod_transport.get_transport(url)
260
289
            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")
 
290
            self.assertIsInstance(found_format, format.__class__)
 
291
        check_format(BzrDirFormatTest1(), "foo")
 
292
        check_format(BzrDirFormatTest2(), "bar")
264
293
 
265
294
    def test_find_format_nothing_there(self):
266
295
        self.assertRaises(NotBranchError,
267
296
                          bzrdir.BzrDirFormat.find_format,
268
 
                          get_transport('.'))
 
297
                          _mod_transport.get_transport('.'))
269
298
 
270
299
    def test_find_format_unknown_format(self):
271
 
        t = get_transport(self.get_url())
 
300
        t = self.get_transport()
272
301
        t.mkdir('.bzr')
273
302
        t.put_bytes('.bzr/branch-format', '')
274
303
        self.assertRaises(UnknownFormatError,
275
304
                          bzrdir.BzrDirFormat.find_format,
276
 
                          get_transport('.'))
 
305
                          _mod_transport.get_transport('.'))
277
306
 
278
307
    def test_register_unregister_format(self):
279
308
        format = SampleBzrDirFormat()
281
310
        # make a bzrdir
282
311
        format.initialize(url)
283
312
        # register a format for it.
284
 
        bzrdir.BzrDirFormat.register_format(format)
 
313
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
285
314
        # which bzrdir.Open will refuse (not supported)
286
315
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
287
316
        # which bzrdir.open_containing will refuse (not supported)
288
317
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
289
318
        # but open_downlevel will work
290
 
        t = get_transport(url)
 
319
        t = _mod_transport.get_transport(url)
291
320
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
292
321
        # unregister the format
293
 
        bzrdir.BzrDirFormat.unregister_format(format)
 
322
        bzrdir.BzrProber.formats.remove(format.get_format_string())
294
323
        # now open_downlevel should fail too.
295
324
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
296
325
 
473
502
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
474
503
        # Make stackable source branch with an unstackable repo format.
475
504
        source_bzrdir = self.make_bzrdir('source')
476
 
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
505
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
477
506
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
478
507
            source_bzrdir)
479
508
        # Make a directory with a default stacking policy
679
708
        self.assertEqual(relpath, 'baz')
680
709
 
681
710
    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')))
 
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')))
686
717
        control = bzrdir.BzrDir.create(self.get_url())
687
718
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
688
 
            get_transport(self.get_readonly_url('')))
 
719
            _mod_transport.get_transport(self.get_readonly_url('')))
689
720
        self.assertEqual('', relpath)
690
721
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
691
 
            get_transport(self.get_readonly_url('g/p/q')))
 
722
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
692
723
        self.assertEqual('g/p/q', relpath)
693
724
 
694
725
    def test_open_containing_tree_or_branch(self):
738
769
        # transport pointing at bzrdir should give a bzrdir with root transport
739
770
        # set to the given transport
740
771
        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)
 
772
        t = self.get_transport()
 
773
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
 
774
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
744
775
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
745
776
 
746
777
    def test_open_from_transport_no_bzrdir(self):
747
 
        transport = get_transport(self.get_url())
748
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
749
 
                          transport)
 
778
        t = self.get_transport()
 
779
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
750
780
 
751
781
    def test_open_from_transport_bzrdir_in_parent(self):
752
782
        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,
757
 
                          transport)
 
783
        t = self.get_transport()
 
784
        t.mkdir('subdir')
 
785
        t = t.clone('subdir')
 
786
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
758
787
 
759
788
    def test_sprout_recursive(self):
760
789
        tree = self.make_branch_and_tree('tree1',
769
798
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
770
799
        tree2.lock_read()
771
800
        self.addCleanup(tree2.unlock)
772
 
        self.failUnlessExists('tree2/subtree/file')
 
801
        self.assertPathExists('tree2/subtree/file')
773
802
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
774
803
 
775
804
    def test_cloning_metadir(self):
779
808
        branch = self.make_branch('branch', format='knit')
780
809
        format = branch.bzrdir.cloning_metadir()
781
810
        self.assertIsInstance(format.workingtree_format,
782
 
            workingtree.WorkingTreeFormat3)
 
811
            workingtree_4.WorkingTreeFormat6)
783
812
 
784
813
    def test_sprout_recursive_treeless(self):
785
814
        tree = self.make_branch_and_tree('tree1',
790
819
        self.build_tree(['tree1/subtree/file'])
791
820
        sub_tree.add('file')
792
821
        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')
793
825
        tree.bzrdir.destroy_workingtree()
 
826
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
 
827
        # fail :-( ) -- vila 20100909
794
828
        repo = self.make_repository('repo', shared=True,
795
829
            format='dirstate-with-subtree')
796
830
        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')
 
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')
800
843
 
801
844
    def make_foo_bar_baz(self):
802
845
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
806
849
 
807
850
    def test_find_bzrdirs(self):
808
851
        foo, bar, baz = self.make_foo_bar_baz()
809
 
        transport = get_transport(self.get_url())
810
 
        self.assertEqualBzrdirs([baz, foo, bar],
811
 
                                bzrdir.BzrDir.find_bzrdirs(transport))
 
852
        t = self.get_transport()
 
853
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
812
854
 
813
855
    def make_fake_permission_denied_transport(self, transport, paths):
814
856
        """Create a transport that raises PermissionDenied for some paths."""
830
872
 
831
873
    def test_find_bzrdirs_permission_denied(self):
832
874
        foo, bar, baz = self.make_foo_bar_baz()
833
 
        transport = get_transport(self.get_url())
 
875
        t = self.get_transport()
834
876
        path_filter_server, path_filter_transport = \
835
 
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
877
            self.make_fake_permission_denied_transport(t, ['foo'])
836
878
        # local transport
837
879
        self.assertBranchUrlsEndWith('/baz/',
838
880
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
847
889
            return [s for s in transport.list_dir('') if s != 'baz']
848
890
 
849
891
        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))
 
892
        t = self.get_transport()
 
893
        self.assertEqualBzrdirs(
 
894
            [foo, bar],
 
895
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
854
896
 
855
897
    def test_find_bzrdirs_evaluate(self):
856
898
        def evaluate(bzrdir):
862
904
                return False, bzrdir.root_transport.base
863
905
 
864
906
        foo, bar, baz = self.make_foo_bar_baz()
865
 
        transport = get_transport(self.get_url())
 
907
        t = self.get_transport()
866
908
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
867
 
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
868
 
                                                         evaluate=evaluate)))
 
909
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
869
910
 
870
911
    def assertEqualBzrdirs(self, first, second):
871
912
        first = list(first)
878
919
        root = self.make_repository('', shared=True)
879
920
        foo, bar, baz = self.make_foo_bar_baz()
880
921
        qux = self.make_bzrdir('foo/qux')
881
 
        transport = get_transport(self.get_url())
882
 
        branches = bzrdir.BzrDir.find_branches(transport)
 
922
        t = self.get_transport()
 
923
        branches = bzrdir.BzrDir.find_branches(t)
883
924
        self.assertEqual(baz.root_transport.base, branches[0].base)
884
925
        self.assertEqual(foo.root_transport.base, branches[1].base)
885
926
        self.assertEqual(bar.root_transport.base, branches[2].base)
886
927
 
887
928
        # ensure this works without a top-level repo
888
 
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
 
929
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
889
930
        self.assertEqual(foo.root_transport.base, branches[0].base)
890
931
        self.assertEqual(bar.root_transport.base, branches[1].base)
891
932
 
893
934
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
894
935
 
895
936
    def test_find_bzrdirs_missing_repo(self):
896
 
        transport = get_transport(self.get_url())
 
937
        t = self.get_transport()
897
938
        arepo = self.make_repository('arepo', shared=True)
898
939
        abranch_url = arepo.user_url + '/abranch'
899
940
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
900
 
        transport.delete_tree('arepo/.bzr')
 
941
        t.delete_tree('arepo/.bzr')
901
942
        self.assertRaises(errors.NoRepositoryPresent,
902
943
            branch.Branch.open, abranch_url)
903
944
        self.make_branch('baz')
904
 
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
 
945
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
905
946
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
906
947
 
907
948
 
917
958
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
918
959
        repository_base = t.clone('repository').base
919
960
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
 
961
        repository_format = repository.format_registry.get_default()
920
962
        self.assertEqual(repository_base,
921
 
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
 
963
                         dir.get_repository_transport(repository_format).base)
922
964
        checkout_base = t.clone('checkout').base
923
965
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
924
966
        self.assertEqual(checkout_base,
925
 
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
 
967
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
926
968
 
927
969
    def test_meta1dir_uses_lockdir(self):
928
970
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
970
1012
        self.assertEqual(2, rpc_count)
971
1013
 
972
1014
 
973
 
class TestFormat5(TestCaseWithTransport):
974
 
    """Tests specific to the version 5 bzrdir format."""
975
 
 
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)
990
 
 
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())
995
 
 
996
 
    def test_needs_conversion(self):
997
 
        # format 5 dirs need a conversion if they are not the default,
998
 
        # and they aren't
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()))
1005
 
 
1006
 
 
1007
 
class TestFormat6(TestCaseWithTransport):
1008
 
    """Tests specific to the version 6 bzrdir format."""
1009
 
 
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)
1024
 
 
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())
1029
 
 
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()))
1035
 
 
1036
 
 
1037
 
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1038
 
    """A non .bzr based control directory."""
1039
 
 
1040
 
    def __init__(self, transport, format):
1041
 
        self._format = format
1042
 
        self.root_transport = transport
1043
 
        self.transport = transport.clone('.not')
1044
 
 
1045
 
 
1046
 
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1047
 
    """A test class representing any non-.bzr based disk format."""
1048
 
 
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)
1053
 
 
1054
 
    def open(self, transport):
1055
 
        """Open this directory."""
1056
 
        return NotBzrDir(transport, self)
1057
 
 
1058
 
    @classmethod
1059
 
    def _known_formats(self):
1060
 
        return set([NotBzrDirFormat()])
1061
 
 
1062
 
 
1063
 
class NotBzrDirProber(controldir.Prober):
1064
 
 
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()
1069
 
 
1070
 
 
1071
 
class TestNotBzrDir(TestCaseWithTransport):
1072
 
    """Tests for using the bzrdir api with a non .bzr based disk format.
1073
 
 
1074
 
    If/when one of these is in the core, we can let the implementation tests
1075
 
    verify this works.
1076
 
    """
1077
 
 
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)
1083
 
        # now probe for it.
1084
 
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1085
 
        try:
1086
 
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
1087
 
                get_transport(self.get_url()))
1088
 
            self.assertIsInstance(found, NotBzrDirFormat)
1089
 
        finally:
1090
 
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1091
 
 
1092
 
    def test_included_in_known_formats(self):
1093
 
        not_format = NotBzrDirFormat()
1094
 
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
1095
 
        try:
1096
 
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1097
 
            for format in formats:
1098
 
                if isinstance(format, NotBzrDirFormat):
1099
 
                    return
1100
 
            self.fail("No NotBzrDirFormat in %s" % formats)
1101
 
        finally:
1102
 
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1103
 
 
1104
 
 
1105
1015
class NonLocalTests(TestCaseWithTransport):
1106
1016
    """Tests for bzrdir static behaviour on non local paths."""
1107
1017
 
1126
1036
            self.get_url('foo'),
1127
1037
            force_new_tree=True,
1128
1038
            format=format)
1129
 
        t = get_transport(self.get_url('.'))
 
1039
        t = self.get_transport()
1130
1040
        self.assertFalse(t.has('foo'))
1131
1041
 
1132
1042
    def test_clone(self):
1148
1058
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1149
1059
        checkout_format = my_bzrdir.checkout_metadir()
1150
1060
        self.assertIsInstance(checkout_format.workingtree_format,
1151
 
                              workingtree.WorkingTreeFormat3)
 
1061
                              workingtree_4.WorkingTreeFormat4)
1152
1062
 
1153
1063
 
1154
1064
class TestHTTPRedirections(object):
1328
1238
    def copy_content_into(self, destination, revision_id=None):
1329
1239
        self.calls.append('copy_content_into')
1330
1240
 
 
1241
    def last_revision(self):
 
1242
        return _mod_revision.NULL_REVISION
 
1243
 
1331
1244
    def get_parent(self):
1332
1245
        return self._parent
1333
1246
 
1334
1247
    def set_parent(self, parent):
1335
1248
        self._parent = parent
1336
1249
 
 
1250
    def lock_read(self):
 
1251
        return lock.LogicalLockResult(self.unlock)
 
1252
 
 
1253
    def unlock(self):
 
1254
        return
 
1255
 
1337
1256
 
1338
1257
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1339
1258
 
1417
1336
 
1418
1337
 
1419
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 ?
 
1341
    # -- vila 20100909
1420
1342
 
1421
1343
    def setUp(self):
1422
1344
        super(TestGenerateBackupName, self).setUp()
1423
 
        self._transport = get_transport(self.get_url())
 
1345
        self._transport = self.get_transport()
1424
1346
        bzrdir.BzrDir.create(self.get_url(),
1425
1347
            possible_transports=[self._transport])
1426
1348
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1427
1349
 
 
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')
 
1354
 
1428
1355
    def test_new(self):
1429
 
        self.assertEqual("a.~1~", self._bzrdir.generate_backup_name("a"))
 
1356
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1430
1357
 
1431
1358
    def test_exiting(self):
1432
1359
        self._transport.put_bytes("a.~1~", "some content")
1433
 
        self.assertEqual("a.~2~", self._bzrdir.generate_backup_name("a"))
 
1360
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
 
1361