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.
23
from StringIO import StringIO
31
import bzrlib.bzrdir as bzrdir
32
import bzrlib.errors as errors
33
from bzrlib.errors import (NotBranchError,
35
UnsupportedFormatError,
37
import bzrlib.repository as repository
38
from bzrlib.tests import TestCase, TestCaseWithTransport, test_sftp_transport
39
from bzrlib.tests.HttpServer import HttpServer
40
from bzrlib.transport import get_transport
41
from bzrlib.transport.memory import MemoryServer
42
import bzrlib.workingtree as workingtree
45
class TestDefaultFormat(TestCase):
47
def test_get_set_default_format(self):
48
old_format = bzrdir.BzrDirFormat.get_default_format()
49
# default is BzrDirFormat6
50
self.failUnless(isinstance(old_format, bzrdir.BzrDirMetaFormat1))
51
self.applyDeprecated(symbol_versioning.zero_fourteen,
52
bzrdir.BzrDirFormat.set_default_format,
54
# creating a bzr dir should now create an instrumented dir.
56
result = bzrdir.BzrDir.create('memory:///')
57
self.failUnless(isinstance(result, SampleBzrDir))
59
self.applyDeprecated(symbol_versioning.zero_fourteen,
60
bzrdir.BzrDirFormat.set_default_format, old_format)
61
self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
64
class TestFormatRegistry(TestCase):
66
def make_format_registry(self):
67
my_format_registry = bzrdir.BzrDirFormatRegistry()
68
my_format_registry.register('weave', bzrdir.BzrDirFormat6,
69
'Pre-0.8 format. Slower and does not support checkouts or shared'
70
' repositories', deprecated=True)
71
my_format_registry.register_lazy('lazy', 'bzrlib.bzrdir',
72
'BzrDirFormat6', 'Format registered lazily', deprecated=True)
73
my_format_registry.register_metadir('knit', 'RepositoryFormatKnit1',
75
my_format_registry.set_default('knit')
76
my_format_registry.register_metadir('metaweave', 'RepositoryFormat7',
77
'Transitional format in 0.8. Slower than knit.', deprecated=True)
78
my_format_registry.register_metadir('experimental-knit2',
79
'RepositoryFormatKnit2',
80
'Experimental successor to knit. Use at your own risk.')
81
my_format_registry.register_metadir('branch6',
82
'RepositoryFormatKnit2',
83
'Experimental successor to knit. Use at your own risk.',
84
branch_format='BzrBranchFormat6')
85
return my_format_registry
87
def test_format_registry(self):
88
my_format_registry = self.make_format_registry()
89
my_bzrdir = my_format_registry.make_bzrdir('lazy')
90
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
91
my_bzrdir = my_format_registry.make_bzrdir('weave')
92
self.assertIsInstance(my_bzrdir, bzrdir.BzrDirFormat6)
93
my_bzrdir = my_format_registry.make_bzrdir('default')
94
self.assertIsInstance(my_bzrdir.repository_format,
95
repository.RepositoryFormatKnit1)
96
my_bzrdir = my_format_registry.make_bzrdir('knit')
97
self.assertIsInstance(my_bzrdir.repository_format,
98
repository.RepositoryFormatKnit1)
99
my_bzrdir = my_format_registry.make_bzrdir('metaweave')
100
self.assertIsInstance(my_bzrdir.repository_format,
101
repository.RepositoryFormat7)
102
my_bzrdir = my_format_registry.make_bzrdir('branch6')
103
self.assertIsInstance(my_bzrdir.branch_format,
104
bzrlib.branch.BzrBranchFormat6)
106
def test_get_help(self):
107
my_format_registry = self.make_format_registry()
108
self.assertEqual('Format registered lazily',
109
my_format_registry.get_help('lazy'))
110
self.assertEqual('Format using knits',
111
my_format_registry.get_help('knit'))
112
self.assertEqual('Format using knits',
113
my_format_registry.get_help('default'))
114
self.assertEqual('Pre-0.8 format. Slower and does not support'
115
' checkouts or shared repositories',
116
my_format_registry.get_help('weave'))
118
def test_help_topic(self):
119
topics = help_topics.HelpTopicRegistry()
120
topics.register('formats', self.make_format_registry().help_topic,
122
topic = topics.get_detail('formats')
123
new, deprecated = topic.split('Deprecated formats')
124
self.assertContainsRe(new, 'Bazaar directory formats')
125
self.assertContainsRe(new,
126
' knit/default:\n \(native\) Format using knits\n')
127
self.assertContainsRe(deprecated,
128
' lazy:\n \(native\) Format registered lazily\n')
130
def test_set_default_repository(self):
131
default_factory = bzrdir.format_registry.get('default')
132
old_default = [k for k, v in bzrdir.format_registry.iteritems()
133
if v == default_factory and k != 'default'][0]
134
bzrdir.format_registry.set_default_repository('metaweave')
136
self.assertIs(bzrdir.format_registry.get('metaweave'),
137
bzrdir.format_registry.get('default'))
139
repository.RepositoryFormat.get_default_format().__class__,
140
repository.RepositoryFormat7)
142
bzrdir.format_registry.set_default_repository(old_default)
144
class SampleBranch(bzrlib.branch.Branch):
145
"""A dummy branch for guess what, dummy use."""
147
def __init__(self, dir):
151
class SampleBzrDir(bzrdir.BzrDir):
152
"""A sample BzrDir implementation to allow testing static methods."""
154
def create_repository(self, shared=False):
155
"""See BzrDir.create_repository."""
156
return "A repository"
158
def open_repository(self):
159
"""See BzrDir.open_repository."""
160
return "A repository"
162
def create_branch(self):
163
"""See BzrDir.create_branch."""
164
return SampleBranch(self)
166
def create_workingtree(self):
167
"""See BzrDir.create_workingtree."""
171
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
174
this format is initializable, unsupported to aid in testing the
175
open and open_downlevel routines.
178
def get_format_string(self):
179
"""See BzrDirFormat.get_format_string()."""
180
return "Sample .bzr dir format."
182
def initialize(self, url):
183
"""Create a bzr dir."""
184
t = get_transport(url)
186
t.put_bytes('.bzr/branch-format', self.get_format_string())
187
return SampleBzrDir(t, self)
189
def is_supported(self):
192
def open(self, transport, _found=None):
193
return "opened branch."
196
class TestBzrDirFormat(TestCaseWithTransport):
197
"""Tests for the BzrDirFormat facility."""
199
def test_find_format(self):
200
# is the right format object found for a branch?
201
# create a branch with a few known format objects.
202
# this is not quite the same as
203
t = get_transport(self.get_url())
204
self.build_tree(["foo/", "bar/"], transport=t)
205
def check_format(format, url):
206
format.initialize(url)
207
t = get_transport(url)
208
found_format = bzrdir.BzrDirFormat.find_format(t)
209
self.failUnless(isinstance(found_format, format.__class__))
210
check_format(bzrdir.BzrDirFormat5(), "foo")
211
check_format(bzrdir.BzrDirFormat6(), "bar")
213
def test_find_format_nothing_there(self):
214
self.assertRaises(NotBranchError,
215
bzrdir.BzrDirFormat.find_format,
218
def test_find_format_unknown_format(self):
219
t = get_transport(self.get_url())
221
t.put_bytes('.bzr/branch-format', '')
222
self.assertRaises(UnknownFormatError,
223
bzrdir.BzrDirFormat.find_format,
226
def test_register_unregister_format(self):
227
format = SampleBzrDirFormat()
230
format.initialize(url)
231
# register a format for it.
232
bzrdir.BzrDirFormat.register_format(format)
233
# which bzrdir.Open will refuse (not supported)
234
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
235
# which bzrdir.open_containing will refuse (not supported)
236
self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open_containing, url)
237
# but open_downlevel will work
238
t = get_transport(url)
239
self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
240
# unregister the format
241
bzrdir.BzrDirFormat.unregister_format(format)
242
# now open_downlevel should fail too.
243
self.assertRaises(UnknownFormatError, bzrdir.BzrDir.open_unsupported, url)
245
def test_create_repository(self):
246
format = SampleBzrDirFormat()
247
repo = bzrdir.BzrDir.create_repository(self.get_url(), format=format)
248
self.assertEqual('A repository', repo)
250
def test_create_repository_shared(self):
251
old_format = bzrdir.BzrDirFormat.get_default_format()
252
repo = bzrdir.BzrDir.create_repository('.', shared=True)
253
self.assertTrue(repo.is_shared())
255
def test_create_repository_nonshared(self):
256
old_format = bzrdir.BzrDirFormat.get_default_format()
257
repo = bzrdir.BzrDir.create_repository('.')
258
self.assertFalse(repo.is_shared())
260
def test_create_repository_under_shared(self):
261
# an explicit create_repository always does so.
262
# we trust the format is right from the 'create_repository test'
263
format = bzrdir.format_registry.make_bzrdir('knit')
264
self.make_repository('.', shared=True, format=format)
265
repo = bzrdir.BzrDir.create_repository(self.get_url('child'),
267
self.assertTrue(isinstance(repo, repository.Repository))
268
self.assertTrue(repo.bzrdir.root_transport.base.endswith('child/'))
270
def test_create_branch_and_repo_uses_default(self):
271
format = SampleBzrDirFormat()
272
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
274
self.assertTrue(isinstance(branch, SampleBranch))
276
def test_create_branch_and_repo_under_shared(self):
277
# creating a branch and repo in a shared repo uses the
279
format = bzrdir.format_registry.make_bzrdir('knit')
280
self.make_repository('.', shared=True, format=format)
281
branch = bzrdir.BzrDir.create_branch_and_repo(
282
self.get_url('child'), format=format)
283
self.assertRaises(errors.NoRepositoryPresent,
284
branch.bzrdir.open_repository)
286
def test_create_branch_and_repo_under_shared_force_new(self):
287
# creating a branch and repo in a shared repo can be forced to
289
format = bzrdir.format_registry.make_bzrdir('knit')
290
self.make_repository('.', shared=True, format=format)
291
branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
294
branch.bzrdir.open_repository()
296
def test_create_standalone_working_tree(self):
297
format = SampleBzrDirFormat()
298
# note this is deliberately readonly, as this failure should
299
# occur before any writes.
300
self.assertRaises(errors.NotLocalUrl,
301
bzrdir.BzrDir.create_standalone_workingtree,
302
self.get_readonly_url(), format=format)
303
tree = bzrdir.BzrDir.create_standalone_workingtree('.',
305
self.assertEqual('A tree', tree)
307
def test_create_standalone_working_tree_under_shared_repo(self):
308
# create standalone working tree always makes a repo.
309
format = bzrdir.format_registry.make_bzrdir('knit')
310
self.make_repository('.', shared=True, format=format)
311
# note this is deliberately readonly, as this failure should
312
# occur before any writes.
313
self.assertRaises(errors.NotLocalUrl,
314
bzrdir.BzrDir.create_standalone_workingtree,
315
self.get_readonly_url('child'), format=format)
316
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
318
tree.bzrdir.open_repository()
320
def test_create_branch_convenience(self):
321
# outside a repo the default convenience output is a repo+branch_tree
322
format = bzrdir.format_registry.make_bzrdir('knit')
323
branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
324
branch.bzrdir.open_workingtree()
325
branch.bzrdir.open_repository()
327
def test_create_branch_convenience_root(self):
328
"""Creating a branch at the root of a fs should work."""
329
self.transport_server = MemoryServer
330
# outside a repo the default convenience output is a repo+branch_tree
331
format = bzrdir.format_registry.make_bzrdir('knit')
332
branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
334
self.assertRaises(errors.NoWorkingTree,
335
branch.bzrdir.open_workingtree)
336
branch.bzrdir.open_repository()
338
def test_create_branch_convenience_under_shared_repo(self):
339
# inside a repo the default convenience output is a branch+ follow the
341
format = bzrdir.format_registry.make_bzrdir('knit')
342
self.make_repository('.', shared=True, format=format)
343
branch = bzrdir.BzrDir.create_branch_convenience('child',
345
branch.bzrdir.open_workingtree()
346
self.assertRaises(errors.NoRepositoryPresent,
347
branch.bzrdir.open_repository)
349
def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
350
# inside a repo the default convenience output is a branch+ follow the
351
# repo tree policy but we can override that
352
format = bzrdir.format_registry.make_bzrdir('knit')
353
self.make_repository('.', shared=True, format=format)
354
branch = bzrdir.BzrDir.create_branch_convenience('child',
355
force_new_tree=False, format=format)
356
self.assertRaises(errors.NoWorkingTree,
357
branch.bzrdir.open_workingtree)
358
self.assertRaises(errors.NoRepositoryPresent,
359
branch.bzrdir.open_repository)
361
def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
362
# inside a repo the default convenience output is a branch+ follow the
364
format = bzrdir.format_registry.make_bzrdir('knit')
365
repo = self.make_repository('.', shared=True, format=format)
366
repo.set_make_working_trees(False)
367
branch = bzrdir.BzrDir.create_branch_convenience('child',
369
self.assertRaises(errors.NoWorkingTree,
370
branch.bzrdir.open_workingtree)
371
self.assertRaises(errors.NoRepositoryPresent,
372
branch.bzrdir.open_repository)
374
def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
375
# inside a repo the default convenience output is a branch+ follow the
376
# repo tree policy but we can override that
377
format = bzrdir.format_registry.make_bzrdir('knit')
378
repo = self.make_repository('.', shared=True, format=format)
379
repo.set_make_working_trees(False)
380
branch = bzrdir.BzrDir.create_branch_convenience('child',
381
force_new_tree=True, format=format)
382
branch.bzrdir.open_workingtree()
383
self.assertRaises(errors.NoRepositoryPresent,
384
branch.bzrdir.open_repository)
386
def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
387
# inside a repo the default convenience output is overridable to give
389
format = bzrdir.format_registry.make_bzrdir('knit')
390
self.make_repository('.', shared=True, format=format)
391
branch = bzrdir.BzrDir.create_branch_convenience('child',
392
force_new_repo=True, format=format)
393
branch.bzrdir.open_repository()
394
branch.bzrdir.open_workingtree()
397
class ChrootedTests(TestCaseWithTransport):
398
"""A support class that provides readonly urls outside the local namespace.
400
This is done by checking if self.transport_server is a MemoryServer. if it
401
is then we are chrooted already, if it is not then an HttpServer is used
406
super(ChrootedTests, self).setUp()
407
if not self.transport_server == MemoryServer:
408
self.transport_readonly_server = HttpServer
410
def test_open_containing(self):
411
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
412
self.get_readonly_url(''))
413
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
414
self.get_readonly_url('g/p/q'))
415
control = bzrdir.BzrDir.create(self.get_url())
416
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url(''))
417
self.assertEqual('', relpath)
418
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
419
self.assertEqual('g/p/q', relpath)
421
def test_open_containing_from_transport(self):
422
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
423
get_transport(self.get_readonly_url('')))
424
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
425
get_transport(self.get_readonly_url('g/p/q')))
426
control = bzrdir.BzrDir.create(self.get_url())
427
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
428
get_transport(self.get_readonly_url('')))
429
self.assertEqual('', relpath)
430
branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
431
get_transport(self.get_readonly_url('g/p/q')))
432
self.assertEqual('g/p/q', relpath)
434
def test_open_containing_tree_or_branch(self):
435
def local_branch_path(branch):
436
return os.path.realpath(
437
urlutils.local_path_from_url(branch.base))
439
self.make_branch_and_tree('topdir')
440
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
442
self.assertEqual(os.path.realpath('topdir'),
443
os.path.realpath(tree.basedir))
444
self.assertEqual(os.path.realpath('topdir'),
445
local_branch_path(branch))
446
self.assertIs(tree.bzrdir, branch.bzrdir)
447
self.assertEqual('foo', relpath)
448
self.make_branch('topdir/foo')
449
tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
451
self.assertIs(tree, None)
452
self.assertEqual(os.path.realpath('topdir/foo'),
453
local_branch_path(branch))
454
self.assertEqual('', relpath)
456
def test_open_from_transport(self):
457
# transport pointing at bzrdir should give a bzrdir with root transport
458
# set to the given transport
459
control = bzrdir.BzrDir.create(self.get_url())
460
transport = get_transport(self.get_url())
461
opened_bzrdir = bzrdir.BzrDir.open_from_transport(transport)
462
self.assertEqual(transport.base, opened_bzrdir.root_transport.base)
463
self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
465
def test_open_from_transport_no_bzrdir(self):
466
transport = get_transport(self.get_url())
467
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
470
def test_open_from_transport_bzrdir_in_parent(self):
471
control = bzrdir.BzrDir.create(self.get_url())
472
transport = get_transport(self.get_url())
473
transport.mkdir('subdir')
474
transport = transport.clone('subdir')
475
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport,
479
class TestMeta1DirFormat(TestCaseWithTransport):
480
"""Tests specific to the meta1 dir format."""
482
def test_right_base_dirs(self):
483
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
485
branch_base = t.clone('branch').base
486
self.assertEqual(branch_base, dir.get_branch_transport(None).base)
487
self.assertEqual(branch_base,
488
dir.get_branch_transport(bzrlib.branch.BzrBranchFormat5()).base)
489
repository_base = t.clone('repository').base
490
self.assertEqual(repository_base, dir.get_repository_transport(None).base)
491
self.assertEqual(repository_base,
492
dir.get_repository_transport(repository.RepositoryFormat7()).base)
493
checkout_base = t.clone('checkout').base
494
self.assertEqual(checkout_base, dir.get_workingtree_transport(None).base)
495
self.assertEqual(checkout_base,
496
dir.get_workingtree_transport(workingtree.WorkingTreeFormat3()).base)
498
def test_meta1dir_uses_lockdir(self):
499
"""Meta1 format uses a LockDir to guard the whole directory, not a file."""
500
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
502
self.assertIsDirectory('branch-lock', t)
505
class TestFormat5(TestCaseWithTransport):
506
"""Tests specific to the version 5 bzrdir format."""
508
def test_same_lockfiles_between_tree_repo_branch(self):
509
# this checks that only a single lockfiles instance is created
510
# for format 5 objects
511
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
512
def check_dir_components_use_same_lock(dir):
513
ctrl_1 = dir.open_repository().control_files
514
ctrl_2 = dir.open_branch().control_files
515
ctrl_3 = dir.open_workingtree()._control_files
516
self.assertTrue(ctrl_1 is ctrl_2)
517
self.assertTrue(ctrl_2 is ctrl_3)
518
check_dir_components_use_same_lock(dir)
519
# and if we open it normally.
520
dir = bzrdir.BzrDir.open(self.get_url())
521
check_dir_components_use_same_lock(dir)
523
def test_can_convert(self):
524
# format 5 dirs are convertable
525
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
526
self.assertTrue(dir.can_convert_format())
528
def test_needs_conversion(self):
529
# format 5 dirs need a conversion if they are not the default.
530
# and they start of not the default.
531
old_format = bzrdir.BzrDirFormat.get_default_format()
532
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
534
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
535
self.assertFalse(dir.needs_format_conversion())
537
bzrdir.BzrDirFormat._set_default_format(old_format)
538
self.assertTrue(dir.needs_format_conversion())
541
class TestFormat6(TestCaseWithTransport):
542
"""Tests specific to the version 6 bzrdir format."""
544
def test_same_lockfiles_between_tree_repo_branch(self):
545
# this checks that only a single lockfiles instance is created
546
# for format 6 objects
547
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
548
def check_dir_components_use_same_lock(dir):
549
ctrl_1 = dir.open_repository().control_files
550
ctrl_2 = dir.open_branch().control_files
551
ctrl_3 = dir.open_workingtree()._control_files
552
self.assertTrue(ctrl_1 is ctrl_2)
553
self.assertTrue(ctrl_2 is ctrl_3)
554
check_dir_components_use_same_lock(dir)
555
# and if we open it normally.
556
dir = bzrdir.BzrDir.open(self.get_url())
557
check_dir_components_use_same_lock(dir)
559
def test_can_convert(self):
560
# format 6 dirs are convertable
561
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
562
self.assertTrue(dir.can_convert_format())
564
def test_needs_conversion(self):
565
# format 6 dirs need an conversion if they are not the default.
566
old_format = bzrdir.BzrDirFormat.get_default_format()
567
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
569
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
570
self.assertTrue(dir.needs_format_conversion())
572
bzrdir.BzrDirFormat._set_default_format(old_format)
575
class NotBzrDir(bzrlib.bzrdir.BzrDir):
576
"""A non .bzr based control directory."""
578
def __init__(self, transport, format):
579
self._format = format
580
self.root_transport = transport
581
self.transport = transport.clone('.not')
584
class NotBzrDirFormat(bzrlib.bzrdir.BzrDirFormat):
585
"""A test class representing any non-.bzr based disk format."""
587
def initialize_on_transport(self, transport):
588
"""Initialize a new .not dir in the base directory of a Transport."""
589
transport.mkdir('.not')
590
return self.open(transport)
592
def open(self, transport):
593
"""Open this directory."""
594
return NotBzrDir(transport, self)
597
def _known_formats(self):
598
return set([NotBzrDirFormat()])
601
def probe_transport(self, transport):
602
"""Our format is present if the transport ends in '.not/'."""
603
if transport.has('.not'):
604
return NotBzrDirFormat()
607
class TestNotBzrDir(TestCaseWithTransport):
608
"""Tests for using the bzrdir api with a non .bzr based disk format.
610
If/when one of these is in the core, we can let the implementation tests
614
def test_create_and_find_format(self):
615
# create a .notbzr dir
616
format = NotBzrDirFormat()
617
dir = format.initialize(self.get_url())
618
self.assertIsInstance(dir, NotBzrDir)
620
bzrlib.bzrdir.BzrDirFormat.register_control_format(format)
622
found = bzrlib.bzrdir.BzrDirFormat.find_format(
623
get_transport(self.get_url()))
624
self.assertIsInstance(found, NotBzrDirFormat)
626
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(format)
628
def test_included_in_known_formats(self):
629
bzrlib.bzrdir.BzrDirFormat.register_control_format(NotBzrDirFormat)
631
formats = bzrlib.bzrdir.BzrDirFormat.known_formats()
632
for format in formats:
633
if isinstance(format, NotBzrDirFormat):
635
self.fail("No NotBzrDirFormat in %s" % formats)
637
bzrlib.bzrdir.BzrDirFormat.unregister_control_format(NotBzrDirFormat)
640
class NonLocalTests(TestCaseWithTransport):
641
"""Tests for bzrdir static behaviour on non local paths."""
644
super(NonLocalTests, self).setUp()
645
self.transport_server = MemoryServer
647
def test_create_branch_convenience(self):
648
# outside a repo the default convenience output is a repo+branch_tree
649
format = bzrdir.format_registry.make_bzrdir('knit')
650
branch = bzrdir.BzrDir.create_branch_convenience(
651
self.get_url('foo'), format=format)
652
self.assertRaises(errors.NoWorkingTree,
653
branch.bzrdir.open_workingtree)
654
branch.bzrdir.open_repository()
656
def test_create_branch_convenience_force_tree_not_local_fails(self):
657
# outside a repo the default convenience output is a repo+branch_tree
658
format = bzrdir.format_registry.make_bzrdir('knit')
659
self.assertRaises(errors.NotLocalUrl,
660
bzrdir.BzrDir.create_branch_convenience,
664
t = get_transport(self.get_url('.'))
665
self.assertFalse(t.has('foo'))
667
def test_clone(self):
668
# clone into a nonlocal path works
669
format = bzrdir.format_registry.make_bzrdir('knit')
670
branch = bzrdir.BzrDir.create_branch_convenience('local',
672
branch.bzrdir.open_workingtree()
673
result = branch.bzrdir.clone(self.get_url('remote'))
674
self.assertRaises(errors.NoWorkingTree,
675
result.open_workingtree)
677
result.open_repository()
680
class TestRemoteSFTP(test_sftp_transport.TestCaseWithSFTPServer):
682
def test_open_containing_tree_or_branch(self):
683
tree = self.make_branch_and_tree('tree')
684
bzrdir.BzrDir.open_containing_tree_or_branch(self.get_url('tree'))