/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 brzlib/tests/test_bzrdir.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import subprocess
24
24
import sys
25
25
 
26
 
from .. import (
 
26
from brzlib import (
27
27
    branch,
28
 
    bzr,
 
28
    bzrdir,
29
29
    config,
30
30
    controldir,
31
31
    errors,
34
34
    repository,
35
35
    revision as _mod_revision,
36
36
    osutils,
 
37
    remote,
37
38
    transport as _mod_transport,
38
39
    urlutils,
39
40
    win32utils,
40
 
    )
41
 
from ..bzr import (
42
 
    branch as bzrbranch,
43
 
    bzrdir,
44
 
    remote,
45
41
    workingtree_3,
46
42
    workingtree_4,
47
43
    )
48
 
import breezy.branch
49
 
import breezy.bzr.branch
50
 
from ..bzr.fullhistory import BzrBranchFormat5
51
 
from ..errors import (
 
44
import brzlib.branch
 
45
from brzlib.branchfmt.fullhistory import BzrBranchFormat5
 
46
from brzlib.errors import (
52
47
    NotBranchError,
53
48
    NoColocatedBranchSupport,
54
49
    UnknownFormatError,
55
50
    UnsupportedFormatError,
56
51
    )
57
 
from . import (
 
52
from brzlib.tests import (
58
53
    TestCase,
59
54
    TestCaseWithMemoryTransport,
60
55
    TestCaseWithTransport,
61
56
    TestSkipped,
62
57
    )
63
 
from . import (
 
58
from brzlib.tests import(
64
59
    http_server,
65
60
    http_utils,
66
61
    )
67
 
from ..transport import (
 
62
from brzlib.tests.test_http import TestWithTransport_pycurl
 
63
from brzlib.transport import (
68
64
    memory,
69
65
    pathfilter,
70
66
    )
71
 
from ..transport.http import HttpTransport
72
 
from ..transport.nosmart import NoSmartTransportDecorator
73
 
from ..transport.readonly import ReadonlyTransportDecorator
74
 
from ..bzr import knitrepo, knitpack_repo
 
67
from brzlib.transport.http._urllib import HttpTransport_urllib
 
68
from brzlib.transport.nosmart import NoSmartTransportDecorator
 
69
from brzlib.transport.readonly import ReadonlyTransportDecorator
 
70
from brzlib.repofmt import knitrepo, knitpack_repo
75
71
 
76
72
 
77
73
class TestDefaultFormat(TestCase):
99
95
    def make_format_registry(self):
100
96
        my_format_registry = controldir.ControlDirFormatRegistry()
101
97
        my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
102
 
                                    'Some format.  Slower and unawesome and deprecated.',
103
 
                                    deprecated=True)
104
 
        my_format_registry.register_lazy('lazy', 'breezy.tests.test_bzrdir',
105
 
                                         'DeprecatedBzrDirFormat', 'Format registered lazily',
106
 
                                         deprecated=True)
107
 
        bzr.register_metadir(my_format_registry, 'knit',
108
 
                             'breezy.bzr.knitrepo.RepositoryFormatKnit1',
109
 
                             'Format using knits',
110
 
                             )
 
98
            'Some format.  Slower and unawesome and deprecated.',
 
99
            deprecated=True)
 
100
        my_format_registry.register_lazy('lazy', 'brzlib.tests.test_bzrdir',
 
101
            'DeprecatedBzrDirFormat', 'Format registered lazily',
 
102
            deprecated=True)
 
103
        bzrdir.register_metadir(my_format_registry, 'knit',
 
104
            'brzlib.repofmt.knitrepo.RepositoryFormatKnit1',
 
105
            'Format using knits',
 
106
            )
111
107
        my_format_registry.set_default('knit')
112
 
        bzr.register_metadir(my_format_registry,
113
 
                             'branch6',
114
 
                             'breezy.bzr.knitrepo.RepositoryFormatKnit3',
115
 
                             'Experimental successor to knit.  Use at your own risk.',
116
 
                             branch_format='breezy.bzr.branch.BzrBranchFormat6',
117
 
                             experimental=True)
118
 
        bzr.register_metadir(my_format_registry,
119
 
                             'hidden format',
120
 
                             'breezy.bzr.knitrepo.RepositoryFormatKnit3',
121
 
                             'Experimental successor to knit.  Use at your own risk.',
122
 
                             branch_format='breezy.bzr.branch.BzrBranchFormat6', hidden=True)
 
108
        bzrdir.register_metadir(my_format_registry,
 
109
            'branch6',
 
110
            'brzlib.repofmt.knitrepo.RepositoryFormatKnit3',
 
111
            'Experimental successor to knit.  Use at your own risk.',
 
112
            branch_format='brzlib.branch.BzrBranchFormat6',
 
113
            experimental=True)
 
114
        bzrdir.register_metadir(my_format_registry,
 
115
            'hidden format',
 
116
            'brzlib.repofmt.knitrepo.RepositoryFormatKnit3',
 
117
            'Experimental successor to knit.  Use at your own risk.',
 
118
            branch_format='brzlib.branch.BzrBranchFormat6', hidden=True)
123
119
        my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
124
 
                                    'Old format.  Slower and does not support things. ', hidden=True)
125
 
        my_format_registry.register_lazy('hiddenlazy', 'breezy.tests.test_bzrdir',
126
 
                                         'DeprecatedBzrDirFormat', 'Format registered lazily',
127
 
                                         deprecated=True, hidden=True)
 
120
            'Old format.  Slower and does not support things. ', hidden=True)
 
121
        my_format_registry.register_lazy('hiddenlazy', 'brzlib.tests.test_bzrdir',
 
122
            'DeprecatedBzrDirFormat', 'Format registered lazily',
 
123
            deprecated=True, hidden=True)
128
124
        return my_format_registry
129
125
 
130
126
    def test_format_registry(self):
131
127
        my_format_registry = self.make_format_registry()
132
 
        my_bzrdir = my_format_registry.make_controldir('lazy')
133
 
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
134
 
        my_bzrdir = my_format_registry.make_controldir('deprecated')
135
 
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
136
 
        my_bzrdir = my_format_registry.make_controldir('default')
137
 
        self.assertIsInstance(my_bzrdir.repository_format,
138
 
                              knitrepo.RepositoryFormatKnit1)
139
 
        my_bzrdir = my_format_registry.make_controldir('knit')
140
 
        self.assertIsInstance(my_bzrdir.repository_format,
141
 
                              knitrepo.RepositoryFormatKnit1)
142
 
        my_bzrdir = my_format_registry.make_controldir('branch6')
 
128
        my_bzrdir = my_format_registry.make_bzrdir('lazy')
 
129
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
 
130
        my_bzrdir = my_format_registry.make_bzrdir('deprecated')
 
131
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
 
132
        my_bzrdir = my_format_registry.make_bzrdir('default')
 
133
        self.assertIsInstance(my_bzrdir.repository_format,
 
134
            knitrepo.RepositoryFormatKnit1)
 
135
        my_bzrdir = my_format_registry.make_bzrdir('knit')
 
136
        self.assertIsInstance(my_bzrdir.repository_format,
 
137
            knitrepo.RepositoryFormatKnit1)
 
138
        my_bzrdir = my_format_registry.make_bzrdir('branch6')
143
139
        self.assertIsInstance(my_bzrdir.get_branch_format(),
144
 
                              breezy.bzr.branch.BzrBranchFormat6)
 
140
                              brzlib.branch.BzrBranchFormat6)
145
141
 
146
142
    def test_get_help(self):
147
143
        my_format_registry = self.make_format_registry()
166
162
        experimental, deprecated = rest.split('Deprecated formats')
167
163
        self.assertContainsRe(new, 'formats-help')
168
164
        self.assertContainsRe(new,
169
 
                              ':knit:\n    \\(native\\) \\(default\\) Format using knits\n')
 
165
                ':knit:\n    \(native\) \(default\) Format using knits\n')
170
166
        self.assertContainsRe(experimental,
171
 
                              ':branch6:\n    \\(native\\) Experimental successor to knit')
 
167
                ':branch6:\n    \(native\) Experimental successor to knit')
172
168
        self.assertContainsRe(deprecated,
173
 
                              ':lazy:\n    \\(native\\) Format registered lazily\n')
 
169
                ':lazy:\n    \(native\) Format registered lazily\n')
174
170
        self.assertNotContainsRe(new, 'hidden')
175
171
 
176
172
    def test_set_default_repository(self):
177
173
        default_factory = controldir.format_registry.get('default')
178
174
        old_default = [k for k, v in controldir.format_registry.iteritems()
179
175
                       if v == default_factory and k != 'default'][0]
180
 
        controldir.format_registry.set_default_repository(
181
 
            'dirstate-with-subtree')
 
176
        controldir.format_registry.set_default_repository('dirstate-with-subtree')
182
177
        try:
183
178
            self.assertIs(controldir.format_registry.get('dirstate-with-subtree'),
184
179
                          controldir.format_registry.get('default'))
191
186
    def test_aliases(self):
192
187
        a_registry = controldir.ControlDirFormatRegistry()
193
188
        a_registry.register('deprecated', DeprecatedBzrDirFormat,
194
 
                            'Old format.  Slower and does not support stuff',
195
 
                            deprecated=True)
196
 
        a_registry.register_alias('deprecatedalias', 'deprecated')
197
 
        self.assertEqual({'deprecatedalias': 'deprecated'},
198
 
                         a_registry.aliases())
199
 
 
200
 
 
201
 
class SampleBranch(breezy.branch.Branch):
 
189
            'Old format.  Slower and does not support stuff',
 
190
            deprecated=True)
 
191
        a_registry.register('deprecatedalias', DeprecatedBzrDirFormat,
 
192
            'Old format.  Slower and does not support stuff',
 
193
            deprecated=True, alias=True)
 
194
        self.assertEqual(frozenset(['deprecatedalias']), a_registry.aliases())
 
195
 
 
196
 
 
197
class SampleBranch(brzlib.branch.Branch):
202
198
    """A dummy branch for guess what, dummy use."""
203
199
 
204
200
    def __init__(self, dir):
205
 
        self.controldir = dir
206
 
 
207
 
 
208
 
class SampleRepository(breezy.repository.Repository):
 
201
        self.bzrdir = dir
 
202
 
 
203
 
 
204
class SampleRepository(brzlib.repository.Repository):
209
205
    """A dummy repo."""
210
206
 
211
207
    def __init__(self, dir):
212
 
        self.controldir = dir
 
208
        self.bzrdir = dir
213
209
 
214
210
 
215
211
class SampleBzrDir(bzrdir.BzrDir):
243
239
 
244
240
    def get_format_string(self):
245
241
        """See BzrDirFormat.get_format_string()."""
246
 
        return b"Sample .bzr dir format."
 
242
        return "Sample .bzr dir format."
247
243
 
248
244
    def initialize_on_transport(self, t):
249
245
        """Create a bzr dir."""
266
262
 
267
263
    @staticmethod
268
264
    def get_format_string():
269
 
        return b"Test format 1"
 
265
        return "Test format 1"
270
266
 
271
267
 
272
268
class BzrDirFormatTest2(bzrdir.BzrDirMetaFormat1):
273
269
 
274
270
    @staticmethod
275
271
    def get_format_string():
276
 
        return b"Test format 2"
 
272
        return "Test format 2"
277
273
 
278
274
 
279
275
class TestBzrDirFormat(TestCaseWithTransport):
282
278
    def test_find_format(self):
283
279
        # is the right format object found for a branch?
284
280
        # create a branch with a few known format objects.
285
 
        bzr.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
286
 
                                       BzrDirFormatTest1())
287
 
        self.addCleanup(bzr.BzrProber.formats.remove,
288
 
                        BzrDirFormatTest1.get_format_string())
289
 
        bzr.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
290
 
                                       BzrDirFormatTest2())
291
 
        self.addCleanup(bzr.BzrProber.formats.remove,
292
 
                        BzrDirFormatTest2.get_format_string())
 
281
        bzrdir.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
 
282
            BzrDirFormatTest1())
 
283
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
284
            BzrDirFormatTest1.get_format_string())
 
285
        bzrdir.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
 
286
            BzrDirFormatTest2())
 
287
        self.addCleanup(bzrdir.BzrProber.formats.remove,
 
288
            BzrDirFormatTest2.get_format_string())
293
289
        t = self.get_transport()
294
290
        self.build_tree(["foo/", "bar/"], transport=t)
295
 
 
296
291
        def check_format(format, url):
297
292
            format.initialize(url)
298
293
            t = _mod_transport.get_transport_from_path(url)
309
304
    def test_find_format_unknown_format(self):
310
305
        t = self.get_transport()
311
306
        t.mkdir('.bzr')
312
 
        t.put_bytes('.bzr/branch-format', b'')
 
307
        t.put_bytes('.bzr/branch-format', '')
313
308
        self.assertRaises(UnknownFormatError,
314
309
                          bzrdir.BzrDirFormat.find_format,
315
310
                          _mod_transport.get_transport_from_path('.'))
316
311
 
317
 
    def test_find_format_line_endings(self):
318
 
        t = self.get_transport()
319
 
        t.mkdir('.bzr')
320
 
        t.put_bytes('.bzr/branch-format', b'Corrupt line endings\r\n')
321
 
        self.assertRaises(errors.LineEndingError,
322
 
                          bzrdir.BzrDirFormat.find_format,
323
 
                          _mod_transport.get_transport_from_path('.'))
324
 
 
325
312
    def test_register_unregister_format(self):
326
313
        format = SampleBzrDirFormat()
327
314
        url = self.get_url()
328
315
        # make a bzrdir
329
316
        format.initialize(url)
330
317
        # register a format for it.
331
 
        bzr.BzrProber.formats.register(format.get_format_string(), format)
 
318
        bzrdir.BzrProber.formats.register(format.get_format_string(), format)
332
319
        # which bzrdir.Open will refuse (not supported)
333
320
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
334
321
        # which bzrdir.open_containing will refuse (not supported)
335
 
        self.assertRaises(UnsupportedFormatError,
336
 
                          bzrdir.BzrDir.open_containing, url)
 
322
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
337
323
        # but open_downlevel will work
338
324
        t = _mod_transport.get_transport_from_url(url)
339
325
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
340
326
        # unregister the format
341
 
        bzr.BzrProber.formats.remove(format.get_format_string())
 
327
        bzrdir.BzrProber.formats.remove(format.get_format_string())
342
328
        # now open_downlevel should fail too.
343
 
        self.assertRaises(UnknownFormatError,
344
 
                          bzrdir.BzrDir.open_unsupported, url)
 
329
        self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
345
330
 
346
331
    def test_create_branch_and_repo_uses_default(self):
347
332
        format = SampleBzrDirFormat()
352
337
    def test_create_branch_and_repo_under_shared(self):
353
338
        # creating a branch and repo in a shared repo uses the
354
339
        # shared repository
355
 
        format = controldir.format_registry.make_controldir('knit')
 
340
        format = controldir.format_registry.make_bzrdir('knit')
356
341
        self.make_repository('.', shared=True, format=format)
357
342
        branch = bzrdir.BzrDir.create_branch_and_repo(
358
343
            self.get_url('child'), format=format)
359
344
        self.assertRaises(errors.NoRepositoryPresent,
360
 
                          branch.controldir.open_repository)
 
345
                          branch.bzrdir.open_repository)
361
346
 
362
347
    def test_create_branch_and_repo_under_shared_force_new(self):
363
348
        # creating a branch and repo in a shared repo can be forced to
364
349
        # make a new repo
365
 
        format = controldir.format_registry.make_controldir('knit')
 
350
        format = controldir.format_registry.make_bzrdir('knit')
366
351
        self.make_repository('.', shared=True, format=format)
367
352
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
368
353
                                                      force_new_repo=True,
369
354
                                                      format=format)
370
 
        branch.controldir.open_repository()
 
355
        branch.bzrdir.open_repository()
371
356
 
372
357
    def test_create_standalone_working_tree(self):
373
358
        format = SampleBzrDirFormat()
382
367
 
383
368
    def test_create_standalone_working_tree_under_shared_repo(self):
384
369
        # create standalone working tree always makes a repo.
385
 
        format = controldir.format_registry.make_controldir('knit')
 
370
        format = controldir.format_registry.make_bzrdir('knit')
386
371
        self.make_repository('.', shared=True, format=format)
387
372
        # note this is deliberately readonly, as this failure should
388
373
        # occur before any writes.
390
375
                          bzrdir.BzrDir.create_standalone_workingtree,
391
376
                          self.get_readonly_url('child'), format=format)
392
377
        tree = bzrdir.BzrDir.create_standalone_workingtree('child',
393
 
                                                           format=format)
394
 
        tree.controldir.open_repository()
 
378
            format=format)
 
379
        tree.bzrdir.open_repository()
395
380
 
396
381
    def test_create_branch_convenience(self):
397
382
        # outside a repo the default convenience output is a repo+branch_tree
398
 
        format = controldir.format_registry.make_controldir('knit')
 
383
        format = controldir.format_registry.make_bzrdir('knit')
399
384
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
400
 
        branch.controldir.open_workingtree()
401
 
        branch.controldir.open_repository()
 
385
        branch.bzrdir.open_workingtree()
 
386
        branch.bzrdir.open_repository()
402
387
 
403
388
    def test_create_branch_convenience_possible_transports(self):
404
389
        """Check that the optional 'possible_transports' is recognized"""
405
 
        format = controldir.format_registry.make_controldir('knit')
 
390
        format = controldir.format_registry.make_bzrdir('knit')
406
391
        t = self.get_transport()
407
392
        branch = bzrdir.BzrDir.create_branch_convenience(
408
393
            '.', format=format, possible_transports=[t])
409
 
        branch.controldir.open_workingtree()
410
 
        branch.controldir.open_repository()
 
394
        branch.bzrdir.open_workingtree()
 
395
        branch.bzrdir.open_repository()
411
396
 
412
397
    def test_create_branch_convenience_root(self):
413
398
        """Creating a branch at the root of a fs should work."""
414
399
        self.vfs_transport_factory = memory.MemoryServer
415
400
        # outside a repo the default convenience output is a repo+branch_tree
416
 
        format = controldir.format_registry.make_controldir('knit')
 
401
        format = controldir.format_registry.make_bzrdir('knit')
417
402
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
418
403
                                                         format=format)
419
404
        self.assertRaises(errors.NoWorkingTree,
420
 
                          branch.controldir.open_workingtree)
421
 
        branch.controldir.open_repository()
 
405
                          branch.bzrdir.open_workingtree)
 
406
        branch.bzrdir.open_repository()
422
407
 
423
408
    def test_create_branch_convenience_under_shared_repo(self):
424
409
        # inside a repo the default convenience output is a branch+ follow the
425
410
        # repo tree policy
426
 
        format = controldir.format_registry.make_controldir('knit')
 
411
        format = controldir.format_registry.make_bzrdir('knit')
427
412
        self.make_repository('.', shared=True, format=format)
428
413
        branch = bzrdir.BzrDir.create_branch_convenience('child',
429
 
                                                         format=format)
430
 
        branch.controldir.open_workingtree()
 
414
            format=format)
 
415
        branch.bzrdir.open_workingtree()
431
416
        self.assertRaises(errors.NoRepositoryPresent,
432
 
                          branch.controldir.open_repository)
 
417
                          branch.bzrdir.open_repository)
433
418
 
434
419
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
435
420
        # inside a repo the default convenience output is a branch+ follow the
436
421
        # repo tree policy but we can override that
437
 
        format = controldir.format_registry.make_controldir('knit')
 
422
        format = controldir.format_registry.make_bzrdir('knit')
438
423
        self.make_repository('.', shared=True, format=format)
439
424
        branch = bzrdir.BzrDir.create_branch_convenience('child',
440
 
                                                         force_new_tree=False, format=format)
 
425
            force_new_tree=False, format=format)
441
426
        self.assertRaises(errors.NoWorkingTree,
442
 
                          branch.controldir.open_workingtree)
 
427
                          branch.bzrdir.open_workingtree)
443
428
        self.assertRaises(errors.NoRepositoryPresent,
444
 
                          branch.controldir.open_repository)
 
429
                          branch.bzrdir.open_repository)
445
430
 
446
431
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
447
432
        # inside a repo the default convenience output is a branch+ follow the
448
433
        # repo tree policy
449
 
        format = controldir.format_registry.make_controldir('knit')
 
434
        format = controldir.format_registry.make_bzrdir('knit')
450
435
        repo = self.make_repository('.', shared=True, format=format)
451
436
        repo.set_make_working_trees(False)
452
437
        branch = bzrdir.BzrDir.create_branch_convenience('child',
453
438
                                                         format=format)
454
439
        self.assertRaises(errors.NoWorkingTree,
455
 
                          branch.controldir.open_workingtree)
 
440
                          branch.bzrdir.open_workingtree)
456
441
        self.assertRaises(errors.NoRepositoryPresent,
457
 
                          branch.controldir.open_repository)
 
442
                          branch.bzrdir.open_repository)
458
443
 
459
444
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
460
445
        # inside a repo the default convenience output is a branch+ follow the
461
446
        # repo tree policy but we can override that
462
 
        format = controldir.format_registry.make_controldir('knit')
 
447
        format = controldir.format_registry.make_bzrdir('knit')
463
448
        repo = self.make_repository('.', shared=True, format=format)
464
449
        repo.set_make_working_trees(False)
465
450
        branch = bzrdir.BzrDir.create_branch_convenience('child',
466
 
                                                         force_new_tree=True, format=format)
467
 
        branch.controldir.open_workingtree()
 
451
            force_new_tree=True, format=format)
 
452
        branch.bzrdir.open_workingtree()
468
453
        self.assertRaises(errors.NoRepositoryPresent,
469
 
                          branch.controldir.open_repository)
 
454
                          branch.bzrdir.open_repository)
470
455
 
471
456
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
472
457
        # inside a repo the default convenience output is overridable to give
473
458
        # repo+branch+tree
474
 
        format = controldir.format_registry.make_controldir('knit')
 
459
        format = controldir.format_registry.make_bzrdir('knit')
475
460
        self.make_repository('.', shared=True, format=format)
476
461
        branch = bzrdir.BzrDir.create_branch_convenience('child',
477
 
                                                         force_new_repo=True, format=format)
478
 
        branch.controldir.open_repository()
479
 
        branch.controldir.open_workingtree()
 
462
            force_new_repo=True, format=format)
 
463
        branch.bzrdir.open_repository()
 
464
        branch.bzrdir.open_workingtree()
480
465
 
481
466
 
482
467
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
483
468
 
484
469
    def test_acquire_repository_standalone(self):
485
470
        """The default acquisition policy should create a standalone branch."""
486
 
        my_bzrdir = self.make_controldir('.')
 
471
        my_bzrdir = self.make_bzrdir('.')
487
472
        repo_policy = my_bzrdir.determine_repository_policy()
488
473
        repo, is_new = repo_policy.acquire_repository()
489
 
        self.assertEqual(repo.controldir.root_transport.base,
 
474
        self.assertEqual(repo.bzrdir.root_transport.base,
490
475
                         my_bzrdir.root_transport.base)
491
476
        self.assertFalse(repo.is_shared())
492
477
 
493
478
    def test_determine_stacking_policy(self):
494
 
        parent_bzrdir = self.make_controldir('.')
495
 
        child_bzrdir = self.make_controldir('child')
 
479
        parent_bzrdir = self.make_bzrdir('.')
 
480
        child_bzrdir = self.make_bzrdir('child')
496
481
        parent_bzrdir.get_config().set_default_stack_on('http://example.org')
497
482
        repo_policy = child_bzrdir.determine_repository_policy()
498
483
        self.assertEqual('http://example.org', repo_policy._stack_on)
499
484
 
500
485
    def test_determine_stacking_policy_relative(self):
501
 
        parent_bzrdir = self.make_controldir('.')
502
 
        child_bzrdir = self.make_controldir('child')
 
486
        parent_bzrdir = self.make_bzrdir('.')
 
487
        child_bzrdir = self.make_bzrdir('child')
503
488
        parent_bzrdir.get_config().set_default_stack_on('child2')
504
489
        repo_policy = child_bzrdir.determine_repository_policy()
505
490
        self.assertEqual('child2', repo_policy._stack_on)
507
492
                         repo_policy._stack_on_pwd)
508
493
 
509
494
    def prepare_default_stacking(self, child_format='1.6'):
510
 
        parent_bzrdir = self.make_controldir('.')
 
495
        parent_bzrdir = self.make_bzrdir('.')
511
496
        child_branch = self.make_branch('child', format=child_format)
512
497
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
513
498
        new_child_transport = parent_bzrdir.transport.clone('child2')
515
500
 
516
501
    def test_clone_on_transport_obeys_stacking_policy(self):
517
502
        child_branch, new_child_transport = self.prepare_default_stacking()
518
 
        new_child = child_branch.controldir.clone_on_transport(
519
 
            new_child_transport)
 
503
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
520
504
        self.assertEqual(child_branch.base,
521
505
                         new_child.open_branch().get_stacked_on_url())
522
506
 
523
507
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
524
508
        # Make stackable source branch with an unstackable repo format.
525
 
        source_bzrdir = self.make_controldir('source')
 
509
        source_bzrdir = self.make_bzrdir('source')
526
510
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
527
 
        source_branch = breezy.bzr.branch.BzrBranchFormat7().initialize(
 
511
        source_branch = brzlib.branch.BzrBranchFormat7().initialize(
528
512
            source_bzrdir)
529
513
        # Make a directory with a default stacking policy
530
 
        parent_bzrdir = self.make_controldir('parent')
 
514
        parent_bzrdir = self.make_bzrdir('parent')
531
515
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
532
516
        parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
533
517
        # Clone source into directory
539
523
        # general case.
540
524
        trunk = self.make_branch('trunk', format='1.9')
541
525
        t = self.get_transport('stacked')
542
 
        old_fmt = controldir.format_registry.make_controldir('pack-0.92')
 
526
        old_fmt = controldir.format_registry.make_bzrdir('pack-0.92')
543
527
        repo_name = old_fmt.repository_format.network_name()
544
528
        # Should end up with a 1.9 format (stackable)
545
529
        repo, control, require_stacking, repo_policy = \
546
530
            old_fmt.initialize_on_transport_ex(t,
547
 
                                               repo_format_name=repo_name, stacked_on='../trunk',
548
 
                                               stack_on_pwd=t.base)
 
531
                    repo_format_name=repo_name, stacked_on='../trunk',
 
532
                    stack_on_pwd=t.base)
549
533
        if repo is not None:
550
534
            # Repositories are open write-locked
551
535
            self.assertTrue(repo.is_write_locked())
556
540
        opened = bzrdir.BzrDir.open(t.base)
557
541
        if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
558
542
            self.assertEqual(control._format.network_name(),
559
 
                             old_fmt.network_name())
 
543
                old_fmt.network_name())
560
544
            self.assertEqual(control._format.network_name(),
561
 
                             opened._format.network_name())
 
545
                opened._format.network_name())
562
546
        self.assertEqual(control.__class__, opened.__class__)
563
547
        self.assertLength(1, repo._fallback_repositories)
564
548
 
565
549
    def test_sprout_obeys_stacking_policy(self):
566
550
        child_branch, new_child_transport = self.prepare_default_stacking()
567
 
        new_child = child_branch.controldir.sprout(new_child_transport.base)
 
551
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
568
552
        self.assertEqual(child_branch.base,
569
553
                         new_child.open_branch().get_stacked_on_url())
570
554
 
571
555
    def test_clone_ignores_policy_for_unsupported_formats(self):
572
556
        child_branch, new_child_transport = self.prepare_default_stacking(
573
557
            child_format='pack-0.92')
574
 
        new_child = child_branch.controldir.clone_on_transport(
575
 
            new_child_transport)
576
 
        self.assertRaises(branch.UnstackableBranchFormat,
 
558
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
 
559
        self.assertRaises(errors.UnstackableBranchFormat,
577
560
                          new_child.open_branch().get_stacked_on_url)
578
561
 
579
562
    def test_sprout_ignores_policy_for_unsupported_formats(self):
580
563
        child_branch, new_child_transport = self.prepare_default_stacking(
581
564
            child_format='pack-0.92')
582
 
        new_child = child_branch.controldir.sprout(new_child_transport.base)
583
 
        self.assertRaises(branch.UnstackableBranchFormat,
 
565
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
 
566
        self.assertRaises(errors.UnstackableBranchFormat,
584
567
                          new_child.open_branch().get_stacked_on_url)
585
568
 
586
569
    def test_sprout_upgrades_format_if_stacked_specified(self):
587
570
        child_branch, new_child_transport = self.prepare_default_stacking(
588
571
            child_format='pack-0.92')
589
 
        new_child = child_branch.controldir.sprout(new_child_transport.base,
590
 
                                                   stacked=True)
591
 
        self.assertEqual(child_branch.controldir.root_transport.base,
 
572
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
573
                                               stacked=True)
 
574
        self.assertEqual(child_branch.bzrdir.root_transport.base,
592
575
                         new_child.open_branch().get_stacked_on_url())
593
576
        repo = new_child.open_repository()
594
577
        self.assertTrue(repo._format.supports_external_lookups)
597
580
    def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
598
581
        child_branch, new_child_transport = self.prepare_default_stacking(
599
582
            child_format='pack-0.92')
600
 
        new_child = child_branch.controldir.clone_on_transport(new_child_transport,
601
 
                                                               stacked_on=child_branch.controldir.root_transport.base)
602
 
        self.assertEqual(child_branch.controldir.root_transport.base,
 
583
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
 
584
            stacked_on=child_branch.bzrdir.root_transport.base)
 
585
        self.assertEqual(child_branch.bzrdir.root_transport.base,
603
586
                         new_child.open_branch().get_stacked_on_url())
604
587
        repo = new_child.open_repository()
605
588
        self.assertTrue(repo._format.supports_external_lookups)
608
591
    def test_sprout_upgrades_to_rich_root_format_if_needed(self):
609
592
        child_branch, new_child_transport = self.prepare_default_stacking(
610
593
            child_format='rich-root-pack')
611
 
        new_child = child_branch.controldir.sprout(new_child_transport.base,
612
 
                                                   stacked=True)
 
594
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
595
                                               stacked=True)
613
596
        repo = new_child.open_repository()
614
597
        self.assertTrue(repo._format.supports_external_lookups)
615
598
        self.assertTrue(repo.supports_rich_root())
630
613
        stack_on = self.make_branch('stack_on', format='1.6')
631
614
        stacked = self.make_branch('stack_on/stacked', format='1.6')
632
615
        policy = bzrdir.UseExistingRepository(stacked.repository,
633
 
                                              '.', stack_on.base)
 
616
            '.', stack_on.base)
634
617
        policy.configure_branch(stacked)
635
618
        self.assertEqual('..', stacked.get_stacked_on_url())
636
619
 
638
621
        stack_on = self.make_branch('stack_on', format='1.6')
639
622
        stacked = self.make_branch('stack_on/stacked', format='1.6')
640
623
        policy = bzrdir.UseExistingRepository(stacked.repository,
641
 
                                              '.', self.get_readonly_url('stack_on'))
 
624
            '.', self.get_readonly_url('stack_on'))
642
625
        policy.configure_branch(stacked)
643
626
        self.assertEqual(self.get_readonly_url('stack_on'),
644
627
                         stacked.get_stacked_on_url())
658
641
            self.transport_readonly_server = http_server.HttpServer
659
642
 
660
643
    def local_branch_path(self, branch):
661
 
        return os.path.realpath(urlutils.local_path_from_url(branch.base))
 
644
         return os.path.realpath(urlutils.local_path_from_url(branch.base))
662
645
 
663
646
    def test_open_containing(self):
664
647
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
666
649
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
667
650
                          self.get_readonly_url('g/p/q'))
668
651
        control = bzrdir.BzrDir.create(self.get_url())
669
 
        branch, relpath = bzrdir.BzrDir.open_containing(
 
652
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
 
653
        self.assertEqual('', relpath)
 
654
        branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
 
655
        self.assertEqual('g/p/q', relpath)
 
656
 
 
657
    def test_open_containing_tree_branch_or_repository_empty(self):
 
658
        self.assertRaises(errors.NotBranchError,
 
659
            bzrdir.BzrDir.open_containing_tree_branch_or_repository,
670
660
            self.get_readonly_url(''))
671
 
        self.assertEqual('', relpath)
672
 
        branch, relpath = bzrdir.BzrDir.open_containing(
673
 
            self.get_readonly_url('g/p/q'))
674
 
        self.assertEqual('g/p/q', relpath)
675
 
 
676
 
    def test_open_containing_tree_branch_or_repository_empty(self):
677
 
        self.assertRaises(errors.NotBranchError,
678
 
                          bzrdir.BzrDir.open_containing_tree_branch_or_repository,
679
 
                          self.get_readonly_url(''))
680
661
 
681
662
    def test_open_containing_tree_branch_or_repository_all(self):
682
663
        self.make_branch_and_tree('topdir')
689
670
                         self.local_branch_path(branch))
690
671
        self.assertEqual(
691
672
            osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
692
 
            repo.controldir.transport.local_abspath('repository'))
 
673
            repo.bzrdir.transport.local_abspath('repository'))
693
674
        self.assertEqual(relpath, 'foo')
694
675
 
695
676
    def test_open_containing_tree_branch_or_repository_no_tree(self):
702
683
                         self.local_branch_path(branch))
703
684
        self.assertEqual(
704
685
            osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
705
 
            repo.controldir.transport.local_abspath('repository'))
 
686
            repo.bzrdir.transport.local_abspath('repository'))
706
687
        self.assertEqual(relpath, 'foo')
707
688
 
708
689
    def test_open_containing_tree_branch_or_repository_repo(self):
714
695
        self.assertEqual(branch, None)
715
696
        self.assertEqual(
716
697
            osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
717
 
            repo.controldir.transport.local_abspath('repository'))
 
698
            repo.bzrdir.transport.local_abspath('repository'))
718
699
        self.assertEqual(relpath, '')
719
700
 
720
701
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
729
710
                         self.local_branch_path(branch))
730
711
        self.assertEqual(
731
712
            osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
732
 
            repo.controldir.transport.local_abspath('repository'))
 
713
            repo.bzrdir.transport.local_abspath('repository'))
733
714
        self.assertEqual(relpath, '')
734
715
 
735
716
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
744
725
                         self.local_branch_path(branch))
745
726
        self.assertEqual(
746
727
            osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
747
 
            repo.controldir.transport.local_abspath('repository'))
 
728
            repo.bzrdir.transport.local_abspath('repository'))
748
729
        self.assertEqual(relpath, 'bar')
749
730
 
750
731
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
757
738
        self.assertEqual(branch, None)
758
739
        self.assertEqual(
759
740
            osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
760
 
            repo.controldir.transport.local_abspath('repository'))
 
741
            repo.bzrdir.transport.local_abspath('repository'))
761
742
        self.assertEqual(relpath, 'baz')
762
743
 
763
744
    def test_open_containing_from_transport(self):
764
745
        self.assertRaises(NotBranchError,
765
 
                          bzrdir.BzrDir.open_containing_from_transport,
766
 
                          _mod_transport.get_transport_from_url(self.get_readonly_url('')))
 
746
            bzrdir.BzrDir.open_containing_from_transport,
 
747
            _mod_transport.get_transport_from_url(self.get_readonly_url('')))
767
748
        self.assertRaises(NotBranchError,
768
 
                          bzrdir.BzrDir.open_containing_from_transport,
769
 
                          _mod_transport.get_transport_from_url(
770
 
                              self.get_readonly_url('g/p/q')))
 
749
            bzrdir.BzrDir.open_containing_from_transport,
 
750
            _mod_transport.get_transport_from_url(
 
751
                self.get_readonly_url('g/p/q')))
771
752
        control = bzrdir.BzrDir.create(self.get_url())
772
753
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
773
754
            _mod_transport.get_transport_from_url(
786
767
                         os.path.realpath(tree.basedir))
787
768
        self.assertEqual(os.path.realpath('topdir'),
788
769
                         self.local_branch_path(branch))
789
 
        self.assertIs(tree.controldir, branch.controldir)
 
770
        self.assertIs(tree.bzrdir, branch.bzrdir)
790
771
        self.assertEqual('foo', relpath)
791
772
        # opening from non-local should not return the tree
792
773
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
809
790
                         os.path.realpath(tree.basedir))
810
791
        self.assertEqual(os.path.realpath('topdir'),
811
792
                         self.local_branch_path(branch))
812
 
        self.assertIs(tree.controldir, branch.controldir)
 
793
        self.assertIs(tree.bzrdir, branch.bzrdir)
813
794
        # opening from non-local should not return the tree
814
795
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
815
796
            self.get_readonly_url('topdir'))
842
823
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
843
824
 
844
825
    def test_sprout_recursive(self):
845
 
        tree = self.make_branch_and_tree('tree1')
846
 
        sub_tree = self.make_branch_and_tree('tree1/subtree')
847
 
        sub_tree.set_root_id(b'subtree-root')
 
826
        tree = self.make_branch_and_tree('tree1',
 
827
                                         format='development-subtree')
 
828
        sub_tree = self.make_branch_and_tree('tree1/subtree',
 
829
            format='development-subtree')
 
830
        sub_tree.set_root_id('subtree-root')
848
831
        tree.add_reference(sub_tree)
849
 
        tree.set_reference_info('subtree', sub_tree.branch.user_url)
850
832
        self.build_tree(['tree1/subtree/file'])
851
833
        sub_tree.add('file')
852
834
        tree.commit('Initial commit')
853
 
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
 
835
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
854
836
        tree2.lock_read()
855
837
        self.addCleanup(tree2.unlock)
856
838
        self.assertPathExists('tree2/subtree/file')
857
 
        self.assertEqual('tree-reference', tree2.kind('subtree'))
 
839
        self.assertEqual('tree-reference', tree2.kind('subtree-root'))
858
840
 
859
841
    def test_cloning_metadir(self):
860
842
        """Ensure that cloning metadir is suitable"""
861
 
        bzrdir = self.make_controldir('bzrdir')
 
843
        bzrdir = self.make_bzrdir('bzrdir')
862
844
        bzrdir.cloning_metadir()
863
845
        branch = self.make_branch('branch', format='knit')
864
 
        format = branch.controldir.cloning_metadir()
 
846
        format = branch.bzrdir.cloning_metadir()
865
847
        self.assertIsInstance(format.workingtree_format,
866
 
                              workingtree_4.WorkingTreeFormat6)
 
848
            workingtree_4.WorkingTreeFormat6)
867
849
 
868
850
    def test_sprout_recursive_treeless(self):
869
851
        tree = self.make_branch_and_tree('tree1',
870
 
                                         format='development-subtree')
 
852
            format='development-subtree')
871
853
        sub_tree = self.make_branch_and_tree('tree1/subtree',
872
 
                                             format='development-subtree')
 
854
            format='development-subtree')
873
855
        tree.add_reference(sub_tree)
874
 
        tree.set_reference_info('subtree', sub_tree.branch.user_url)
875
856
        self.build_tree(['tree1/subtree/file'])
876
857
        sub_tree.add('file')
877
858
        tree.commit('Initial commit')
878
859
        # The following line force the orhaning to reveal bug #634470
879
 
        tree.branch.get_config_stack().set('transform.orphan_policy', 'move')
880
 
        tree.controldir.destroy_workingtree()
 
860
        tree.branch.get_config_stack().set(
 
861
            'bzr.transform.orphan_policy', 'move')
 
862
        tree.bzrdir.destroy_workingtree()
881
863
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
882
864
        # fail :-( ) -- vila 20100909
883
865
        repo = self.make_repository('repo', shared=True,
884
 
                                    format='development-subtree')
 
866
            format='development-subtree')
885
867
        repo.set_make_working_trees(False)
886
868
        # FIXME: we just deleted the workingtree and now we want to use it ????
887
869
        # At a minimum, we should use tree.branch below (but this fails too
891
873
        # by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
892
874
        # [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
893
875
        # #634470.  -- vila 20100909
894
 
        tree.controldir.sprout('repo/tree2')
895
 
        self.assertPathExists('repo/tree2/subtree')
896
 
        self.assertPathDoesNotExist('repo/tree2/subtree/file')
 
876
        self.assertRaises(errors.NotBranchError,
 
877
                          tree.bzrdir.sprout, 'repo/tree2')
 
878
#        self.assertPathExists('repo/tree2/subtree')
 
879
#        self.assertPathDoesNotExist('repo/tree2/subtree/file')
897
880
 
898
881
    def make_foo_bar_baz(self):
899
 
        foo = bzrdir.BzrDir.create_branch_convenience('foo').controldir
900
 
        bar = self.make_branch('foo/bar').controldir
901
 
        baz = self.make_branch('baz').controldir
 
882
        foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
 
883
        bar = self.make_branch('foo/bar').bzrdir
 
884
        baz = self.make_branch('baz').bzrdir
902
885
        return foo, bar, baz
903
886
 
904
 
    def test_find_controldirs(self):
 
887
    def test_find_bzrdirs(self):
905
888
        foo, bar, baz = self.make_foo_bar_baz()
906
889
        t = self.get_transport()
907
 
        self.assertEqualBzrdirs(
908
 
            [baz, foo, bar], bzrdir.BzrDir.find_controldirs(t))
 
890
        self.assertEqualBzrdirs([baz, foo, bar], bzrdir.BzrDir.find_bzrdirs(t))
909
891
 
910
892
    def make_fake_permission_denied_transport(self, transport, paths):
911
893
        """Create a transport that raises PermissionDenied for some paths."""
925
907
        for actual_bzrdir in actual_bzrdirs:
926
908
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
927
909
 
928
 
    def test_find_controldirs_permission_denied(self):
 
910
    def test_find_bzrdirs_permission_denied(self):
929
911
        foo, bar, baz = self.make_foo_bar_baz()
930
912
        t = self.get_transport()
931
913
        path_filter_server, path_filter_transport = \
932
914
            self.make_fake_permission_denied_transport(t, ['foo'])
933
915
        # local transport
934
916
        self.assertBranchUrlsEndWith('/baz/',
935
 
                                     bzrdir.BzrDir.find_controldirs(path_filter_transport))
 
917
            bzrdir.BzrDir.find_bzrdirs(path_filter_transport))
936
918
        # smart server
937
919
        smart_transport = self.make_smart_server('.',
938
 
                                                 backing_server=path_filter_server)
 
920
            backing_server=path_filter_server)
939
921
        self.assertBranchUrlsEndWith('/baz/',
940
 
                                     bzrdir.BzrDir.find_controldirs(smart_transport))
 
922
            bzrdir.BzrDir.find_bzrdirs(smart_transport))
941
923
 
942
 
    def test_find_controldirs_list_current(self):
 
924
    def test_find_bzrdirs_list_current(self):
943
925
        def list_current(transport):
944
926
            return [s for s in transport.list_dir('') if s != 'baz']
945
927
 
947
929
        t = self.get_transport()
948
930
        self.assertEqualBzrdirs(
949
931
            [foo, bar],
950
 
            bzrdir.BzrDir.find_controldirs(t, list_current=list_current))
 
932
            bzrdir.BzrDir.find_bzrdirs(t, list_current=list_current))
951
933
 
952
 
    def test_find_controldirs_evaluate(self):
 
934
    def test_find_bzrdirs_evaluate(self):
953
935
        def evaluate(bzrdir):
954
936
            try:
955
937
                repo = bzrdir.open_repository()
961
943
        foo, bar, baz = self.make_foo_bar_baz()
962
944
        t = self.get_transport()
963
945
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
964
 
                         list(bzrdir.BzrDir.find_controldirs(t, evaluate=evaluate)))
 
946
                         list(bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate)))
965
947
 
966
948
    def assertEqualBzrdirs(self, first, second):
967
949
        first = list(first)
973
955
    def test_find_branches(self):
974
956
        root = self.make_repository('', shared=True)
975
957
        foo, bar, baz = self.make_foo_bar_baz()
976
 
        qux = self.make_controldir('foo/qux')
 
958
        qux = self.make_bzrdir('foo/qux')
977
959
        t = self.get_transport()
978
960
        branches = bzrdir.BzrDir.find_branches(t)
979
961
        self.assertEqual(baz.root_transport.base, branches[0].base)
988
970
 
989
971
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
990
972
 
991
 
    def test_find_controldirs_missing_repo(self):
 
973
    def test_find_bzrdirs_missing_repo(self):
992
974
        t = self.get_transport()
993
975
        arepo = self.make_repository('arepo', shared=True)
994
976
        abranch_url = arepo.user_url + '/abranch'
995
977
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
996
978
        t.delete_tree('arepo/.bzr')
997
979
        self.assertRaises(errors.NoRepositoryPresent,
998
 
                          branch.Branch.open, abranch_url)
 
980
            branch.Branch.open, abranch_url)
999
981
        self.make_branch('baz')
1000
982
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
1001
983
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
1012
994
        self.assertEqual(branch_base,
1013
995
                         dir.get_branch_transport(BzrBranchFormat5()).base)
1014
996
        repository_base = t.clone('repository').base
1015
 
        self.assertEqual(
1016
 
            repository_base, dir.get_repository_transport(None).base)
 
997
        self.assertEqual(repository_base, dir.get_repository_transport(None).base)
1017
998
        repository_format = repository.format_registry.get_default()
1018
999
        self.assertEqual(repository_base,
1019
1000
                         dir.get_repository_transport(repository_format).base)
1020
1001
        checkout_base = t.clone('checkout').base
1021
 
        self.assertEqual(
1022
 
            checkout_base, dir.get_workingtree_transport(None).base)
 
1002
        self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
1023
1003
        self.assertEqual(checkout_base,
1024
1004
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
1025
1005
 
1035
1015
        Metadirs should compare equal iff they have the same repo, branch and
1036
1016
        tree formats.
1037
1017
        """
1038
 
        mydir = controldir.format_registry.make_controldir('knit')
 
1018
        mydir = controldir.format_registry.make_bzrdir('knit')
1039
1019
        self.assertEqual(mydir, mydir)
1040
1020
        self.assertFalse(mydir != mydir)
1041
 
        otherdir = controldir.format_registry.make_controldir('knit')
 
1021
        otherdir = controldir.format_registry.make_bzrdir('knit')
1042
1022
        self.assertEqual(otherdir, mydir)
1043
1023
        self.assertFalse(otherdir != mydir)
1044
 
        otherdir2 = controldir.format_registry.make_controldir(
1045
 
            'development-subtree')
 
1024
        otherdir2 = controldir.format_registry.make_bzrdir('development-subtree')
1046
1025
        self.assertNotEqual(otherdir2, mydir)
1047
1026
        self.assertFalse(otherdir2 == mydir)
1048
1027
 
1049
1028
    def test_with_features(self):
1050
1029
        tree = self.make_branch_and_tree('tree', format='2a')
1051
 
        tree.controldir.update_feature_flags({b"bar": b"required"})
1052
 
        self.assertRaises(bzrdir.MissingFeature, bzrdir.BzrDir.open, 'tree')
1053
 
        bzrdir.BzrDirMetaFormat1.register_feature(b'bar')
1054
 
        self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, b'bar')
 
1030
        tree.bzrdir.update_feature_flags({"bar": "required"})
 
1031
        self.assertRaises(errors.MissingFeature, bzrdir.BzrDir.open, 'tree')
 
1032
        bzrdir.BzrDirMetaFormat1.register_feature('bar')
 
1033
        self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, 'bar')
1055
1034
        dir = bzrdir.BzrDir.open('tree')
1056
 
        self.assertEqual(b"required", dir._format.features.get(b"bar"))
1057
 
        tree.controldir.update_feature_flags({
1058
 
            b"bar": None,
1059
 
            b"nonexistant": None})
 
1035
        self.assertEqual("required", dir._format.features.get("bar"))
 
1036
        tree.bzrdir.update_feature_flags({"bar": None, "nonexistant": None})
1060
1037
        dir = bzrdir.BzrDir.open('tree')
1061
1038
        self.assertEqual({}, dir._format.features)
1062
1039
 
1063
1040
    def test_needs_conversion_different_working_tree(self):
1064
1041
        # meta1dirs need an conversion if any element is not the default.
1065
 
        new_format = controldir.format_registry.make_controldir('dirstate')
 
1042
        new_format = controldir.format_registry.make_bzrdir('dirstate')
1066
1043
        tree = self.make_branch_and_tree('tree', format='knit')
1067
 
        self.assertTrue(tree.controldir.needs_format_conversion(
 
1044
        self.assertTrue(tree.bzrdir.needs_format_conversion(
1068
1045
            new_format))
1069
1046
 
1070
1047
    def test_initialize_on_format_uses_smart_transport(self):
1071
1048
        self.setup_smart_server_with_call_log()
1072
 
        new_format = controldir.format_registry.make_controldir('dirstate')
 
1049
        new_format = controldir.format_registry.make_bzrdir('dirstate')
1073
1050
        transport = self.get_transport('target')
1074
1051
        transport.ensure_base()
1075
1052
        self.reset_smart_call_log()
1093
1070
 
1094
1071
    def test_create_branch_convenience(self):
1095
1072
        # outside a repo the default convenience output is a repo+branch_tree
1096
 
        format = controldir.format_registry.make_controldir('knit')
 
1073
        format = controldir.format_registry.make_bzrdir('knit')
1097
1074
        branch = bzrdir.BzrDir.create_branch_convenience(
1098
1075
            self.get_url('foo'), format=format)
1099
1076
        self.assertRaises(errors.NoWorkingTree,
1100
 
                          branch.controldir.open_workingtree)
1101
 
        branch.controldir.open_repository()
 
1077
                          branch.bzrdir.open_workingtree)
 
1078
        branch.bzrdir.open_repository()
1102
1079
 
1103
1080
    def test_create_branch_convenience_force_tree_not_local_fails(self):
1104
1081
        # outside a repo the default convenience output is a repo+branch_tree
1105
 
        format = controldir.format_registry.make_controldir('knit')
 
1082
        format = controldir.format_registry.make_bzrdir('knit')
1106
1083
        self.assertRaises(errors.NotLocalUrl,
1107
 
                          bzrdir.BzrDir.create_branch_convenience,
1108
 
                          self.get_url('foo'),
1109
 
                          force_new_tree=True,
1110
 
                          format=format)
 
1084
            bzrdir.BzrDir.create_branch_convenience,
 
1085
            self.get_url('foo'),
 
1086
            force_new_tree=True,
 
1087
            format=format)
1111
1088
        t = self.get_transport()
1112
1089
        self.assertFalse(t.has('foo'))
1113
1090
 
1114
1091
    def test_clone(self):
1115
1092
        # clone into a nonlocal path works
1116
 
        format = controldir.format_registry.make_controldir('knit')
 
1093
        format = controldir.format_registry.make_bzrdir('knit')
1117
1094
        branch = bzrdir.BzrDir.create_branch_convenience('local',
1118
1095
                                                         format=format)
1119
 
        branch.controldir.open_workingtree()
1120
 
        result = branch.controldir.clone(self.get_url('remote'))
 
1096
        branch.bzrdir.open_workingtree()
 
1097
        result = branch.bzrdir.clone(self.get_url('remote'))
1121
1098
        self.assertRaises(errors.NoWorkingTree,
1122
1099
                          result.open_workingtree)
1123
1100
        result.open_branch()
1133
1110
                              workingtree_4.WorkingTreeFormat4)
1134
1111
 
1135
1112
 
1136
 
class TestHTTPRedirectionsBase(object):
 
1113
class TestHTTPRedirections(object):
1137
1114
    """Test redirection between two http servers.
1138
1115
 
1139
1116
    This MUST be used by daughter classes that also inherit from
1153
1130
        return http_utils.HTTPServerRedirecting()
1154
1131
 
1155
1132
    def setUp(self):
1156
 
        super(TestHTTPRedirectionsBase, self).setUp()
 
1133
        super(TestHTTPRedirections, self).setUp()
1157
1134
        # The redirections will point to the new server
1158
1135
        self.new_server = self.get_readonly_server()
1159
1136
        # The requests to the old server will be redirected
1187
1164
        self.assertIsInstance(bdir.root_transport, type(start))
1188
1165
 
1189
1166
 
1190
 
class TestHTTPRedirections(TestHTTPRedirectionsBase,
1191
 
                           http_utils.TestCaseWithTwoWebservers):
 
1167
class TestHTTPRedirections_urllib(TestHTTPRedirections,
 
1168
                                  http_utils.TestCaseWithTwoWebservers):
1192
1169
    """Tests redirections for urllib implementation"""
1193
1170
 
1194
 
    _transport = HttpTransport
1195
 
 
1196
 
    def _qualified_url(self, host, port):
1197
 
        result = 'http://%s:%s' % (host, port)
1198
 
        self.permit_url(result)
1199
 
        return result
1200
 
 
1201
 
 
1202
 
class TestHTTPRedirections_nosmart(TestHTTPRedirectionsBase,
1203
 
                                   http_utils.TestCaseWithTwoWebservers):
 
1171
    _transport = HttpTransport_urllib
 
1172
 
 
1173
    def _qualified_url(self, host, port):
 
1174
        result = 'http+urllib://%s:%s' % (host, port)
 
1175
        self.permit_url(result)
 
1176
        return result
 
1177
 
 
1178
 
 
1179
 
 
1180
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
 
1181
                                  TestHTTPRedirections,
 
1182
                                  http_utils.TestCaseWithTwoWebservers):
 
1183
    """Tests redirections for pycurl implementation"""
 
1184
 
 
1185
    def _qualified_url(self, host, port):
 
1186
        result = 'http+pycurl://%s:%s' % (host, port)
 
1187
        self.permit_url(result)
 
1188
        return result
 
1189
 
 
1190
 
 
1191
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
 
1192
                                  http_utils.TestCaseWithTwoWebservers):
1204
1193
    """Tests redirections for the nosmart decorator"""
1205
1194
 
1206
1195
    _transport = NoSmartTransportDecorator
1211
1200
        return result
1212
1201
 
1213
1202
 
1214
 
class TestHTTPRedirections_readonly(TestHTTPRedirectionsBase,
 
1203
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1215
1204
                                    http_utils.TestCaseWithTwoWebservers):
1216
1205
    """Tests redirections for readonly decoratror"""
1217
1206
 
1231
1220
 
1232
1221
    def get_ls(self):
1233
1222
        f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
1234
 
                             stderr=subprocess.PIPE)
 
1223
            stderr=subprocess.PIPE)
1235
1224
        out, err = f.communicate()
1236
1225
        self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1237
1226
                         % (self.ls, err))
1238
1227
        return out.splitlines()
1239
1228
 
1240
1229
    def test_dot_bzr_hidden(self):
 
1230
        if sys.platform == 'win32' and not win32utils.has_win32file:
 
1231
            raise TestSkipped('unable to make file hidden without pywin32 library')
1241
1232
        b = bzrdir.BzrDir.create('.')
1242
1233
        self.build_tree(['a'])
1243
 
        self.assertEqual([b'a'], self.get_ls())
 
1234
        self.assertEqual(['a'], self.get_ls())
1244
1235
 
1245
1236
    def test_dot_bzr_hidden_with_url(self):
 
1237
        if sys.platform == 'win32' and not win32utils.has_win32file:
 
1238
            raise TestSkipped('unable to make file hidden without pywin32 library')
1246
1239
        b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1247
1240
        self.build_tree(['a'])
1248
 
        self.assertEqual([b'a'], self.get_ls())
 
1241
        self.assertEqual(['a'], self.get_ls())
1249
1242
 
1250
1243
 
1251
1244
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1274
1267
        return _TestBzrDirFormat()
1275
1268
 
1276
1269
 
1277
 
class _TestBranchFormat(breezy.branch.BranchFormat):
 
1270
class _TestBranchFormat(brzlib.branch.BranchFormat):
1278
1271
    """Test Branch format for TestBzrDirSprout."""
1279
1272
 
1280
1273
 
1281
 
class _TestBranch(breezy.branch.Branch):
 
1274
class _TestBranch(brzlib.branch.Branch):
1282
1275
    """Test Branch implementation for TestBzrDirSprout."""
1283
1276
 
1284
1277
    def __init__(self, transport, *args, **kwargs):
1350
1343
 
1351
1344
    def test_sprout_parent(self):
1352
1345
        grandparent_tree = self.make_branch('grandparent')
1353
 
        parent = grandparent_tree.controldir.sprout('parent').open_branch()
1354
 
        branch_tree = parent.controldir.sprout('branch').open_branch()
 
1346
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
 
1347
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
1355
1348
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1356
1349
 
1357
1350
 
1367
1360
 
1368
1361
    def test_pre_open_actual_exceptions_raised(self):
1369
1362
        count = [0]
1370
 
 
1371
1363
        def fail_once(transport):
1372
1364
            count[0] += 1
1373
1365
            if count[0] == 1:
1379
1371
        self.assertEqual('fail', err._preformatted_string)
1380
1372
 
1381
1373
    def test_post_repo_init(self):
1382
 
        from ..controldir import RepoInitHookParams
 
1374
        from brzlib.controldir import RepoInitHookParams
1383
1375
        calls = []
1384
1376
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1385
 
                                               calls.append, None)
 
1377
            calls.append, None)
1386
1378
        self.make_repository('foo')
1387
1379
        self.assertLength(1, calls)
1388
1380
        params = calls[0]
1389
1381
        self.assertIsInstance(params, RepoInitHookParams)
1390
 
        self.assertTrue(hasattr(params, 'controldir'))
 
1382
        self.assertTrue(hasattr(params, 'bzrdir'))
1391
1383
        self.assertTrue(hasattr(params, 'repository'))
1392
1384
 
1393
1385
    def test_post_repo_init_hook_repr(self):
1394
1386
        param_reprs = []
1395
1387
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
1396
 
                                               lambda params: param_reprs.append(repr(params)), None)
 
1388
            lambda params: param_reprs.append(repr(params)), None)
1397
1389
        self.make_repository('foo')
1398
1390
        self.assertLength(1, param_reprs)
1399
1391
        param_repr = param_reprs[0]
1409
1401
        super(TestGenerateBackupName, self).setUp()
1410
1402
        self._transport = self.get_transport()
1411
1403
        bzrdir.BzrDir.create(self.get_url(),
1412
 
                             possible_transports=[self._transport])
 
1404
            possible_transports=[self._transport])
1413
1405
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1414
1406
 
1415
1407
    def test_new(self):
1416
1408
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
1417
1409
 
1418
1410
    def test_exiting(self):
1419
 
        self._transport.put_bytes("a.~1~", b"some content")
 
1411
        self._transport.put_bytes("a.~1~", "some content")
1420
1412
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1421
1413
 
1422
1414
 
1430
1422
    def test_upgrade_from_2a(self):
1431
1423
        tree = self.make_branch_and_tree('.', format='2a')
1432
1424
        format = bzrdir.BzrDirMetaFormat1Colo()
1433
 
        self.assertTrue(tree.controldir.needs_format_conversion(format))
1434
 
        converter = tree.controldir._format.get_converter(format)
1435
 
        result = converter.convert(tree.controldir, None)
 
1425
        self.assertTrue(tree.bzrdir.needs_format_conversion(format))
 
1426
        converter = tree.bzrdir._format.get_converter(format)
 
1427
        result = converter.convert(tree.bzrdir, None)
1436
1428
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1437
1429
        self.assertFalse(result.needs_format_conversion(format))
1438
1430
 
1439
1431
    def test_downgrade_to_2a(self):
1440
1432
        tree = self.make_branch_and_tree('.', format='development-colo')
1441
1433
        format = bzrdir.BzrDirMetaFormat1()
1442
 
        self.assertTrue(tree.controldir.needs_format_conversion(format))
1443
 
        converter = tree.controldir._format.get_converter(format)
1444
 
        result = converter.convert(tree.controldir, None)
 
1434
        self.assertTrue(tree.bzrdir.needs_format_conversion(format))
 
1435
        converter = tree.bzrdir._format.get_converter(format)
 
1436
        result = converter.convert(tree.bzrdir, None)
1445
1437
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1446
1438
        self.assertFalse(result.needs_format_conversion(format))
1447
1439
 
1448
1440
    def test_downgrade_to_2a_too_many_branches(self):
1449
1441
        tree = self.make_branch_and_tree('.', format='development-colo')
1450
 
        tree.controldir.create_branch(name="another-colocated-branch")
1451
 
        converter = tree.controldir._format.get_converter(
 
1442
        tree.bzrdir.create_branch(name="another-colocated-branch")
 
1443
        converter = tree.bzrdir._format.get_converter(
1452
1444
            bzrdir.BzrDirMetaFormat1())
1453
 
        result = converter.convert(tree.controldir, bzrdir.BzrDirMetaFormat1())
 
1445
        result = converter.convert(tree.bzrdir, bzrdir.BzrDirMetaFormat1())
1454
1446
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1455
1447
 
1456
1448
    def test_nested(self):
1457
1449
        tree = self.make_branch_and_tree('.', format='development-colo')
1458
 
        tree.controldir.create_branch(name='foo')
1459
 
        tree.controldir.create_branch(name='fool/bla')
 
1450
        tree.bzrdir.create_branch(name='foo')
 
1451
        tree.bzrdir.create_branch(name='fool/bla')
1460
1452
        self.assertRaises(
1461
 
            errors.ParentBranchExists, tree.controldir.create_branch,
 
1453
            errors.ParentBranchExists, tree.bzrdir.create_branch,
1462
1454
            name='foo/bar')
1463
1455
 
1464
1456
    def test_parent(self):
1465
1457
        tree = self.make_branch_and_tree('.', format='development-colo')
1466
 
        tree.controldir.create_branch(name='fool/bla')
1467
 
        tree.controldir.create_branch(name='foo/bar')
 
1458
        tree.bzrdir.create_branch(name='fool/bla')
 
1459
        tree.bzrdir.create_branch(name='foo/bar')
1468
1460
        self.assertRaises(
1469
 
            errors.AlreadyBranchError, tree.controldir.create_branch,
 
1461
            errors.AlreadyBranchError, tree.bzrdir.create_branch,
1470
1462
            name='foo')
1471
1463
 
1472
 
    def test_supports_relative_reference(self):
1473
 
        tree = self.make_branch_and_tree('.', format='development-colo')
1474
 
        target1 = tree.controldir.create_branch(name='target1')
1475
 
        target2 = tree.controldir.create_branch(name='target2')
1476
 
        source = tree.controldir.set_branch_reference(target1, name='source')
1477
 
        self.assertEqual(
1478
 
            target1.user_url, tree.controldir.open_branch('source').user_url)
1479
 
        source.controldir.get_branch_transport(None, 'source').put_bytes(
1480
 
            'location', b'file:,branch=target2')
1481
 
        self.assertEqual(
1482
 
            target2.user_url, tree.controldir.open_branch('source').user_url)
1483
 
 
1484
1464
 
1485
1465
class SampleBzrFormat(bzrdir.BzrFormat):
1486
1466
 
1487
1467
    @classmethod
1488
1468
    def get_format_string(cls):
1489
 
        return b"First line\n"
 
1469
        return "First line\n"
1490
1470
 
1491
1471
 
1492
1472
class TestBzrFormat(TestCase):
1494
1474
 
1495
1475
    def test_as_string(self):
1496
1476
        format = SampleBzrFormat()
1497
 
        format.features = {b"foo": b"required"}
1498
 
        self.assertEqual(format.as_string(),
1499
 
                         b"First line\n"
1500
 
                         b"required foo\n")
1501
 
        format.features[b"another"] = b"optional"
1502
 
        self.assertEqual(format.as_string(),
1503
 
                         b"First line\n"
1504
 
                         b"optional another\n"
1505
 
                         b"required foo\n")
 
1477
        format.features = {"foo": "required"}
 
1478
        self.assertEqual(format.as_string(),
 
1479
            "First line\n"
 
1480
            "required foo\n")
 
1481
        format.features["another"] = "optional"
 
1482
        self.assertEqual(format.as_string(),
 
1483
            "First line\n"
 
1484
            "required foo\n"
 
1485
            "optional another\n")
1506
1486
 
1507
1487
    def test_network_name(self):
1508
1488
        # The network string should include the feature info
1509
1489
        format = SampleBzrFormat()
1510
 
        format.features = {b"foo": b"required"}
 
1490
        format.features = {"foo": "required"}
1511
1491
        self.assertEqual(
1512
 
            b"First line\nrequired foo\n",
 
1492
            "First line\nrequired foo\n",
1513
1493
            format.network_name())
1514
1494
 
1515
1495
    def test_from_string_no_features(self):
1516
1496
        # No features
1517
1497
        format = SampleBzrFormat.from_string(
1518
 
            b"First line\n")
 
1498
            "First line\n")
1519
1499
        self.assertEqual({}, format.features)
1520
1500
 
1521
1501
    def test_from_string_with_feature(self):
1522
1502
        # Proper feature
1523
1503
        format = SampleBzrFormat.from_string(
1524
 
            b"First line\nrequired foo\n")
1525
 
        self.assertEqual(b"required", format.features.get(b"foo"))
 
1504
            "First line\nrequired foo\n")
 
1505
        self.assertEqual("required", format.features.get("foo"))
1526
1506
 
1527
1507
    def test_from_string_format_string_mismatch(self):
1528
1508
        # The first line has to match the format string
1529
1509
        self.assertRaises(AssertionError, SampleBzrFormat.from_string,
1530
 
                          b"Second line\nrequired foo\n")
 
1510
            "Second line\nrequired foo\n")
1531
1511
 
1532
1512
    def test_from_string_missing_space(self):
1533
1513
        # At least one space is required in the feature lines
1534
1514
        self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
1535
 
                          b"First line\nfoo\n")
 
1515
            "First line\nfoo\n")
1536
1516
 
1537
1517
    def test_from_string_with_spaces(self):
1538
1518
        # Feature with spaces (in case we add stuff like this in the future)
1539
1519
        format = SampleBzrFormat.from_string(
1540
 
            b"First line\nrequired foo with spaces\n")
1541
 
        self.assertEqual(b"required", format.features.get(b"foo with spaces"))
 
1520
            "First line\nrequired foo with spaces\n")
 
1521
        self.assertEqual("required", format.features.get("foo with spaces"))
1542
1522
 
1543
1523
    def test_eq(self):
1544
1524
        format1 = SampleBzrFormat()
1545
 
        format1.features = {b"nested-trees": b"optional"}
 
1525
        format1.features = {"nested-trees": "optional"}
1546
1526
        format2 = SampleBzrFormat()
1547
 
        format2.features = {b"nested-trees": b"optional"}
 
1527
        format2.features = {"nested-trees": "optional"}
1548
1528
        self.assertEqual(format1, format1)
1549
1529
        self.assertEqual(format1, format2)
1550
1530
        format3 = SampleBzrFormat()
1553
1533
    def test_check_support_status_optional(self):
1554
1534
        # Optional, so silently ignore
1555
1535
        format = SampleBzrFormat()
1556
 
        format.features = {b"nested-trees": b"optional"}
 
1536
        format.features = {"nested-trees": "optional"}
1557
1537
        format.check_support_status(True)
1558
 
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1559
 
        SampleBzrFormat.register_feature(b"nested-trees")
 
1538
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1539
        SampleBzrFormat.register_feature("nested-trees")
1560
1540
        format.check_support_status(True)
1561
1541
 
1562
1542
    def test_check_support_status_required(self):
1563
1543
        # Optional, so trigger an exception
1564
1544
        format = SampleBzrFormat()
1565
 
        format.features = {b"nested-trees": b"required"}
1566
 
        self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1567
 
                          True)
1568
 
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1569
 
        SampleBzrFormat.register_feature(b"nested-trees")
 
1545
        format.features = {"nested-trees": "required"}
 
1546
        self.assertRaises(errors.MissingFeature, format.check_support_status,
 
1547
            True)
 
1548
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1549
        SampleBzrFormat.register_feature("nested-trees")
1570
1550
        format.check_support_status(True)
1571
1551
 
1572
1552
    def test_check_support_status_unknown(self):
1573
1553
        # treat unknown necessity as required
1574
1554
        format = SampleBzrFormat()
1575
 
        format.features = {b"nested-trees": b"unknown"}
1576
 
        self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
1577
 
                          True)
1578
 
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1579
 
        SampleBzrFormat.register_feature(b"nested-trees")
 
1555
        format.features = {"nested-trees": "unknown"}
 
1556
        self.assertRaises(errors.MissingFeature, format.check_support_status,
 
1557
            True)
 
1558
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1559
        SampleBzrFormat.register_feature("nested-trees")
1580
1560
        format.check_support_status(True)
1581
1561
 
1582
1562
    def test_feature_already_registered(self):
1583
1563
        # a feature can only be registered once
1584
 
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1585
 
        SampleBzrFormat.register_feature(b"nested-trees")
1586
 
        self.assertRaises(bzrdir.FeatureAlreadyRegistered,
1587
 
                          SampleBzrFormat.register_feature, b"nested-trees")
 
1564
        self.addCleanup(SampleBzrFormat.unregister_feature, "nested-trees")
 
1565
        SampleBzrFormat.register_feature("nested-trees")
 
1566
        self.assertRaises(errors.FeatureAlreadyRegistered,
 
1567
            SampleBzrFormat.register_feature, "nested-trees")
1588
1568
 
1589
1569
    def test_feature_with_space(self):
1590
1570
        # spaces are not allowed in feature names
1591
1571
        self.assertRaises(ValueError, SampleBzrFormat.register_feature,
1592
 
                          b"nested trees")
 
1572
            "nested trees")