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

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

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