/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: Vincent Ladeuil
  • Date: 2011-07-06 09:22:00 UTC
  • mfrom: (6008 +trunk)
  • mto: (6012.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6013.
  • Revision ID: v.ladeuil+lp@free.fr-20110706092200-7iai2mwzc0sqdsvf
MergingĀ inĀ trunk

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,
37
38
    transport as _mod_transport,
38
39
    urlutils,
39
40
    win32utils,
40
 
    workingtree,
 
41
    workingtree_3,
 
42
    workingtree_4,
41
43
    )
42
44
import bzrlib.branch
43
 
from bzrlib.errors import (NotBranchError,
44
 
                           NoColocatedBranchSupport,
45
 
                           UnknownFormatError,
46
 
                           UnsupportedFormatError,
47
 
                           )
 
45
from bzrlib.errors import (
 
46
    NotBranchError,
 
47
    NoColocatedBranchSupport,
 
48
    UnknownFormatError,
 
49
    UnsupportedFormatError,
 
50
    )
48
51
from bzrlib.tests import (
49
52
    TestCase,
50
53
    TestCaseWithMemoryTransport,
63
66
from bzrlib.transport.http._urllib import HttpTransport_urllib
64
67
from bzrlib.transport.nosmart import NoSmartTransportDecorator
65
68
from bzrlib.transport.readonly import ReadonlyTransportDecorator
66
 
from bzrlib.repofmt import knitrepo, weaverepo, pack_repo
 
69
from bzrlib.repofmt import knitrepo, knitpack_repo
67
70
 
68
71
 
69
72
class TestDefaultFormat(TestCase):
70
73
 
71
74
    def test_get_set_default_format(self):
72
75
        old_format = bzrdir.BzrDirFormat.get_default_format()
 
76
        # default is BzrDirMetaFormat1
73
77
        self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
74
78
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
75
79
        # creating a bzr dir should now create an instrumented dir.
81
85
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
82
86
 
83
87
 
 
88
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
 
89
    """A deprecated bzr dir format."""
 
90
 
 
91
 
84
92
class TestFormatRegistry(TestCase):
85
93
 
86
94
    def make_format_registry(self):
87
95
        my_format_registry = controldir.ControlDirFormatRegistry()
88
 
        my_format_registry.register('weave', bzrdir.BzrDirFormat6,
89
 
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
90
 
            ' repositories', deprecated=True)
91
 
        my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
92
 
            '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)
93
102
        bzrdir.register_metadir(my_format_registry, 'knit',
94
103
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit1',
95
104
            'Format using knits',
106
115
            'bzrlib.repofmt.knitrepo.RepositoryFormatKnit3',
107
116
            'Experimental successor to knit.  Use at your own risk.',
108
117
            branch_format='bzrlib.branch.BzrBranchFormat6', hidden=True)
109
 
        my_format_registry.register('hiddenweave', bzrdir.BzrDirFormat6,
110
 
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
111
 
            ' repositories', hidden=True)
112
 
        my_format_registry.register_lazy('hiddenlazy', 'bzrlib.bzrdir',
113
 
            'BzrDirFormat6', 'Format registered lazily', deprecated=True,
114
 
            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)
115
123
        return my_format_registry
116
124
 
117
125
    def test_format_registry(self):
118
126
        my_format_registry = self.make_format_registry()
119
127
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
120
 
        self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
121
 
        my_bzrdir = my_format_registry.make_bzrdir('weave')
122
 
        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)
123
131
        my_bzrdir = my_format_registry.make_bzrdir('default')
124
132
        self.assertIsInstance(my_bzrdir.repository_format,
125
133
            knitrepo.RepositoryFormatKnit1)
138
146
                         my_format_registry.get_help('knit'))
139
147
        self.assertEqual('Format using knits',
140
148
                         my_format_registry.get_help('default'))
141
 
        self.assertEqual('Pre-0.8 format.  Slower and does not support'
142
 
                         ' checkouts or shared repositories',
143
 
                         my_format_registry.get_help('weave'))
 
149
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
 
150
                         my_format_registry.get_help('deprecated'))
144
151
 
145
152
    def test_help_topic(self):
146
153
        topics = help_topics.HelpTopicRegistry()
170
177
            self.assertIs(bzrdir.format_registry.get('dirstate-with-subtree'),
171
178
                          bzrdir.format_registry.get('default'))
172
179
            self.assertIs(
173
 
                repository.RepositoryFormat.get_default_format().__class__,
 
180
                repository.format_registry.get_default().__class__,
174
181
                knitrepo.RepositoryFormatKnit3)
175
182
        finally:
176
183
            bzrdir.format_registry.set_default_repository(old_default)
177
184
 
178
185
    def test_aliases(self):
179
186
        a_registry = controldir.ControlDirFormatRegistry()
180
 
        a_registry.register('weave', bzrdir.BzrDirFormat6,
181
 
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
182
 
            ' repositories', deprecated=True)
183
 
        a_registry.register('weavealias', bzrdir.BzrDirFormat6,
184
 
            'Pre-0.8 format.  Slower and does not support checkouts or shared'
185
 
            ' repositories', deprecated=True, alias=True)
186
 
        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())
187
194
 
188
195
 
189
196
class SampleBranch(bzrlib.branch.Branch):
246
253
        return "opened branch."
247
254
 
248
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
 
249
270
class TestBzrDirFormat(TestCaseWithTransport):
250
271
    """Tests for the BzrDirFormat facility."""
251
272
 
252
273
    def test_find_format(self):
253
274
        # is the right format object found for a branch?
254
275
        # create a branch with a few known format objects.
255
 
        # this is not quite the same as
 
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())
256
284
        t = self.get_transport()
257
285
        self.build_tree(["foo/", "bar/"], transport=t)
258
286
        def check_format(format, url):
260
288
            t = _mod_transport.get_transport(url)
261
289
            found_format = bzrdir.BzrDirFormat.find_format(t)
262
290
            self.assertIsInstance(found_format, format.__class__)
263
 
        check_format(bzrdir.BzrDirFormat5(), "foo")
264
 
        check_format(bzrdir.BzrDirFormat6(), "bar")
 
291
        check_format(BzrDirFormatTest1(), "foo")
 
292
        check_format(BzrDirFormatTest2(), "bar")
265
293
 
266
294
    def test_find_format_nothing_there(self):
267
295
        self.assertRaises(NotBranchError,
282
310
        # make a bzrdir
283
311
        format.initialize(url)
284
312
        # register a format for it.
285
 
        bzrdir.BzrDirFormat.register_format(format)
 
313
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
286
314
        # which bzrdir.Open will refuse (not supported)
287
315
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
288
316
        # which bzrdir.open_containing will refuse (not supported)
291
319
        t = _mod_transport.get_transport(url)
292
320
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
293
321
        # unregister the format
294
 
        bzrdir.BzrDirFormat.unregister_format(format)
 
322
        bzrdir.BzrProber.formats.remove(format.get_format_string())
295
323
        # now open_downlevel should fail too.
296
324
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
297
325
 
474
502
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
475
503
        # Make stackable source branch with an unstackable repo format.
476
504
        source_bzrdir = self.make_bzrdir('source')
477
 
        pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
 
505
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
478
506
        source_branch = bzrlib.branch.BzrBranchFormat7().initialize(
479
507
            source_bzrdir)
480
508
        # Make a directory with a default stacking policy
780
808
        branch = self.make_branch('branch', format='knit')
781
809
        format = branch.bzrdir.cloning_metadir()
782
810
        self.assertIsInstance(format.workingtree_format,
783
 
            workingtree.WorkingTreeFormat3)
 
811
            workingtree_4.WorkingTreeFormat6)
784
812
 
785
813
    def test_sprout_recursive_treeless(self):
786
814
        tree = self.make_branch_and_tree('tree1',
930
958
                         dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
931
959
        repository_base = t.clone('repository').base
932
960
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
 
961
        repository_format = repository.format_registry.get_default()
933
962
        self.assertEqual(repository_base,
934
 
                         dir.get_repository_transport(weaverepo.RepositoryFormat7()).base)
 
963
                         dir.get_repository_transport(repository_format).base)
935
964
        checkout_base = t.clone('checkout').base
936
965
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
937
966
        self.assertEqual(checkout_base,
938
 
                         dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
 
967
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
939
968
 
940
969
    def test_meta1dir_uses_lockdir(self):
941
970
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
983
1012
        self.assertEqual(2, rpc_count)
984
1013
 
985
1014
 
986
 
class TestFormat5(TestCaseWithTransport):
987
 
    """Tests specific to the version 5 bzrdir format."""
988
 
 
989
 
    def test_same_lockfiles_between_tree_repo_branch(self):
990
 
        # this checks that only a single lockfiles instance is created
991
 
        # for format 5 objects
992
 
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
993
 
        def check_dir_components_use_same_lock(dir):
994
 
            ctrl_1 = dir.open_repository().control_files
995
 
            ctrl_2 = dir.open_branch().control_files
996
 
            ctrl_3 = dir.open_workingtree()._control_files
997
 
            self.assertTrue(ctrl_1 is ctrl_2)
998
 
            self.assertTrue(ctrl_2 is ctrl_3)
999
 
        check_dir_components_use_same_lock(dir)
1000
 
        # and if we open it normally.
1001
 
        dir = bzrdir.BzrDir.open(self.get_url())
1002
 
        check_dir_components_use_same_lock(dir)
1003
 
 
1004
 
    def test_can_convert(self):
1005
 
        # format 5 dirs are convertable
1006
 
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1007
 
        self.assertTrue(dir.can_convert_format())
1008
 
 
1009
 
    def test_needs_conversion(self):
1010
 
        # format 5 dirs need a conversion if they are not the default,
1011
 
        # and they aren't
1012
 
        dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
1013
 
        # don't need to convert it to itself
1014
 
        self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
1015
 
        # do need to convert it to the current default
1016
 
        self.assertTrue(dir.needs_format_conversion(
1017
 
            bzrdir.BzrDirFormat.get_default_format()))
1018
 
 
1019
 
 
1020
 
class TestFormat6(TestCaseWithTransport):
1021
 
    """Tests specific to the version 6 bzrdir format."""
1022
 
 
1023
 
    def test_same_lockfiles_between_tree_repo_branch(self):
1024
 
        # this checks that only a single lockfiles instance is created
1025
 
        # for format 6 objects
1026
 
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1027
 
        def check_dir_components_use_same_lock(dir):
1028
 
            ctrl_1 = dir.open_repository().control_files
1029
 
            ctrl_2 = dir.open_branch().control_files
1030
 
            ctrl_3 = dir.open_workingtree()._control_files
1031
 
            self.assertTrue(ctrl_1 is ctrl_2)
1032
 
            self.assertTrue(ctrl_2 is ctrl_3)
1033
 
        check_dir_components_use_same_lock(dir)
1034
 
        # and if we open it normally.
1035
 
        dir = bzrdir.BzrDir.open(self.get_url())
1036
 
        check_dir_components_use_same_lock(dir)
1037
 
 
1038
 
    def test_can_convert(self):
1039
 
        # format 6 dirs are convertable
1040
 
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1041
 
        self.assertTrue(dir.can_convert_format())
1042
 
 
1043
 
    def test_needs_conversion(self):
1044
 
        # format 6 dirs need an conversion if they are not the default.
1045
 
        dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
1046
 
        self.assertTrue(dir.needs_format_conversion(
1047
 
            bzrdir.BzrDirFormat.get_default_format()))
1048
 
 
1049
 
 
1050
 
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1051
 
    """A non .bzr based control directory."""
1052
 
 
1053
 
    def __init__(self, transport, format):
1054
 
        self._format = format
1055
 
        self.root_transport = transport
1056
 
        self.transport = transport.clone('.not')
1057
 
 
1058
 
 
1059
 
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
1060
 
    """A test class representing any non-.bzr based disk format."""
1061
 
 
1062
 
    def initialize_on_transport(self, transport):
1063
 
        """Initialize a new .not dir in the base directory of a Transport."""
1064
 
        transport.mkdir('.not')
1065
 
        return self.open(transport)
1066
 
 
1067
 
    def open(self, transport):
1068
 
        """Open this directory."""
1069
 
        return NotBzrDir(transport, self)
1070
 
 
1071
 
    @classmethod
1072
 
    def _known_formats(self):
1073
 
        return set([NotBzrDirFormat()])
1074
 
 
1075
 
 
1076
 
class NotBzrDirProber(controldir.Prober):
1077
 
 
1078
 
    def probe_transport(self, transport):
1079
 
        """Our format is present if the transport ends in '.not/'."""
1080
 
        if transport.has('.not'):
1081
 
            return NotBzrDirFormat()
1082
 
 
1083
 
 
1084
 
class TestNotBzrDir(TestCaseWithTransport):
1085
 
    """Tests for using the bzrdir api with a non .bzr based disk format.
1086
 
 
1087
 
    If/when one of these is in the core, we can let the implementation tests
1088
 
    verify this works.
1089
 
    """
1090
 
 
1091
 
    def test_create_and_find_format(self):
1092
 
        # create a .notbzr dir
1093
 
        format = NotBzrDirFormat()
1094
 
        dir = format.initialize(self.get_url())
1095
 
        self.assertIsInstance(dir, NotBzrDir)
1096
 
        # now probe for it.
1097
 
        controldir.ControlDirFormat.register_prober(NotBzrDirProber)
1098
 
        try:
1099
 
            found = bzrlib.bzrdir.BzrDirFormat.find_format(self.get_transport())
1100
 
            self.assertIsInstance(found, NotBzrDirFormat)
1101
 
        finally:
1102
 
            controldir.ControlDirFormat.unregister_prober(NotBzrDirProber)
1103
 
 
1104
 
    def test_included_in_known_formats(self):
1105
 
        not_format = NotBzrDirFormat()
1106
 
        bzrlib.controldir.ControlDirFormat.register_format(not_format)
1107
 
        try:
1108
 
            formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
1109
 
            for format in formats:
1110
 
                if isinstance(format, NotBzrDirFormat):
1111
 
                    return
1112
 
            self.fail("No NotBzrDirFormat in %s" % formats)
1113
 
        finally:
1114
 
            bzrlib.controldir.ControlDirFormat.unregister_format(not_format)
1115
 
 
1116
 
 
1117
1015
class NonLocalTests(TestCaseWithTransport):
1118
1016
    """Tests for bzrdir static behaviour on non local paths."""
1119
1017
 
1160
1058
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1161
1059
        checkout_format = my_bzrdir.checkout_metadir()
1162
1060
        self.assertIsInstance(checkout_format.workingtree_format,
1163
 
                              workingtree.WorkingTreeFormat3)
 
1061
                              workingtree_4.WorkingTreeFormat4)
1164
1062
 
1165
1063
 
1166
1064
class TestHTTPRedirections(object):
1340
1238
    def copy_content_into(self, destination, revision_id=None):
1341
1239
        self.calls.append('copy_content_into')
1342
1240
 
 
1241
    def last_revision(self):
 
1242
        return _mod_revision.NULL_REVISION
 
1243
 
1343
1244
    def get_parent(self):
1344
1245
        return self._parent
1345
1246
 
1457
1358
    def test_exiting(self):
1458
1359
        self._transport.put_bytes("a.~1~", "some content")
1459
1360
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
 
1361