/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Zearin
  • Date: 2010-11-12 22:36:19 UTC
  • mto: (5570.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5572.
  • Revision ID: zearin@users.sourceforge.net-20101112223619-1i2oscfgg1xgzuqk
Continued capitalization fixes ([S]FTP, SSH).

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sys
25
25
 
26
26
from bzrlib import (
 
27
    branch,
27
28
    bzrdir,
 
29
    controldir,
28
30
    errors,
29
31
    help_topics,
30
32
    repository,
31
33
    osutils,
32
34
    remote,
 
35
    symbol_versioning,
33
36
    urlutils,
34
37
    win32utils,
35
38
    workingtree,
54
57
from bzrlib.transport import (
55
58
    get_transport,
56
59
    memory,
 
60
    pathfilter,
57
61
    )
58
62
from bzrlib.transport.http._urllib import HttpTransport_urllib
59
63
from bzrlib.transport.nosmart import NoSmartTransportDecorator
67
71
        old_format = bzrdir.BzrDirFormat.get_default_format()
68
72
        # default is BzrDirFormat6
69
73
        self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
70
 
        bzrdir.BzrDirFormat._set_default_format(SampleBzrDirFormat())
 
74
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
71
75
        # creating a bzr dir should now create an instrumented dir.
72
76
        try:
73
77
            result = bzrdir.BzrDir.create('memory:///')
74
78
            self.failUnless(isinstance(result, SampleBzrDir))
75
79
        finally:
76
 
            bzrdir.BzrDirFormat._set_default_format(old_format)
 
80
            controldir.ControlDirFormat._set_default_format(old_format)
77
81
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
78
82
 
79
83
 
80
84
class TestFormatRegistry(TestCase):
81
85
 
82
86
    def make_format_registry(self):
83
 
        my_format_registry = bzrdir.BzrDirFormatRegistry()
 
87
        my_format_registry = controldir.ControlDirFormatRegistry()
84
88
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
85
89
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
86
90
            ' repositories', deprecated=True)
87
91
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
88
92
            'BzrDirFormat6', 'Format registered lazily', deprecated=True)
89
 
        my_format_registry.register_metadir('knit',
 
93
        bzrdir.register_metadir(my_format_registry, 'knit',
90
94
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
91
95
            'Format using knits',
92
96
            )
93
97
        my_format_registry.set_default('knit')
94
 
        my_format_registry.register_metadir(
 
98
        bzrdir.register_metadir(my_format_registry,
95
99
            'branch6',
96
100
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
97
101
            'Experimental successor to knit.  Use at your own risk.',
98
102
            branch_format='bzrlib.branch.BzrBranchFormat6',
99
103
            experimental=True)
100
 
        my_format_registry.register_metadir(
 
104
        bzrdir.register_metadir(my_format_registry,
101
105
            'hidden format',
102
106
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
103
107
            'Experimental successor to knit.  Use at your own risk.',
172
176
            bzrdir.format_registry.set_default_repository(old_default)
173
177
 
174
178
    def test_aliases(self):
175
 
        a_registry = bzrdir.BzrDirFormatRegistry()
 
179
        a_registry = controldir.ControlDirFormatRegistry()
176
180
        a_registry.register('weave', bzrdir.BzrDirFormat6,
177
181
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
178
182
            ' repositories', deprecated=True)
787
791
        self.build_tree(['tree1/subtree/file'])
788
792
        sub_tree.add('file')
789
793
        tree.commit('Initial commit')
 
794
        # The following line force the orhaning to reveal bug #634470
 
795
        tree.branch.get_config().set_user_option(
 
796
            'bzr.transform.orphan_policy', 'move')
790
797
        tree.bzrdir.destroy_workingtree()
 
798
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
 
799
        # fail :-( ) -- vila 20100909
791
800
        repo = self.make_repository('repo', shared=True,
792
801
            format='dirstate-with-subtree')
793
802
        repo.set_make_working_trees(False)
794
 
        tree.bzrdir.sprout('repo/tree2')
795
 
        self.failUnlessExists('repo/tree2/subtree')
796
 
        self.failIfExists('repo/tree2/subtree/file')
 
803
        # FIXME: we just deleted the workingtree and now we want to use it ????
 
804
        # At a minimum, we should use tree.branch below (but this fails too
 
805
        # currently) or stop calling this test 'treeless'. Specifically, I've
 
806
        # turn the line below into an assertRaises when 'subtree/.bzr' is
 
807
        # orphaned and sprout tries to access the branch there (which is left
 
808
        # by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
 
809
        # [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
 
810
        # #634470.  -- vila 20100909
 
811
        self.assertRaises(errors.NotBranchError,
 
812
                          tree.bzrdir.sprout, 'repo/tree2')
 
813
#        self.failUnlessExists('repo/tree2/subtree')
 
814
#        self.failIfExists('repo/tree2/subtree/file')
797
815
 
798
816
    def make_foo_bar_baz(self):
799
817
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
807
825
        self.assertEqualBzrdirs([baz, foo, bar],
808
826
                                bzrdir.BzrDir.find_bzrdirs(transport))
809
827
 
 
828
    def make_fake_permission_denied_transport(self, transport, paths):
 
829
        """Create a transport that raises PermissionDenied for some paths."""
 
830
        def filter(path):
 
831
            if path in paths:
 
832
                raise errors.PermissionDenied(path)
 
833
            return path
 
834
        path_filter_server = pathfilter.PathFilteringServer(transport, filter)
 
835
        path_filter_server.start_server()
 
836
        self.addCleanup(path_filter_server.stop_server)
 
837
        path_filter_transport = pathfilter.PathFilteringTransport(
 
838
            path_filter_server, '.')
 
839
        return (path_filter_server, path_filter_transport)
 
840
 
 
841
    def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
 
842
        """Check that each branch url ends with the given suffix."""
 
843
        for actual_bzrdir in actual_bzrdirs:
 
844
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
 
845
 
 
846
    def test_find_bzrdirs_permission_denied(self):
 
847
        foo, bar, baz = self.make_foo_bar_baz()
 
848
        transport = get_transport(self.get_url())
 
849
        path_filter_server, path_filter_transport = \
 
850
            self.make_fake_permission_denied_transport(transport, ['foo'])
 
851
        # local transport
 
852
        self.assertBranchUrlsEndWith('/baz/',
 
853
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
 
854
        # smart server
 
855
        smart_transport = self.make_smart_server('.',
 
856
            backing_server=path_filter_server)
 
857
        self.assertBranchUrlsEndWith('/baz/',
 
858
            bzrdir.BzrDir.find_bzrdirs(smart_transport))
 
859
 
810
860
    def test_find_bzrdirs_list_current(self):
811
861
        def list_current(transport):
812
862
            return [s for s in transport.list_dir('') if s != 'baz']
817
867
                                bzrdir.BzrDir.find_bzrdirs(transport,
818
868
                                    list_current=list_current))
819
869
 
820
 
 
821
870
    def test_find_bzrdirs_evaluate(self):
822
871
        def evaluate(bzrdir):
823
872
            try:
856
905
        self.assertEqual(bar.root_transport.base, branches[1].base)
857
906
 
858
907
 
 
908
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
 
909
 
 
910
    def test_find_bzrdirs_missing_repo(self):
 
911
        transport = get_transport(self.get_url())
 
912
        arepo = self.make_repository('arepo', shared=True)
 
913
        abranch_url = arepo.user_url + '/abranch'
 
914
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
 
915
        transport.delete_tree('arepo/.bzr')
 
916
        self.assertRaises(errors.NoRepositoryPresent,
 
917
            branch.Branch.open, abranch_url)
 
918
        self.make_branch('baz')
 
919
        for actual_bzrdir in bzrdir.BzrDir.find_branches(transport):
 
920
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
 
921
 
 
922
 
859
923
class TestMeta1DirFormat(TestCaseWithTransport):
860
924
    """Tests specific to the meta1 dir format."""
861
925
 
1010
1074
    def _known_formats(self):
1011
1075
        return set([NotBzrDirFormat()])
1012
1076
 
1013
 
    @classmethod
 
1077
 
 
1078
class NotBzrDirProber(controldir.Prober):
 
1079
 
1014
1080
    def probe_transport(self, transport):
1015
1081
        """Our format is present if the transport ends in '.not/'."""
1016
1082
        if transport.has('.not'):
1030
1096
        dir = format.initialize(self.get_url())
1031
1097
        self.assertIsInstance(dir, NotBzrDir)
1032
1098
        # now probe for it.
1033
 
        bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
 
1099
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1034
1100
        try:
1035
1101
            found = bzrlib.bzrdir.BzrDirFormat.find_format(
1036
1102
                get_transport(self.get_url()))
1037
1103
            self.assertIsInstance(found, NotBzrDirFormat)
1038
1104
        finally:
1039
 
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
 
1105
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1040
1106
 
1041
1107
    def test_included_in_known_formats(self):
1042
 
        bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
 
1108
        not_format = NotBzrDirFormat()
 
1109
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
1043
1110
        try:
1044
1111
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1045
1112
            for format in formats:
1047
1114
                    return
1048
1115
            self.fail("No NotBzrDirFormat in %s" % formats)
1049
1116
        finally:
1050
 
            bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
 
1117
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1051
1118
 
1052
1119
 
1053
1120
class NonLocalTests(TestCaseWithTransport):
1111
1178
    """
1112
1179
 
1113
1180
    def create_transport_readonly_server(self):
 
1181
        # We don't set the http protocol version, relying on the default
1114
1182
        return http_utils.HTTPServerRedirecting()
1115
1183
 
1116
1184
    def create_transport_secondary_server(self):
 
1185
        # We don't set the http protocol version, relying on the default
1117
1186
        return http_utils.HTTPServerRedirecting()
1118
1187
 
1119
1188
    def setUp(self):
1351
1420
        self.assertIsInstance(params, RepoInitHookParams)
1352
1421
        self.assertTrue(hasattr(params, 'bzrdir'))
1353
1422
        self.assertTrue(hasattr(params, 'repository'))
 
1423
 
 
1424
    def test_post_repo_init_hook_repr(self):
 
1425
        param_reprs = []
 
1426
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
 
1427
            lambda params: param_reprs.append(repr(params)), None)
 
1428
        self.make_repository('foo')
 
1429
        self.assertLength(1, param_reprs)
 
1430
        param_repr = param_reprs[0]
 
1431
        self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
 
1432
 
 
1433
 
 
1434
class TestGenerateBackupName(TestCaseWithMemoryTransport):
 
1435
    # FIXME: This may need to be unified with test_osutils.TestBackupNames or
 
1436
    # moved to per_bzrdir or per_transport for better coverage ?
 
1437
    # -- vila 20100909
 
1438
 
 
1439
    def setUp(self):
 
1440
        super(TestGenerateBackupName, self).setUp()
 
1441
        self._transport = get_transport(self.get_url())
 
1442
        bzrdir.BzrDir.create(self.get_url(),
 
1443
            possible_transports=[self._transport])
 
1444
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
 
1445
 
 
1446
    def test_deprecated_generate_backup_name(self):
 
1447
        res = self.applyDeprecated(
 
1448
                symbol_versioning.deprecated_in((2, 3, 0)),
 
1449
                self._bzrdir.generate_backup_name, 'whatever')
 
1450
 
 
1451
    def test_new(self):
 
1452
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
 
1453
 
 
1454
    def test_exiting(self):
 
1455
        self._transport.put_bytes("a.~1~", "some content")
 
1456
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))