1
# Copyright (C) 2005, 2006 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Tests for the BzrDir facility and any format specific tests.
19
For interface contract tests, see tests/bzr_dir_implementations.
22
from StringIO import StringIO
29
import bzrlib.bzrdir as bzrdir
30
import bzrlib.errors as errors
31
from bzrlib.errors import (NotBranchError,
33
UnsupportedFormatError,
35
import bzrlib.repository as repository
36
from bzrlib.tests import TestCase, TestCaseWithTransport
37
from bzrlib.tests.HttpServer import HttpServer
38
from bzrlib.transport import get_transport
39
from bzrlib.transport.memory import MemoryServer
40
import bzrlib.workingtree as workingtree
43
class TestDefaultFormat(TestCase):
45
def test_get_set_default_format(self):
46
old_format = bzrdir.BzrDirFormat.get_default_format()
47
# default is BzrDirFormat6
48
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
49
self.applyDeprecated(symbol_versioning.zero_fourteen,
50
bzrdir.BzrDirFormat.set_default_format,
52
# creating a bzr dir should now create an instrumented dir.
54
result = bzrdir.BzrDir.create('memory:///')
55
self.failUnless(isinstance(result, SampleBzrDir))
57
self.applyDeprecated(symbol_versioning.zero_fourteen,
58
bzrdir.BzrDirFormat.set_default_format, old_format)
59
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
62
class TestFormatRegistry(TestCase):
64
def make_format_registry(self):
65
my_format_registry = bzrdir.BzrDirFormatRegistry()
66
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
67
'Pre-0.8 format. Slower and does not support checkouts or shared'
68
' repositories', deprecated=True)
69
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
70
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
71
my_format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
73
my_format_registry.register_metadir('experimental-knit3',
74
'RepositoryFormatKnit2',
76
tree='WorkingTreeFormat4')
77
my_format_registry.set_default('knit')
78
my_format_registry.register_metadir('metaweave', 'RepositoryFormat7',
79
'Transitional format in 0.8. Slower than knit.', deprecated=True)
80
my_format_registry.register_metadir('experimental-knit2',
81
'RepositoryFormatKnit2',
82
'Experimental successor to knit. Use at your own risk.')
83
return my_format_registry
85
def test_format_registry(self):
86
my_format_registry = self.make_format_registry()
87
my_bzrdir = my_format_registry.make_bzrdir('lazy')
88
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
89
my_bzrdir = my_format_registry.make_bzrdir('weave')
90
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
91
my_bzrdir = my_format_registry.make_bzrdir('default')
92
self.assertIsInstance(my_bzrdir.repository_format,
93
repository.RepositoryFormatKnit1)
94
my_bzrdir = my_format_registry.make_bzrdir('knit')
95
self.assertIsInstance(my_bzrdir.repository_format,
96
repository.RepositoryFormatKnit1)
97
my_bzrdir = my_format_registry.make_bzrdir('metaweave')
98
self.assertIsInstance(my_bzrdir.repository_format,
99
repository.RepositoryFormat7)
100
self.assertIsInstance(my_bzrdir.workingtree_format,
101
workingtree.WorkingTreeFormat3)
102
my_bzrdir = my_format_registry.make_bzrdir('experimental-knit3')
103
self.assertIsInstance(my_bzrdir.repository_format,
104
repository.RepositoryFormatKnit2)
105
self.assertIsInstance(my_bzrdir.workingtree_format,
106
workingtree.WorkingTreeFormat4)
108
def test_get_help(self):
109
my_format_registry = self.make_format_registry()
110
self.assertEqual('Format registered lazily',
111
my_format_registry.get_help('lazy'))
112
self.assertEqual('Format using knits',
113
my_format_registry.get_help('knit'))
114
self.assertEqual('Format using knits',
115
my_format_registry.get_help('default'))
116
self.assertEqual('Pre-0.8 format. Slower and does not support'
117
' checkouts or shared repositories',
118
my_format_registry.get_help('weave'))
120
def test_help_topic(self):
121
topics = help_topics.HelpTopicRegistry()
122
topics.register('formats', self.make_format_registry().help_topic,
124
topic = topics.get_detail('formats')
125
new, deprecated = topic.split('Deprecated formats')
126
self.assertContainsRe(new, 'Bazaar directory formats')
127
self.assertContainsRe(new,
128
' knit/default:\n \(native\) Format using knits\n')
129
self.assertContainsRe(deprecated,
130
' lazy:\n \(native\) Format registered lazily\n')
132
def test_set_default_repository(self):
133
default_factory = bzrdir.format_registry.get('default')
134
old_default = [k for k, v in bzrdir.format_registry.iteritems()
135
if v == default_factory and k != 'default'][0]
136
bzrdir.format_registry.set_default_repository('metaweave')
138
self.assertIs(bzrdir.format_registry.get('metaweave'),
139
bzrdir.format_registry.get('default'))
141
repository.RepositoryFormat.get_default_format().__class__,
142
repository.RepositoryFormat7)
144
bzrdir.format_registry.set_default_repository(old_default)
146
class SampleBranch(bzrlib.branch.Branch):
147
"""A dummy branch for guess what, dummy use."""
149
def __init__(self, dir):
153
class SampleBzrDir(bzrdir.BzrDir):
154
"""A sample BzrDir implementation to allow testing static methods."""
156
def create_repository(self, shared=False):
157
"""See BzrDir.create_repository."""
158
return "A repository"
160
def open_repository(self):
161
"""See BzrDir.open_repository."""
162
return "A repository"
164
def create_branch(self):
165
"""See BzrDir.create_branch."""
166
return SampleBranch(self)
168
def create_workingtree(self):
169
"""See BzrDir.create_workingtree."""
173
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
176
this format is initializable, unsupported to aid in testing the
177
open and open_downlevel routines.
180
def get_format_string(self):
181
"""See BzrDirFormat.get_format_string()."""
182
return "Sample .bzr dir format."
184
def initialize(self, url):
185
"""Create a bzr dir."""
186
t = get_transport(url)
188
t.put_bytes('.bzr/branch-format', self.get_format_string())
189
return SampleBzrDir(t, self)
191
def is_supported(self):
194
def open(self, transport, _found=None):
195
return "opened branch."
198
class TestBzrDirFormat(TestCaseWithTransport):
199
"""Tests for the BzrDirFormat facility."""
201
def test_find_format(self):
202
# is the right format object found for a branch?
203
# create a branch with a few known format objects.
204
# this is not quite the same as
205
t = get_transport(self.get_url())
206
self.build_tree(["foo/", "bar/"], transport=t)
207
def check_format(format, url):
208
format.initialize(url)
209
t = get_transport(url)
210
found_format = bzrdir.BzrDirFormat.find_format(t)
211
self.failUnless(isinstance(found_format, format.__class__))
212
check_format(bzrdir.BzrDirFormat5(), "foo")
213
check_format(bzrdir.BzrDirFormat6(), "bar")
215
def test_find_format_nothing_there(self):
216
self.assertRaises(NotBranchError,
217
bzrdir.BzrDirFormat.find_format,
220
def test_find_format_unknown_format(self):
221
t = get_transport(self.get_url())
223
t.put_bytes('.bzr/branch-format', '')
224
self.assertRaises(UnknownFormatError,
225
bzrdir.BzrDirFormat.find_format,
228
def test_register_unregister_format(self):
229
format = SampleBzrDirFormat()
232
format.initialize(url)
233
# register a format for it.
234
bzrdir.BzrDirFormat.register_format(format)
235
# which bzrdir.Open will refuse (not supported)
236
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
237
# which bzrdir.open_containing will refuse (not supported)
238
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
239
# but open_downlevel will work
240
t = get_transport(url)
241
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
242
# unregister the format
243
bzrdir.BzrDirFormat.unregister_format(format)
244
# now open_downlevel should fail too.
245
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
247
def test_create_repository(self):
248
format = SampleBzrDirFormat()
249
repo = bzrdir.BzrDir.create_repository(self.get_url(), format=format)
250
self.assertEqual('A repository', repo)
252
def test_create_repository_shared(self):
253
old_format = bzrdir.BzrDirFormat.get_default_format()
254
repo = bzrdir.BzrDir.create_repository('.', shared=True)
255
self.assertTrue(repo.is_shared())
257
def test_create_repository_nonshared(self):
258
old_format = bzrdir.BzrDirFormat.get_default_format()
259
repo = bzrdir.BzrDir.create_repository('.')
260
self.assertFalse(repo.is_shared())
262
def test_create_repository_under_shared(self):
263
# an explicit create_repository always does so.
264
# we trust the format is right from the 'create_repository test'
265
format = bzrdir.format_registry.make_bzrdir('knit')
266
self.make_repository('.', shared=True, format=format)
267
repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
269
self.assertTrue(isinstance(repo, repository.Repository))
270
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
272
def test_create_branch_and_repo_uses_default(self):
273
format = SampleBzrDirFormat()
274
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
276
self.assertTrue(isinstance(branch, SampleBranch))
278
def test_create_branch_and_repo_under_shared(self):
279
# creating a branch and repo in a shared repo uses the
281
format = bzrdir.format_registry.make_bzrdir('knit')
282
self.make_repository('.', shared=True, format=format)
283
branch = bzrdir.BzrDir.create_branch_and_repo(
284
self.get_url('child'), format=format)
285
self.assertRaises(errors.NoRepositoryPresent,
286
branch.bzrdir.open_repository)
288
def test_create_branch_and_repo_under_shared_force_new(self):
289
# creating a branch and repo in a shared repo can be forced to
291
format = bzrdir.format_registry.make_bzrdir('knit')
292
self.make_repository('.', shared=True, format=format)
293
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
296
branch.bzrdir.open_repository()
298
def test_create_standalone_working_tree(self):
299
format = SampleBzrDirFormat()
300
# note this is deliberately readonly, as this failure should
301
# occur before any writes.
302
self.assertRaises(errors.NotLocalUrl,
303
bzrdir.BzrDir.create_standalone_workingtree,
304
self.get_readonly_url(), format=format)
305
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
307
self.assertEqual('A tree', tree)
309
def test_create_standalone_working_tree_under_shared_repo(self):
310
# create standalone working tree always makes a repo.
311
format = bzrdir.format_registry.make_bzrdir('knit')
312
self.make_repository('.', shared=True, format=format)
313
# note this is deliberately readonly, as this failure should
314
# occur before any writes.
315
self.assertRaises(errors.NotLocalUrl,
316
bzrdir.BzrDir.create_standalone_workingtree,
317
self.get_readonly_url('child'), format=format)
318
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
320
tree.bzrdir.open_repository()
322
def test_create_branch_convenience(self):
323
# outside a repo the default convenience output is a repo+branch_tree
324
format = bzrdir.format_registry.make_bzrdir('knit')
325
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
326
branch.bzrdir.open_workingtree()
327
branch.bzrdir.open_repository()
329
def test_create_branch_convenience_root(self):
330
"""Creating a branch at the root of a fs should work."""
331
self.transport_server = MemoryServer
332
# outside a repo the default convenience output is a repo+branch_tree
333
format = bzrdir.format_registry.make_bzrdir('knit')
334
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
336
self.assertRaises(errors.NoWorkingTree,
337
branch.bzrdir.open_workingtree)
338
branch.bzrdir.open_repository()
340
def test_create_branch_convenience_under_shared_repo(self):
341
# inside a repo the default convenience output is a branch+ follow the
343
format = bzrdir.format_registry.make_bzrdir('knit')
344
self.make_repository('.', shared=True, format=format)
345
branch = bzrdir.BzrDir.create_branch_convenience('child',
347
branch.bzrdir.open_workingtree()
348
self.assertRaises(errors.NoRepositoryPresent,
349
branch.bzrdir.open_repository)
351
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
352
# inside a repo the default convenience output is a branch+ follow the
353
# repo tree policy but we can override that
354
format = bzrdir.format_registry.make_bzrdir('knit')
355
self.make_repository('.', shared=True, format=format)
356
branch = bzrdir.BzrDir.create_branch_convenience('child',
357
force_new_tree=False, format=format)
358
self.assertRaises(errors.NoWorkingTree,
359
branch.bzrdir.open_workingtree)
360
self.assertRaises(errors.NoRepositoryPresent,
361
branch.bzrdir.open_repository)
363
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
364
# inside a repo the default convenience output is a branch+ follow the
366
format = bzrdir.format_registry.make_bzrdir('knit')
367
repo = self.make_repository('.', shared=True, format=format)
368
repo.set_make_working_trees(False)
369
branch = bzrdir.BzrDir.create_branch_convenience('child',
371
self.assertRaises(errors.NoWorkingTree,
372
branch.bzrdir.open_workingtree)
373
self.assertRaises(errors.NoRepositoryPresent,
374
branch.bzrdir.open_repository)
376
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
377
# inside a repo the default convenience output is a branch+ follow the
378
# repo tree policy but we can override that
379
format = bzrdir.format_registry.make_bzrdir('knit')
380
repo = self.make_repository('.', shared=True, format=format)
381
repo.set_make_working_trees(False)
382
branch = bzrdir.BzrDir.create_branch_convenience('child',
383
force_new_tree=True, format=format)
384
branch.bzrdir.open_workingtree()
385
self.assertRaises(errors.NoRepositoryPresent,
386
branch.bzrdir.open_repository)
388
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
389
# inside a repo the default convenience output is overridable to give
391
format = bzrdir.format_registry.make_bzrdir('knit')
392
self.make_repository('.', shared=True, format=format)
393
branch = bzrdir.BzrDir.create_branch_convenience('child',
394
force_new_repo=True, format=format)
395
branch.bzrdir.open_repository()
396
branch.bzrdir.open_workingtree()
399
class ChrootedTests(TestCaseWithTransport):
400
"""A support class that provides readonly urls outside the local namespace.
402
This is done by checking if self.transport_server is a MemoryServer. if it
403
is then we are chrooted already, if it is not then an HttpServer is used
408
super(ChrootedTests, self).setUp()
409
if not self.transport_server == MemoryServer:
410
self.transport_readonly_server = HttpServer
412
def test_open_containing(self):
413
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
414
self.get_readonly_url(''))
415
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
416
self.get_readonly_url('g/p/q'))
417
control = bzrdir.BzrDir.create(self.get_url())
418
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
419
self.assertEqual('', relpath)
420
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
421
self.assertEqual('g/p/q', relpath)
423
def test_open_containing_from_transport(self):
424
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
425
get_transport(self.get_readonly_url('')))
426
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
427
get_transport(self.get_readonly_url('g/p/q')))
428
control = bzrdir.BzrDir.create(self.get_url())
429
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
430
get_transport(self.get_readonly_url('')))
431
self.assertEqual('', relpath)
432
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
433
get_transport(self.get_readonly_url('g/p/q')))
434
self.assertEqual('g/p/q', relpath)
436
def test_open_from_transport(self):
437
# transport pointing at bzrdir should give a bzrdir with root transport
438
# set to the given transport
439
control = bzrdir.BzrDir.create(self.get_url())
440
transport = get_transport(self.get_url())
441
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
442
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
443
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
445
def test_open_from_transport_no_bzrdir(self):
446
transport = get_transport(self.get_url())
447
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
450
def test_open_from_transport_bzrdir_in_parent(self):
451
control = bzrdir.BzrDir.create(self.get_url())
452
transport = get_transport(self.get_url())
453
transport.mkdir('subdir')
454
transport = transport.clone('subdir')
455
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
459
class TestMeta1DirFormat(TestCaseWithTransport):
460
"""Tests specific to the meta1 dir format."""
462
def test_right_base_dirs(self):
463
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
465
branch_base = t.clone('branch').base
466
self.assertEqual(branch_base, dir.get_branch_transport(None).base)
467
self.assertEqual(branch_base,
468
dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
469
repository_base = t.clone('repository').base
470
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
471
self.assertEqual(repository_base,
472
dir.get_repository_transport(repository.RepositoryFormat7()).base)
473
checkout_base = t.clone('checkout').base
474
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
475
self.assertEqual(checkout_base,
476
dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
478
def test_meta1dir_uses_lockdir(self):
479
"""Meta1 format uses a LockDir to guard the whole directory, not a file."""
480
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
482
self.assertIsDirectory('branch-lock', t)
485
class TestFormat5(TestCaseWithTransport):
486
"""Tests specific to the version 5 bzrdir format."""
488
def test_same_lockfiles_between_tree_repo_branch(self):
489
# this checks that only a single lockfiles instance is created
490
# for format 5 objects
491
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
492
def check_dir_components_use_same_lock(dir):
493
ctrl_1 = dir.open_repository().control_files
494
ctrl_2 = dir.open_branch().control_files
495
ctrl_3 = dir.open_workingtree()._control_files
496
self.assertTrue(ctrl_1 is ctrl_2)
497
self.assertTrue(ctrl_2 is ctrl_3)
498
check_dir_components_use_same_lock(dir)
499
# and if we open it normally.
500
dir = bzrdir.BzrDir.open(self.get_url())
501
check_dir_components_use_same_lock(dir)
503
def test_can_convert(self):
504
# format 5 dirs are convertable
505
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
506
self.assertTrue(dir.can_convert_format())
508
def test_needs_conversion(self):
509
# format 5 dirs need a conversion if they are not the default.
510
# and they start of not the default.
511
old_format = bzrdir.BzrDirFormat.get_default_format()
512
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
514
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
515
self.assertFalse(dir.needs_format_conversion())
517
bzrdir.BzrDirFormat._set_default_format(old_format)
518
self.assertTrue(dir.needs_format_conversion())
521
class TestFormat6(TestCaseWithTransport):
522
"""Tests specific to the version 6 bzrdir format."""
524
def test_same_lockfiles_between_tree_repo_branch(self):
525
# this checks that only a single lockfiles instance is created
526
# for format 6 objects
527
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
528
def check_dir_components_use_same_lock(dir):
529
ctrl_1 = dir.open_repository().control_files
530
ctrl_2 = dir.open_branch().control_files
531
ctrl_3 = dir.open_workingtree()._control_files
532
self.assertTrue(ctrl_1 is ctrl_2)
533
self.assertTrue(ctrl_2 is ctrl_3)
534
check_dir_components_use_same_lock(dir)
535
# and if we open it normally.
536
dir = bzrdir.BzrDir.open(self.get_url())
537
check_dir_components_use_same_lock(dir)
539
def test_can_convert(self):
540
# format 6 dirs are convertable
541
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
542
self.assertTrue(dir.can_convert_format())
544
def test_needs_conversion(self):
545
# format 6 dirs need an conversion if they are not the default.
546
old_format = bzrdir.BzrDirFormat.get_default_format()
547
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
549
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
550
self.assertTrue(dir.needs_format_conversion())
552
bzrdir.BzrDirFormat._set_default_format(old_format)
555
class NotBzrDir(bzrlib.bzrdir.BzrDir):
556
"""A non .bzr based control directory."""
558
def __init__(self, transport, format):
559
self._format = format
560
self.root_transport = transport
561
self.transport = transport.clone('.not')
564
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
565
"""A test class representing any non-.bzr based disk format."""
567
def initialize_on_transport(self, transport):
568
"""Initialize a new .not dir in the base directory of a Transport."""
569
transport.mkdir('.not')
570
return self.open(transport)
572
def open(self, transport):
573
"""Open this directory."""
574
return NotBzrDir(transport, self)
577
def _known_formats(self):
578
return set([NotBzrDirFormat()])
581
def probe_transport(self, transport):
582
"""Our format is present if the transport ends in '.not/'."""
583
if transport.has('.not'):
584
return NotBzrDirFormat()
587
class TestNotBzrDir(TestCaseWithTransport):
588
"""Tests for using the bzrdir api with a non .bzr based disk format.
590
If/when one of these is in the core, we can let the implementation tests
594
def test_create_and_find_format(self):
595
# create a .notbzr dir
596
format = NotBzrDirFormat()
597
dir = format.initialize(self.get_url())
598
self.assertIsInstance(dir, NotBzrDir)
600
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
602
found = bzrlib.bzrdir.BzrDirFormat.find_format(
603
get_transport(self.get_url()))
604
self.assertIsInstance(found, NotBzrDirFormat)
606
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
608
def test_included_in_known_formats(self):
609
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
611
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
612
for format in formats:
613
if isinstance(format, NotBzrDirFormat):
615
self.fail("No NotBzrDirFormat in %s" % formats)
617
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
620
class NonLocalTests(TestCaseWithTransport):
621
"""Tests for bzrdir static behaviour on non local paths."""
624
super(NonLocalTests, self).setUp()
625
self.transport_server = MemoryServer
627
def test_create_branch_convenience(self):
628
# outside a repo the default convenience output is a repo+branch_tree
629
format = bzrdir.format_registry.make_bzrdir('knit')
630
branch = bzrdir.BzrDir.create_branch_convenience(
631
self.get_url('foo'), format=format)
632
self.assertRaises(errors.NoWorkingTree,
633
branch.bzrdir.open_workingtree)
634
branch.bzrdir.open_repository()
636
def test_create_branch_convenience_force_tree_not_local_fails(self):
637
# outside a repo the default convenience output is a repo+branch_tree
638
format = bzrdir.format_registry.make_bzrdir('knit')
639
self.assertRaises(errors.NotLocalUrl,
640
bzrdir.BzrDir.create_branch_convenience,
644
t = get_transport(self.get_url('.'))
645
self.assertFalse(t.has('foo'))
647
def test_clone(self):
648
# clone into a nonlocal path works
649
format = bzrdir.format_registry.make_bzrdir('knit')
650
branch = bzrdir.BzrDir.create_branch_convenience('local',
652
branch.bzrdir.open_workingtree()
653
result = branch.bzrdir.clone(self.get_url('remote'))
654
self.assertRaises(errors.NoWorkingTree,
655
result.open_workingtree)
657
result.open_repository()