~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Vincent Ladeuil
  • Date: 2011-01-27 15:58:36 UTC
  • mfrom: (5609.2.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5635.
  • Revision ID: v.ladeuil+lp@free.fr-20110127155836-hoyxs53z42jh3ezm
Merge 2.3 into trunk

Show diffs side-by-side

added added

removed removed

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