124
131
my_format_registry = self.make_format_registry()
125
132
self.assertEqual('Format registered lazily',
126
133
my_format_registry.get_help('lazy'))
127
self.assertEqual('Format using knits',
134
self.assertEqual('Format using knits',
128
135
my_format_registry.get_help('knit'))
129
self.assertEqual('Format using knits',
136
self.assertEqual('Format using knits',
130
137
my_format_registry.get_help('default'))
131
138
self.assertEqual('Pre-0.8 format. Slower and does not support'
132
' checkouts or shared repositories',
139
' checkouts or shared repositories',
133
140
my_format_registry.get_help('weave'))
135
142
def test_help_topic(self):
136
143
topics = help_topics.HelpTopicRegistry()
137
topics.register('formats', self.make_format_registry().help_topic,
139
topic = topics.get_detail('formats')
140
new, deprecated = topic.split('Deprecated formats')
141
self.assertContainsRe(new, 'Bazaar directory formats')
142
self.assertContainsRe(new,
143
' knit/default:\n \(native\) Format using knits\n')
144
self.assertContainsRe(deprecated,
145
' lazy:\n \(native\) Format registered lazily\n')
144
registry = self.make_format_registry()
145
topics.register('current-formats', registry.help_topic,
147
topics.register('other-formats', registry.help_topic,
149
new = topics.get_detail('current-formats')
150
rest = topics.get_detail('other-formats')
151
experimental, deprecated = rest.split('Deprecated formats')
152
self.assertContainsRe(new, 'bzr help formats')
153
self.assertContainsRe(new,
154
':knit:\n \(native\) \(default\) Format using knits\n')
155
self.assertContainsRe(experimental,
156
':branch6:\n \(native\) Experimental successor to knit')
157
self.assertContainsRe(deprecated,
158
':lazy:\n \(native\) Format registered lazily\n')
146
159
self.assertNotContainsRe(new, 'hidden')
148
161
def test_set_default_repository(self):
413
426
branch.bzrdir.open_workingtree()
429
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
431
def test_acquire_repository_standalone(self):
432
"""The default acquisition policy should create a standalone branch."""
433
my_bzrdir = self.make_bzrdir('.')
434
repo_policy = my_bzrdir.determine_repository_policy()
435
repo, is_new = repo_policy.acquire_repository()
436
self.assertEqual(repo.bzrdir.root_transport.base,
437
my_bzrdir.root_transport.base)
438
self.assertFalse(repo.is_shared())
440
def test_determine_stacking_policy(self):
441
parent_bzrdir = self.make_bzrdir('.')
442
child_bzrdir = self.make_bzrdir('child')
443
parent_bzrdir.get_config().set_default_stack_on('http://example.org')
444
repo_policy = child_bzrdir.determine_repository_policy()
445
self.assertEqual('http://example.org', repo_policy._stack_on)
447
def test_determine_stacking_policy_relative(self):
448
parent_bzrdir = self.make_bzrdir('.')
449
child_bzrdir = self.make_bzrdir('child')
450
parent_bzrdir.get_config().set_default_stack_on('child2')
451
repo_policy = child_bzrdir.determine_repository_policy()
452
self.assertEqual('child2', repo_policy._stack_on)
453
self.assertEqual(parent_bzrdir.root_transport.base,
454
repo_policy._stack_on_pwd)
456
def prepare_default_stacking(self, child_format='1.6'):
457
parent_bzrdir = self.make_bzrdir('.')
458
child_branch = self.make_branch('child', format=child_format)
459
parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
460
new_child_transport = parent_bzrdir.transport.clone('child2')
461
return child_branch, new_child_transport
463
def test_clone_on_transport_obeys_stacking_policy(self):
464
child_branch, new_child_transport = self.prepare_default_stacking()
465
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
466
self.assertEqual(child_branch.base,
467
new_child.open_branch().get_stacked_on_url())
469
def test_default_stacking_with_stackable_branch_unstackable_repo(self):
470
# Make stackable source branch with an unstackable repo format.
471
source_bzrdir = self.make_bzrdir('source')
472
pack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
473
source_branch = bzrlib.branch.BzrBranchFormat7().initialize(source_bzrdir)
474
# Make a directory with a default stacking policy
475
parent_bzrdir = self.make_bzrdir('parent')
476
stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
477
parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
478
# Clone source into directory
479
target = source_bzrdir.clone(self.get_url('parent/target'))
481
def test_sprout_obeys_stacking_policy(self):
482
child_branch, new_child_transport = self.prepare_default_stacking()
483
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
484
self.assertEqual(child_branch.base,
485
new_child.open_branch().get_stacked_on_url())
487
def test_clone_ignores_policy_for_unsupported_formats(self):
488
child_branch, new_child_transport = self.prepare_default_stacking(
489
child_format='pack-0.92')
490
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
491
self.assertRaises(errors.UnstackableBranchFormat,
492
new_child.open_branch().get_stacked_on_url)
494
def test_sprout_ignores_policy_for_unsupported_formats(self):
495
child_branch, new_child_transport = self.prepare_default_stacking(
496
child_format='pack-0.92')
497
new_child = child_branch.bzrdir.sprout(new_child_transport.base)
498
self.assertRaises(errors.UnstackableBranchFormat,
499
new_child.open_branch().get_stacked_on_url)
501
def test_sprout_upgrades_format_if_stacked_specified(self):
502
child_branch, new_child_transport = self.prepare_default_stacking(
503
child_format='pack-0.92')
504
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
506
self.assertEqual(child_branch.bzrdir.root_transport.base,
507
new_child.open_branch().get_stacked_on_url())
508
repo = new_child.open_repository()
509
self.assertTrue(repo._format.supports_external_lookups)
510
self.assertFalse(repo.supports_rich_root())
512
def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
513
child_branch, new_child_transport = self.prepare_default_stacking(
514
child_format='pack-0.92')
515
new_child = child_branch.bzrdir.clone_on_transport(new_child_transport,
516
stacked_on=child_branch.bzrdir.root_transport.base)
517
self.assertEqual(child_branch.bzrdir.root_transport.base,
518
new_child.open_branch().get_stacked_on_url())
519
repo = new_child.open_repository()
520
self.assertTrue(repo._format.supports_external_lookups)
521
self.assertFalse(repo.supports_rich_root())
523
def test_sprout_upgrades_to_rich_root_format_if_needed(self):
524
child_branch, new_child_transport = self.prepare_default_stacking(
525
child_format='rich-root-pack')
526
new_child = child_branch.bzrdir.sprout(new_child_transport.base,
528
repo = new_child.open_repository()
529
self.assertTrue(repo._format.supports_external_lookups)
530
self.assertTrue(repo.supports_rich_root())
532
def test_add_fallback_repo_handles_absolute_urls(self):
533
stack_on = self.make_branch('stack_on', format='1.6')
534
repo = self.make_repository('repo', format='1.6')
535
policy = bzrdir.UseExistingRepository(repo, stack_on.base)
536
policy._add_fallback(repo)
538
def test_add_fallback_repo_handles_relative_urls(self):
539
stack_on = self.make_branch('stack_on', format='1.6')
540
repo = self.make_repository('repo', format='1.6')
541
policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
542
policy._add_fallback(repo)
544
def test_configure_relative_branch_stacking_url(self):
545
stack_on = self.make_branch('stack_on', format='1.6')
546
stacked = self.make_branch('stack_on/stacked', format='1.6')
547
policy = bzrdir.UseExistingRepository(stacked.repository,
549
policy.configure_branch(stacked)
550
self.assertEqual('..', stacked.get_stacked_on_url())
552
def test_relative_branch_stacking_to_absolute(self):
553
stack_on = self.make_branch('stack_on', format='1.6')
554
stacked = self.make_branch('stack_on/stacked', format='1.6')
555
policy = bzrdir.UseExistingRepository(stacked.repository,
556
'.', self.get_readonly_url('stack_on'))
557
policy.configure_branch(stacked)
558
self.assertEqual(self.get_readonly_url('stack_on'),
559
stacked.get_stacked_on_url())
416
562
class ChrootedTests(TestCaseWithTransport):
417
563
"""A support class that provides readonly urls outside the local namespace.
437
586
branch, relpath = bzrdir.BzrDir.open_containing(self.get_readonly_url('g/p/q'))
438
587
self.assertEqual('g/p/q', relpath)
589
def test_open_containing_tree_branch_or_repository_empty(self):
590
self.assertRaises(errors.NotBranchError,
591
bzrdir.BzrDir.open_containing_tree_branch_or_repository,
592
self.get_readonly_url(''))
594
def test_open_containing_tree_branch_or_repository_all(self):
595
self.make_branch_and_tree('topdir')
596
tree, branch, repo, relpath = \
597
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
599
self.assertEqual(os.path.realpath('topdir'),
600
os.path.realpath(tree.basedir))
601
self.assertEqual(os.path.realpath('topdir'),
602
self.local_branch_path(branch))
604
osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
605
repo.bzrdir.transport.local_abspath('repository'))
606
self.assertEqual(relpath, 'foo')
608
def test_open_containing_tree_branch_or_repository_no_tree(self):
609
self.make_branch('branch')
610
tree, branch, repo, relpath = \
611
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
613
self.assertEqual(tree, None)
614
self.assertEqual(os.path.realpath('branch'),
615
self.local_branch_path(branch))
617
osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
618
repo.bzrdir.transport.local_abspath('repository'))
619
self.assertEqual(relpath, 'foo')
621
def test_open_containing_tree_branch_or_repository_repo(self):
622
self.make_repository('repo')
623
tree, branch, repo, relpath = \
624
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
626
self.assertEqual(tree, None)
627
self.assertEqual(branch, None)
629
osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
630
repo.bzrdir.transport.local_abspath('repository'))
631
self.assertEqual(relpath, '')
633
def test_open_containing_tree_branch_or_repository_shared_repo(self):
634
self.make_repository('shared', shared=True)
635
bzrdir.BzrDir.create_branch_convenience('shared/branch',
636
force_new_tree=False)
637
tree, branch, repo, relpath = \
638
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
640
self.assertEqual(tree, None)
641
self.assertEqual(os.path.realpath('shared/branch'),
642
self.local_branch_path(branch))
644
osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
645
repo.bzrdir.transport.local_abspath('repository'))
646
self.assertEqual(relpath, '')
648
def test_open_containing_tree_branch_or_repository_branch_subdir(self):
649
self.make_branch_and_tree('foo')
650
self.build_tree(['foo/bar/'])
651
tree, branch, repo, relpath = \
652
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
654
self.assertEqual(os.path.realpath('foo'),
655
os.path.realpath(tree.basedir))
656
self.assertEqual(os.path.realpath('foo'),
657
self.local_branch_path(branch))
659
osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
660
repo.bzrdir.transport.local_abspath('repository'))
661
self.assertEqual(relpath, 'bar')
663
def test_open_containing_tree_branch_or_repository_repo_subdir(self):
664
self.make_repository('bar')
665
self.build_tree(['bar/baz/'])
666
tree, branch, repo, relpath = \
667
bzrdir.BzrDir.open_containing_tree_branch_or_repository(
669
self.assertEqual(tree, None)
670
self.assertEqual(branch, None)
672
osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
673
repo.bzrdir.transport.local_abspath('repository'))
674
self.assertEqual(relpath, 'baz')
440
676
def test_open_containing_from_transport(self):
441
677
self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing_from_transport,
442
678
get_transport(self.get_readonly_url('')))
537
793
self.failUnlessExists('repo/tree2/subtree')
538
794
self.failIfExists('repo/tree2/subtree/file')
796
def make_foo_bar_baz(self):
797
foo = bzrdir.BzrDir.create_branch_convenience('foo').bzrdir
798
bar = self.make_branch('foo/bar').bzrdir
799
baz = self.make_branch('baz').bzrdir
802
def test_find_bzrdirs(self):
803
foo, bar, baz = self.make_foo_bar_baz()
804
transport = get_transport(self.get_url())
805
self.assertEqualBzrdirs([baz, foo, bar],
806
bzrdir.BzrDir.find_bzrdirs(transport))
808
def test_find_bzrdirs_list_current(self):
809
def list_current(transport):
810
return [s for s in transport.list_dir('') if s != 'baz']
812
foo, bar, baz = self.make_foo_bar_baz()
813
transport = get_transport(self.get_url())
814
self.assertEqualBzrdirs([foo, bar],
815
bzrdir.BzrDir.find_bzrdirs(transport,
816
list_current=list_current))
819
def test_find_bzrdirs_evaluate(self):
820
def evaluate(bzrdir):
822
repo = bzrdir.open_repository()
823
except NoRepositoryPresent:
824
return True, bzrdir.root_transport.base
826
return False, bzrdir.root_transport.base
828
foo, bar, baz = self.make_foo_bar_baz()
829
transport = get_transport(self.get_url())
830
self.assertEqual([baz.root_transport.base, foo.root_transport.base],
831
list(bzrdir.BzrDir.find_bzrdirs(transport,
834
def assertEqualBzrdirs(self, first, second):
836
second = list(second)
837
self.assertEqual(len(first), len(second))
838
for x, y in zip(first, second):
839
self.assertEqual(x.root_transport.base, y.root_transport.base)
841
def test_find_branches(self):
842
root = self.make_repository('', shared=True)
843
foo, bar, baz = self.make_foo_bar_baz()
844
qux = self.make_bzrdir('foo/qux')
845
transport = get_transport(self.get_url())
846
branches = bzrdir.BzrDir.find_branches(transport)
847
self.assertEqual(baz.root_transport.base, branches[0].base)
848
self.assertEqual(foo.root_transport.base, branches[1].base)
849
self.assertEqual(bar.root_transport.base, branches[2].base)
851
# ensure this works without a top-level repo
852
branches = bzrdir.BzrDir.find_branches(transport.clone('foo'))
853
self.assertEqual(foo.root_transport.base, branches[0].base)
854
self.assertEqual(bar.root_transport.base, branches[1].base)
541
857
class TestMeta1DirFormat(TestCaseWithTransport):
542
858
"""Tests specific to the meta1 dir format."""
776
1097
workingtree.WorkingTreeFormat3)
779
class TestHTTPRedirectionLoop(object):
780
"""Test redirection loop between two http servers.
1100
class TestHTTPRedirections(object):
1101
"""Test redirection between two http servers.
782
1103
This MUST be used by daughter classes that also inherit from
783
1104
TestCaseWithTwoWebservers.
785
1106
We can't inherit directly from TestCaseWithTwoWebservers or the
786
1107
test framework will try to create an instance which cannot
787
run, its implementation being incomplete.
1108
run, its implementation being incomplete.
790
# Should be defined by daughter classes to ensure redirection
791
# still use the same transport implementation (not currently
792
# enforced as it's a bit tricky to get right (see the FIXME
793
# in BzrDir.open_from_transport for the unique use case so
797
1111
def create_transport_readonly_server(self):
798
return HTTPServerRedirecting()
1112
return http_utils.HTTPServerRedirecting()
800
1114
def create_transport_secondary_server(self):
801
return HTTPServerRedirecting()
1115
return http_utils.HTTPServerRedirecting()
803
1117
def setUp(self):
804
# Both servers redirect to each server creating a loop
805
super(TestHTTPRedirectionLoop, self).setUp()
1118
super(TestHTTPRedirections, self).setUp()
806
1119
# The redirections will point to the new server
807
1120
self.new_server = self.get_readonly_server()
808
1121
# The requests to the old server will be redirected
809
1122
self.old_server = self.get_secondary_server()
810
1123
# Configure the redirections
811
1124
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
1126
def test_loop(self):
1127
# Both servers redirect to each other creating a loop
812
1128
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
814
def _qualified_url(self, host, port):
815
return 'http+%s://%s:%s' % (self._qualifier, host, port)
818
1129
# Starting from either server should loop
819
old_url = self._qualified_url(self.old_server.host,
1130
old_url = self._qualified_url(self.old_server.host,
820
1131
self.old_server.port)
821
1132
oldt = self._transport(old_url)
822
1133
self.assertRaises(errors.NotBranchError,
823
1134
bzrdir.BzrDir.open_from_transport, oldt)
824
new_url = self._qualified_url(self.new_server.host,
1135
new_url = self._qualified_url(self.new_server.host,
825
1136
self.new_server.port)
826
1137
newt = self._transport(new_url)
827
1138
self.assertRaises(errors.NotBranchError,
828
1139
bzrdir.BzrDir.open_from_transport, newt)
831
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
832
TestCaseWithTwoWebservers):
1141
def test_qualifier_preserved(self):
1142
wt = self.make_branch_and_tree('branch')
1143
old_url = self._qualified_url(self.old_server.host,
1144
self.old_server.port)
1145
start = self._transport(old_url).clone('branch')
1146
bdir = bzrdir.BzrDir.open_from_transport(start)
1147
# Redirection should preserve the qualifier, hence the transport class
1149
self.assertIsInstance(bdir.root_transport, type(start))
1152
class TestHTTPRedirections_urllib(TestHTTPRedirections,
1153
http_utils.TestCaseWithTwoWebservers):
833
1154
"""Tests redirections for urllib implementation"""
835
_qualifier = 'urllib'
836
1156
_transport = HttpTransport_urllib
1158
def _qualified_url(self, host, port):
1159
return 'http+urllib://%s:%s' % (host, port)
840
1163
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
841
TestHTTPRedirectionLoop,
842
TestCaseWithTwoWebservers):
1164
TestHTTPRedirections,
1165
http_utils.TestCaseWithTwoWebservers):
843
1166
"""Tests redirections for pycurl implementation"""
845
_qualifier = 'pycurl'
1168
def _qualified_url(self, host, port):
1169
return 'http+pycurl://%s:%s' % (host, port)
1172
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1173
http_utils.TestCaseWithTwoWebservers):
1174
"""Tests redirections for the nosmart decorator"""
1176
_transport = NoSmartTransportDecorator
1178
def _qualified_url(self, host, port):
1179
return 'nosmart+http://%s:%s' % (host, port)
1182
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1183
http_utils.TestCaseWithTwoWebservers):
1184
"""Tests redirections for readonly decoratror"""
1186
_transport = ReadonlyTransportDecorator
1188
def _qualified_url(self, host, port):
1189
return 'readonly+http://%s:%s' % (host, port)
1192
class TestDotBzrHidden(TestCaseWithTransport):
1195
if sys.platform == 'win32':
1196
ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
1199
f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
1200
stderr=subprocess.PIPE)
1201
out, err = f.communicate()
1202
self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1204
return out.splitlines()
1206
def test_dot_bzr_hidden(self):
1207
if sys.platform == 'win32' and not win32utils.has_win32file:
1208
raise TestSkipped('unable to make file hidden without pywin32 library')
1209
b = bzrdir.BzrDir.create('.')
1210
self.build_tree(['a'])
1211
self.assertEquals(['a'], self.get_ls())
1213
def test_dot_bzr_hidden_with_url(self):
1214
if sys.platform == 'win32' and not win32utils.has_win32file:
1215
raise TestSkipped('unable to make file hidden without pywin32 library')
1216
b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1217
self.build_tree(['a'])
1218
self.assertEquals(['a'], self.get_ls())
1221
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1222
"""Test BzrDirFormat implementation for TestBzrDirSprout."""
1224
def _open(self, transport):
1225
return _TestBzrDir(transport, self)
1228
class _TestBzrDir(bzrdir.BzrDirMeta1):
1229
"""Test BzrDir implementation for TestBzrDirSprout.
1231
When created a _TestBzrDir already has repository and a branch. The branch
1232
is a test double as well.
1235
def __init__(self, *args, **kwargs):
1236
super(_TestBzrDir, self).__init__(*args, **kwargs)
1237
self.test_branch = _TestBranch()
1238
self.test_branch.repository = self.create_repository()
1240
def open_branch(self, unsupported=False):
1241
return self.test_branch
1243
def cloning_metadir(self, require_stacking=False):
1244
return _TestBzrDirFormat()
1247
class _TestBranchFormat(bzrlib.branch.BranchFormat):
1248
"""Test Branch format for TestBzrDirSprout."""
1251
class _TestBranch(bzrlib.branch.Branch):
1252
"""Test Branch implementation for TestBzrDirSprout."""
1254
def __init__(self, *args, **kwargs):
1255
self._format = _TestBranchFormat()
1256
super(_TestBranch, self).__init__(*args, **kwargs)
1260
def sprout(self, *args, **kwargs):
1261
self.calls.append('sprout')
1262
return _TestBranch()
1264
def copy_content_into(self, destination, revision_id=None):
1265
self.calls.append('copy_content_into')
1267
def get_parent(self):
1270
def set_parent(self, parent):
1271
self._parent = parent
1274
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1276
def test_sprout_uses_branch_sprout(self):
1277
"""BzrDir.sprout calls Branch.sprout.
1279
Usually, BzrDir.sprout should delegate to the branch's sprout method
1280
for part of the work. This allows the source branch to control the
1281
choice of format for the new branch.
1283
There are exceptions, but this tests avoids them:
1284
- if there's no branch in the source bzrdir,
1285
- or if the stacking has been requested and the format needs to be
1286
overridden to satisfy that.
1288
# Make an instrumented bzrdir.
1289
t = self.get_transport('source')
1291
source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1292
# The instrumented bzrdir has a test_branch attribute that logs calls
1293
# made to the branch contained in that bzrdir. Initially the test
1294
# branch exists but no calls have been made to it.
1295
self.assertEqual([], source_bzrdir.test_branch.calls)
1298
target_url = self.get_url('target')
1299
result = source_bzrdir.sprout(target_url, recurse='no')
1301
# The bzrdir called the branch's sprout method.
1302
self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
1304
def test_sprout_parent(self):
1305
grandparent_tree = self.make_branch('grandparent')
1306
parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
1307
branch_tree = parent.bzrdir.sprout('branch').open_branch()
1308
self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
1311
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1313
def test_pre_open_called(self):
1315
bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1316
transport = self.get_transport('foo')
1317
url = transport.base
1318
self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1319
self.assertEqual([transport.base], [t.base for t in calls])
1321
def test_pre_open_actual_exceptions_raised(self):
1323
def fail_once(transport):
1326
raise errors.BzrError("fail")
1327
bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1328
transport = self.get_transport('foo')
1329
url = transport.base
1330
err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1331
self.assertEqual('fail', err._preformatted_string)