~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2011-01-19 22:36:40 UTC
  • mto: This revision was merged to the branch mainline in revision 5626.
  • Revision ID: jelmer@samba.org-20110119223640-mugs4t1nbl55tf7c
fix import.

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