~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

Merge pt1 hooks branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
    help_topics,
32
32
    lock,
33
33
    repository,
 
34
    revision as _mod_revision,
34
35
    osutils,
35
36
    remote,
36
37
    symbol_versioning,
 
38
    transport as _mod_transport,
37
39
    urlutils,
38
40
    win32utils,
39
41
    workingtree,
56
58
    )
57
59
from bzrlib.tests.test_http import TestWithTransport_pycurl
58
60
from bzrlib.transport import (
59
 
    get_transport,
60
61
    memory,
61
62
    pathfilter,
62
63
    )
171
172
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
172
173
                          bzrdir.format_registry.get('default'))
173
174
            self.assertIs(
174
 
                repository.RepositoryFormat.get_default_format().__class__,
 
175
                repository.format_registry.get_default().__class__,
175
176
                knitrepo.RepositoryFormatKnit3)
176
177
        finally:
177
178
            bzrdir.format_registry.set_default_repository(old_default)
254
255
        # is the right format object found for a branch?
255
256
        # create a branch with a few known format objects.
256
257
        # this is not quite the same as
257
 
        t = get_transport(self.get_url())
 
258
        t = self.get_transport()
258
259
        self.build_tree(["foo/", "bar/"], transport=t)
259
260
        def check_format(format, url):
260
261
            format.initialize(url)
261
 
            t = get_transport(url)
 
262
            t = _mod_transport.get_transport(url)
262
263
            found_format = bzrdir.BzrDirFormat.find_format(t)
263
264
            self.failUnless(isinstance(found_format, format.__class__))
264
265
        check_format(bzrdir.BzrDirFormat5(), "foo")
267
268
    def test_find_format_nothing_there(self):
268
269
        self.assertRaises(NotBranchError,
269
270
                          bzrdir.BzrDirFormat.find_format,
270
 
                          get_transport('.'))
 
271
                          _mod_transport.get_transport('.'))
271
272
 
272
273
    def test_find_format_unknown_format(self):
273
 
        t = get_transport(self.get_url())
 
274
        t = self.get_transport()
274
275
        t.mkdir('.bzr')
275
276
        t.put_bytes('.bzr/branch-format', '')
276
277
        self.assertRaises(UnknownFormatError,
277
278
                          bzrdir.BzrDirFormat.find_format,
278
 
                          get_transport('.'))
 
279
                          _mod_transport.get_transport('.'))
279
280
 
280
281
    def test_register_unregister_format(self):
281
282
        format = SampleBzrDirFormat()
289
290
        # which bzrdir.open_containing will refuse (not supported)
290
291
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
291
292
        # but open_downlevel will work
292
 
        t = get_transport(url)
 
293
        t = _mod_transport.get_transport(url)
293
294
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
294
295
        # unregister the format
295
296
        bzrdir.BzrDirFormat.unregister_format(format)
681
682
        self.assertEqual(relpath, 'baz')
682
683
 
683
684
    def test_open_containing_from_transport(self):
684
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
685
 
                          get_transport(self.get_readonly_url('')))
686
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
687
 
                          get_transport(self.get_readonly_url('g/p/q')))
 
685
        self.assertRaises(NotBranchError,
 
686
            bzrdir.BzrDir.open_containing_from_transport,
 
687
            _mod_transport.get_transport(self.get_readonly_url('')))
 
688
        self.assertRaises(NotBranchError,
 
689
            bzrdir.BzrDir.open_containing_from_transport,
 
690
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
688
691
        control = bzrdir.BzrDir.create(self.get_url())
689
692
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
690
 
            get_transport(self.get_readonly_url('')))
 
693
            _mod_transport.get_transport(self.get_readonly_url('')))
691
694
        self.assertEqual('', relpath)
692
695
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
693
 
            get_transport(self.get_readonly_url('g/p/q')))
 
696
            _mod_transport.get_transport(self.get_readonly_url('g/p/q')))
694
697
        self.assertEqual('g/p/q', relpath)
695
698
 
696
699
    def test_open_containing_tree_or_branch(self):
740
743
        # transport pointing at bzrdir should give a bzrdir with root transport
741
744
        # set to the given transport
742
745
        control = bzrdir.BzrDir.create(self.get_url())
743
 
        transport = get_transport(self.get_url())
744
 
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
745
 
        self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
 
746
        t = self.get_transport()
 
747
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
 
748
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
746
749
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
747
750
 
748
751
    def test_open_from_transport_no_bzrdir(self):
749
 
        transport = get_transport(self.get_url())
750
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
751
 
                          transport)
 
752
        t = self.get_transport()
 
753
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
752
754
 
753
755
    def test_open_from_transport_bzrdir_in_parent(self):
754
756
        control = bzrdir.BzrDir.create(self.get_url())
755
 
        transport = get_transport(self.get_url())
756
 
        transport.mkdir('subdir')
757
 
        transport = transport.clone('subdir')
758
 
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
759
 
                          transport)
 
757
        t = self.get_transport()
 
758
        t.mkdir('subdir')
 
759
        t = t.clone('subdir')
 
760
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
760
761
 
761
762
    def test_sprout_recursive(self):
762
763
        tree = self.make_branch_and_tree('tree1',
822
823
 
823
824
    def test_find_bzrdirs(self):
824
825
        foo, bar, baz = self.make_foo_bar_baz()
825
 
        transport = get_transport(self.get_url())
826
 
        self.assertEqualBzrdirs([baz, foo, bar],
827
 
                                bzrdir.BzrDir.find_bzrdirs(transport))
 
826
        t = self.get_transport()
 
827
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
828
828
 
829
829
    def make_fake_permission_denied_transport(self, transport, paths):
830
830
        """Create a transport that raises PermissionDenied for some paths."""
846
846
 
847
847
    def test_find_bzrdirs_permission_denied(self):
848
848
        foo, bar, baz = self.make_foo_bar_baz()
849
 
        transport = get_transport(self.get_url())
 
849
        t = self.get_transport()
850
850
        path_filter_server, path_filter_transport = \
851
 
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
851
            self.make_fake_permission_denied_transport(t, ['foo'])
852
852
        # local transport
853
853
        self.assertBranchUrlsEndWith('/baz/',
854
854
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
863
863
            return [s for s in transport.list_dir('') if s != 'baz']
864
864
 
865
865
        foo, bar, baz = self.make_foo_bar_baz()
866
 
        transport = get_transport(self.get_url())
867
 
        self.assertEqualBzrdirs([foo, bar],
868
 
                                bzrdir.BzrDir.find_bzrdirs(transport,
869
 
                                    list_current=list_current))
 
866
        t = self.get_transport()
 
867
        self.assertEqualBzrdirs(
 
868
            [foo, bar],
 
869
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
870
870
 
871
871
    def test_find_bzrdirs_evaluate(self):
872
872
        def evaluate(bzrdir):
878
878
                return False, bzrdir.root_transport.base
879
879
 
880
880
        foo, bar, baz = self.make_foo_bar_baz()
881
 
        transport = get_transport(self.get_url())
 
881
        t = self.get_transport()
882
882
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
883
 
                         list(bzrdir.BzrDir.find_bzrdirs(transport,
884
 
                                                         evaluate=evaluate)))
 
883
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
885
884
 
886
885
    def assertEqualBzrdirs(self, first, second):
887
886
        first = list(first)
894
893
        root = self.make_repository('', shared=True)
895
894
        foo, bar, baz = self.make_foo_bar_baz()
896
895
        qux = self.make_bzrdir('foo/qux')
897
 
        transport = get_transport(self.get_url())
898
 
        branches = bzrdir.BzrDir.find_branches(transport)
 
896
        t = self.get_transport()
 
897
        branches = bzrdir.BzrDir.find_branches(t)
899
898
        self.assertEqual(baz.root_transport.base, branches[0].base)
900
899
        self.assertEqual(foo.root_transport.base, branches[1].base)
901
900
        self.assertEqual(bar.root_transport.base, branches[2].base)
902
901
 
903
902
        # ensure this works without a top-level repo
904
 
        branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
 
903
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
905
904
        self.assertEqual(foo.root_transport.base, branches[0].base)
906
905
        self.assertEqual(bar.root_transport.base, branches[1].base)
907
906
 
909
908
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
910
909
 
911
910
    def test_find_bzrdirs_missing_repo(self):
912
 
        transport = get_transport(self.get_url())
 
911
        t = self.get_transport()
913
912
        arepo = self.make_repository('arepo', shared=True)
914
913
        abranch_url = arepo.user_url + '/abranch'
915
914
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
916
 
        transport.delete_tree('arepo/.bzr')
 
915
        t.delete_tree('arepo/.bzr')
917
916
        self.assertRaises(errors.NoRepositoryPresent,
918
917
            branch.Branch.open, abranch_url)
919
918
        self.make_branch('baz')
920
 
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
 
919
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
921
920
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
922
921
 
923
922
 
1099
1098
        # now probe for it.
1100
1099
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1101
1100
        try:
1102
 
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
1103
 
                get_transport(self.get_url()))
 
1101
            found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1104
1102
            self.assertIsInstance(found, NotBzrDirFormat)
1105
1103
        finally:
1106
1104
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1142
1140
            self.get_url('foo'),
1143
1141
            force_new_tree=True,
1144
1142
            format=format)
1145
 
        t = get_transport(self.get_url('.'))
 
1143
        t = self.get_transport()
1146
1144
        self.assertFalse(t.has('foo'))
1147
1145
 
1148
1146
    def test_clone(self):
1344
1342
    def copy_content_into(self, destination, revision_id=None):
1345
1343
        self.calls.append('copy_content_into')
1346
1344
 
 
1345
    def last_revision(self):
 
1346
        return _mod_revision.NULL_REVISION
 
1347
 
1347
1348
    def get_parent(self):
1348
1349
        return self._parent
1349
1350
 
1445
1446
 
1446
1447
    def setUp(self):
1447
1448
        super(TestGenerateBackupName, self).setUp()
1448
 
        self._transport = get_transport(self.get_url())
 
1449
        self._transport = self.get_transport()
1449
1450
        bzrdir.BzrDir.create(self.get_url(),
1450
1451
            possible_transports=[self._transport])
1451
1452
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)