17
17
"""Tests for the Branch facility that are not interface tests.
19
For interface tests see tests/per_branch/*.py.
19
For interface tests see `tests/per_branch/*.py`.
21
21
For concrete class tests see this file, and for meta-branch tests
22
22
also see this file.
25
from StringIO import StringIO
25
from cStringIO import StringIO
27
27
from bzrlib import (
28
28
branch as _mod_branch,
35
from bzrlib.branch import (
39
BranchReferenceFormat,
45
_run_with_write_locked_target,
47
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1,
49
from bzrlib.errors import (NotBranchError,
52
UnsupportedFormatError,
55
from bzrlib.tests import TestCase, TestCaseWithTransport
56
from bzrlib.transport import get_transport
59
class TestDefaultFormat(TestCase):
39
class TestDefaultFormat(tests.TestCase):
61
41
def test_default_format(self):
62
42
# update this if you change the default branch format
63
self.assertIsInstance(BranchFormat.get_default_format(),
43
self.assertIsInstance(_mod_branch.format_registry.get_default(),
44
_mod_branch.BzrBranchFormat7)
66
46
def test_default_format_is_same_as_bzrdir_default(self):
67
47
# XXX: it might be nice if there was only one place the default was
68
48
# set, but at the moment that's not true -- mbp 20070814 --
69
49
# https://bugs.launchpad.net/bzr/+bug/132376
70
self.assertEqual(BranchFormat.get_default_format(),
71
BzrDirFormat.get_default_format().get_branch_format())
51
_mod_branch.format_registry.get_default(),
52
bzrdir.BzrDirFormat.get_default_format().get_branch_format())
73
54
def test_get_set_default_format(self):
74
55
# set the format and then set it back again
75
old_format = BranchFormat.get_default_format()
76
BranchFormat.set_default_format(SampleBranchFormat())
56
old_format = _mod_branch.format_registry.get_default()
57
_mod_branch.format_registry.set_default(SampleBranchFormat())
78
59
# the default branch format is used by the meta dir format
79
60
# which is not the default bzrdir format at this point
80
dir = BzrDirMetaFormat1().initialize('memory:///')
61
dir = bzrdir.BzrDirMetaFormat1().initialize('memory:///')
81
62
result = dir.create_branch()
82
63
self.assertEqual(result, 'A branch')
84
BranchFormat.set_default_format(old_format)
85
self.assertEqual(old_format, BranchFormat.get_default_format())
88
class TestBranchFormat5(TestCaseWithTransport):
65
_mod_branch.format_registry.set_default(old_format)
66
self.assertEqual(old_format,
67
_mod_branch.format_registry.get_default())
70
class TestBranchFormat5(tests.TestCaseWithTransport):
89
71
"""Tests specific to branch format 5"""
91
73
def test_branch_format_5_uses_lockdir(self):
92
74
url = self.get_url()
93
bzrdir = BzrDirMetaFormat1().initialize(url)
94
bzrdir.create_repository()
95
branch = bzrdir.create_branch()
75
bdir = bzrdir.BzrDirMetaFormat1().initialize(url)
76
bdir.create_repository()
77
branch = _mod_branch.BzrBranchFormat5().initialize(bdir)
96
78
t = self.get_transport()
97
79
self.log("branch instance is %r" % branch)
98
self.assert_(isinstance(branch, BzrBranch5))
80
self.assert_(isinstance(branch, _mod_branch.BzrBranch5))
99
81
self.assertIsDirectory('.', t)
100
82
self.assertIsDirectory('.bzr/branch', t)
101
83
self.assertIsDirectory('.bzr/branch/lock', t)
102
84
branch.lock_write()
104
self.assertIsDirectory('.bzr/branch/lock/held', t)
85
self.addCleanup(branch.unlock)
86
self.assertIsDirectory('.bzr/branch/lock/held', t)
108
88
def test_set_push_location(self):
109
from bzrlib.config import (locations_config_filename,
110
ensure_config_dir_exists)
111
ensure_config_dir_exists()
112
fn = locations_config_filename()
113
# write correct newlines to locations.conf
114
# by default ConfigObj uses native line-endings for new files
115
# but uses already existing line-endings if file is not empty
118
f.write('# comment\n')
89
conf = config.LocationConfig.from_string('# comment\n', '.', save=True)
122
91
branch = self.make_branch('.', format='knit')
123
92
branch.set_push_location('foo')
127
96
"push_location = foo\n"
128
97
"push_location:policy = norecurse\n" % local_path,
98
config.locations_config_filename())
131
100
# TODO RBC 20051029 test getting a push location from a branch in a
132
101
# recursive section - that is, it appends the branch name.
135
class SampleBranchFormat(BranchFormat):
104
class SampleBranchFormat(_mod_branch.BranchFormatMetadir):
136
105
"""A sample format
138
107
this format is initializable, unsupported to aid in testing the
139
108
open and open_downlevel routines.
142
def get_format_string(self):
112
def get_format_string(cls):
143
113
"""See BzrBranchFormat.get_format_string()."""
144
114
return "Sample branch format."
146
def initialize(self, a_bzrdir):
116
def initialize(self, a_bzrdir, name=None, repository=None,
117
append_revisions_only=None):
147
118
"""Format 4 branches cannot be created."""
148
t = a_bzrdir.get_branch_transport(self)
119
t = a_bzrdir.get_branch_transport(self, name=name)
149
120
t.put_bytes('format', self.get_format_string())
150
121
return 'A branch'
152
123
def is_supported(self):
155
def open(self, transport, _found=False, ignore_fallbacks=False):
126
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
127
possible_transports=None):
156
128
return "opened branch."
159
class TestBzrBranchFormat(TestCaseWithTransport):
131
# Demonstrating how lazy loading is often implemented:
132
# A constant string is created.
133
SampleSupportedBranchFormatString = "Sample supported branch format."
135
# And the format class can then reference the constant to avoid skew.
136
class SampleSupportedBranchFormat(_mod_branch.BranchFormatMetadir):
137
"""A sample supported format."""
140
def get_format_string(cls):
141
"""See BzrBranchFormat.get_format_string()."""
142
return SampleSupportedBranchFormatString
144
def initialize(self, a_bzrdir, name=None, append_revisions_only=None):
145
t = a_bzrdir.get_branch_transport(self, name=name)
146
t.put_bytes('format', self.get_format_string())
149
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
150
possible_transports=None):
151
return "opened supported branch."
154
class SampleExtraBranchFormat(_mod_branch.BranchFormat):
155
"""A sample format that is not usable in a metadir."""
157
def get_format_string(self):
158
# This format is not usable in a metadir.
161
def network_name(self):
162
# Network name always has to be provided.
165
def initialize(self, a_bzrdir, name=None):
166
raise NotImplementedError(self.initialize)
168
def open(self, transport, name=None, _found=False, ignore_fallbacks=False,
169
possible_transports=None):
170
raise NotImplementedError(self.open)
173
class TestBzrBranchFormat(tests.TestCaseWithTransport):
160
174
"""Tests for the BzrBranchFormat facility."""
162
176
def test_find_format(self):
168
182
dir = format._matchingbzrdir.initialize(url)
169
183
dir.create_repository()
170
184
format.initialize(dir)
171
found_format = BranchFormat.find_format(dir)
172
self.failUnless(isinstance(found_format, format.__class__))
173
check_format(BzrBranchFormat5(), "bar")
185
found_format = _mod_branch.BranchFormatMetadir.find_format(dir)
186
self.assertIsInstance(found_format, format.__class__)
187
check_format(_mod_branch.BzrBranchFormat5(), "bar")
189
def test_find_format_factory(self):
190
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
191
SampleSupportedBranchFormat().initialize(dir)
192
factory = _mod_branch.MetaDirBranchFormatFactory(
193
SampleSupportedBranchFormatString,
194
"bzrlib.tests.test_branch", "SampleSupportedBranchFormat")
195
_mod_branch.format_registry.register(factory)
196
self.addCleanup(_mod_branch.format_registry.remove, factory)
197
b = _mod_branch.Branch.open(self.get_url())
198
self.assertEqual(b, "opened supported branch.")
200
def test_from_string(self):
201
self.assertIsInstance(
202
SampleBranchFormat.from_string("Sample branch format."),
204
self.assertRaises(ValueError,
205
SampleBranchFormat.from_string, "Different branch format.")
175
207
def test_find_format_not_branch(self):
176
208
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
177
self.assertRaises(NotBranchError,
178
BranchFormat.find_format,
209
self.assertRaises(errors.NotBranchError,
210
_mod_branch.BranchFormatMetadir.find_format,
181
213
def test_find_format_unknown_format(self):
182
214
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
183
215
SampleBranchFormat().initialize(dir)
184
self.assertRaises(UnknownFormatError,
185
BranchFormat.find_format,
216
self.assertRaises(errors.UnknownFormatError,
217
_mod_branch.BranchFormatMetadir.find_format,
188
220
def test_register_unregister_format(self):
221
# Test the deprecated format registration functions
189
222
format = SampleBranchFormat()
190
223
# make a control dir
191
224
dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
193
226
format.initialize(dir)
194
227
# register a format for it.
195
BranchFormat.register_format(format)
228
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
229
_mod_branch.BranchFormat.register_format, format)
196
230
# which branch.Open will refuse (not supported)
197
self.assertRaises(UnsupportedFormatError, Branch.open, self.get_url())
231
self.assertRaises(errors.UnsupportedFormatError,
232
_mod_branch.Branch.open, self.get_url())
198
233
self.make_branch_and_tree('foo')
199
234
# but open_downlevel will work
200
self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
237
bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
201
238
# unregister the format
202
BranchFormat.unregister_format(format)
239
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
240
_mod_branch.BranchFormat.unregister_format, format)
203
241
self.make_branch_and_tree('bar')
244
class TestBranchFormatRegistry(tests.TestCase):
247
super(TestBranchFormatRegistry, self).setUp()
248
self.registry = _mod_branch.BranchFormatRegistry()
250
def test_default(self):
251
self.assertIs(None, self.registry.get_default())
252
format = SampleBranchFormat()
253
self.registry.set_default(format)
254
self.assertEquals(format, self.registry.get_default())
256
def test_register_unregister_format(self):
257
format = SampleBranchFormat()
258
self.registry.register(format)
259
self.assertEquals(format,
260
self.registry.get("Sample branch format."))
261
self.registry.remove(format)
262
self.assertRaises(KeyError, self.registry.get,
263
"Sample branch format.")
265
def test_get_all(self):
266
format = SampleBranchFormat()
267
self.assertEquals([], self.registry._get_all())
268
self.registry.register(format)
269
self.assertEquals([format], self.registry._get_all())
271
def test_register_extra(self):
272
format = SampleExtraBranchFormat()
273
self.assertEquals([], self.registry._get_all())
274
self.registry.register_extra(format)
275
self.assertEquals([format], self.registry._get_all())
277
def test_register_extra_lazy(self):
278
self.assertEquals([], self.registry._get_all())
279
self.registry.register_extra_lazy("bzrlib.tests.test_branch",
280
"SampleExtraBranchFormat")
281
formats = self.registry._get_all()
282
self.assertEquals(1, len(formats))
283
self.assertIsInstance(formats[0], SampleExtraBranchFormat)
286
#Used by TestMetaDirBranchFormatFactory
287
FakeLazyFormat = None
290
class TestMetaDirBranchFormatFactory(tests.TestCase):
292
def test_get_format_string_does_not_load(self):
293
"""Formats have a static format string."""
294
factory = _mod_branch.MetaDirBranchFormatFactory("yo", None, None)
295
self.assertEqual("yo", factory.get_format_string())
297
def test_call_loads(self):
298
# __call__ is used by the network_format_registry interface to get a
300
global FakeLazyFormat
302
factory = _mod_branch.MetaDirBranchFormatFactory(None,
303
"bzrlib.tests.test_branch", "FakeLazyFormat")
304
self.assertRaises(AttributeError, factory)
306
def test_call_returns_call_of_referenced_object(self):
307
global FakeLazyFormat
308
FakeLazyFormat = lambda:'called'
309
factory = _mod_branch.MetaDirBranchFormatFactory(None,
310
"bzrlib.tests.test_branch", "FakeLazyFormat")
311
self.assertEqual('called', factory())
206
314
class TestBranch67(object):
207
315
"""Common tests for both branch 6 and 7 which are mostly the same."""
228
336
def test_layout(self):
229
337
branch = self.make_branch('a', format=self.get_format_name())
230
self.failUnlessExists('a/.bzr/branch/last-revision')
231
self.failIfExists('a/.bzr/branch/revision-history')
232
self.failIfExists('a/.bzr/branch/references')
338
self.assertPathExists('a/.bzr/branch/last-revision')
339
self.assertPathDoesNotExist('a/.bzr/branch/revision-history')
340
self.assertPathDoesNotExist('a/.bzr/branch/references')
234
342
def test_config(self):
235
343
"""Ensure that all configuration data is stored in the branch"""
236
344
branch = self.make_branch('a', format=self.get_format_name())
237
branch.set_parent('http://bazaar-vcs.org')
238
self.failIfExists('a/.bzr/branch/parent')
239
self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
240
branch.set_push_location('sftp://bazaar-vcs.org')
345
branch.set_parent('http://example.com')
346
self.assertPathDoesNotExist('a/.bzr/branch/parent')
347
self.assertEqual('http://example.com', branch.get_parent())
348
branch.set_push_location('sftp://example.com')
241
349
config = branch.get_config()._get_branch_data_config()
242
self.assertEqual('sftp://bazaar-vcs.org',
350
self.assertEqual('sftp://example.com',
243
351
config.get_user_option('push_location'))
244
branch.set_bound_location('ftp://bazaar-vcs.org')
245
self.failIfExists('a/.bzr/branch/bound')
246
self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
352
branch.set_bound_location('ftp://example.com')
353
self.assertPathDoesNotExist('a/.bzr/branch/bound')
354
self.assertEqual('ftp://example.com', branch.get_bound_location())
248
356
def test_set_revision_history(self):
249
357
builder = self.make_branch_builder('.', format=self.get_format_name())
254
362
branch = builder.get_branch()
255
363
branch.lock_write()
256
364
self.addCleanup(branch.unlock)
257
branch.set_revision_history(['foo', 'bar'])
258
branch.set_revision_history(['foo'])
365
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
366
branch.set_revision_history, ['foo', 'bar'])
367
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
368
branch.set_revision_history, ['foo'])
259
369
self.assertRaises(errors.NotLefthandHistory,
260
branch.set_revision_history, ['bar'])
370
self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)),
371
branch.set_revision_history, ['bar'])
262
373
def do_checkout_test(self, lightweight=False):
263
374
tree = self.make_branch_and_tree('source',
436
548
branch.lock_write()
437
549
branch.set_reference_info('file-id', 'path2', 'location2')
439
doppelganger = Branch.open('branch')
551
doppelganger = _mod_branch.Branch.open('branch')
440
552
doppelganger.set_reference_info('file-id', 'path3', 'location3')
441
553
self.assertEqual(('path3', 'location3'),
442
554
branch.get_reference_info('file-id'))
444
class TestBranchReference(TestCaseWithTransport):
556
def _recordParentMapCalls(self, repo):
557
self._parent_map_calls = []
558
orig_get_parent_map = repo.revisions.get_parent_map
559
def get_parent_map(q):
561
self._parent_map_calls.extend([e[0] for e in q])
562
return orig_get_parent_map(q)
563
repo.revisions.get_parent_map = get_parent_map
566
class TestBranchReference(tests.TestCaseWithTransport):
445
567
"""Tests for the branch reference facility."""
447
569
def test_create_open_reference(self):
448
570
bzrdirformat = bzrdir.BzrDirMetaFormat1()
449
t = get_transport(self.get_url('.'))
571
t = self.get_transport()
451
573
dir = bzrdirformat.initialize(self.get_url('repo'))
452
574
dir.create_repository()
453
575
target_branch = dir.create_branch()
454
576
t.mkdir('branch')
455
577
branch_dir = bzrdirformat.initialize(self.get_url('branch'))
456
made_branch = BranchReferenceFormat().initialize(branch_dir, target_branch)
578
made_branch = _mod_branch.BranchReferenceFormat().initialize(
579
branch_dir, target_branch=target_branch)
457
580
self.assertEqual(made_branch.base, target_branch.base)
458
581
opened_branch = branch_dir.open_branch()
459
582
self.assertEqual(opened_branch.base, target_branch.base)
470
593
_mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
473
class TestHooks(TestCase):
596
class TestHooks(tests.TestCaseWithTransport):
475
598
def test_constructor(self):
476
599
"""Check that creating a BranchHooks instance has the right defaults."""
477
hooks = BranchHooks()
600
hooks = _mod_branch.BranchHooks()
478
601
self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
479
602
self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
480
603
self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
481
604
self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
482
605
self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
483
self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
606
self.assertTrue("post_uncommit" in hooks,
607
"post_uncommit not in %s" % hooks)
484
608
self.assertTrue("post_change_branch_tip" in hooks,
485
609
"post_change_branch_tip not in %s" % hooks)
610
self.assertTrue("post_branch_init" in hooks,
611
"post_branch_init not in %s" % hooks)
612
self.assertTrue("post_switch" in hooks,
613
"post_switch not in %s" % hooks)
487
615
def test_installed_hooks_are_BranchHooks(self):
488
616
"""The installed hooks object should be a BranchHooks."""
489
617
# the installed hooks are saved in self._preserved_hooks.
490
618
self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch][1],
494
class TestPullResult(TestCase):
619
_mod_branch.BranchHooks)
621
def test_post_branch_init_hook(self):
623
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
625
self.assertLength(0, calls)
626
branch = self.make_branch('a')
627
self.assertLength(1, calls)
629
self.assertIsInstance(params, _mod_branch.BranchInitHookParams)
630
self.assertTrue(hasattr(params, 'bzrdir'))
631
self.assertTrue(hasattr(params, 'branch'))
633
def test_post_branch_init_hook_repr(self):
635
_mod_branch.Branch.hooks.install_named_hook('post_branch_init',
636
lambda params: param_reprs.append(repr(params)), None)
637
branch = self.make_branch('a')
638
self.assertLength(1, param_reprs)
639
param_repr = param_reprs[0]
640
self.assertStartsWith(param_repr, '<BranchInitHookParams of ')
642
def test_post_switch_hook(self):
643
from bzrlib import switch
645
_mod_branch.Branch.hooks.install_named_hook('post_switch',
647
tree = self.make_branch_and_tree('branch-1')
648
self.build_tree(['branch-1/file-1'])
651
to_branch = tree.bzrdir.sprout('branch-2').open_branch()
652
self.build_tree(['branch-1/file-2'])
654
tree.remove('file-1')
656
checkout = tree.branch.create_checkout('checkout')
657
self.assertLength(0, calls)
658
switch.switch(checkout.bzrdir, to_branch)
659
self.assertLength(1, calls)
661
self.assertIsInstance(params, _mod_branch.SwitchHookParams)
662
self.assertTrue(hasattr(params, 'to_branch'))
663
self.assertTrue(hasattr(params, 'revision_id'))
666
class TestBranchOptions(tests.TestCaseWithTransport):
669
super(TestBranchOptions, self).setUp()
670
self.branch = self.make_branch('.')
671
self.config_stack = self.branch.get_config_stack()
673
def check_append_revisions_only(self, expected_value, value=None):
674
"""Set append_revisions_only in config and check its interpretation."""
675
if value is not None:
676
self.config_stack.set('append_revisions_only', value)
677
self.assertEqual(expected_value,
678
self.branch.get_append_revisions_only())
680
def test_valid_append_revisions_only(self):
681
self.assertEquals(None,
682
self.config_stack.get('append_revisions_only'))
683
self.check_append_revisions_only(None)
684
self.check_append_revisions_only(False, 'False')
685
self.check_append_revisions_only(True, 'True')
686
# The following values will cause compatibility problems on projects
687
# using older bzr versions (<2.2) but are accepted
688
self.check_append_revisions_only(False, 'false')
689
self.check_append_revisions_only(True, 'true')
691
def test_invalid_append_revisions_only(self):
692
"""Ensure warning is noted on invalid settings"""
695
self.warnings.append(args[0] % args[1:])
696
self.overrideAttr(trace, 'warning', warning)
697
self.check_append_revisions_only(None, 'not-a-bool')
698
self.assertLength(1, self.warnings)
700
'Value "not-a-bool" is not valid for "append_revisions_only"',
704
class TestPullResult(tests.TestCase):
496
706
def test_pull_result_to_int(self):
497
707
# to support old code, the pull result can be used as an int
708
r = _mod_branch.PullResult()
501
711
# this usage of results is not recommended for new code (because it
502
712
# doesn't describe very well what happened), but for api stability
503
713
# it's still supported
504
a = "%d revisions pulled" % r
505
self.assertEqual(a, "10 revisions pulled")
714
self.assertEqual(self.applyDeprecated(
715
symbol_versioning.deprecated_in((2, 3, 0)),
507
719
def test_report_changed(self):
720
r = _mod_branch.PullResult()
509
721
r.old_revid = "old-revid"
511
723
r.new_revid = "new-revid"
515
727
self.assertEqual("Now on revision 20.\n", f.getvalue())
728
self.assertEqual("Now on revision 20.\n", f.getvalue())
517
730
def test_report_unchanged(self):
731
r = _mod_branch.PullResult()
519
732
r.old_revid = "same-revid"
520
733
r.new_revid = "same-revid"
523
self.assertEqual("No revisions to pull.\n", f.getvalue())
526
class _StubLockable(object):
527
"""Helper for TestRunWithWriteLockedTarget."""
529
def __init__(self, calls, unlock_exc=None):
531
self.unlock_exc = unlock_exc
533
def lock_write(self):
534
self.calls.append('lock_write')
537
self.calls.append('unlock')
538
if self.unlock_exc is not None:
539
raise self.unlock_exc
542
class _ErrorFromCallable(Exception):
543
"""Helper for TestRunWithWriteLockedTarget."""
546
class _ErrorFromUnlock(Exception):
547
"""Helper for TestRunWithWriteLockedTarget."""
550
class TestRunWithWriteLockedTarget(TestCase):
551
"""Tests for _run_with_write_locked_target."""
557
def func_that_returns_ok(self):
558
self._calls.append('func called')
561
def func_that_raises(self):
562
self._calls.append('func called')
563
raise _ErrorFromCallable()
565
def test_success_unlocks(self):
566
lockable = _StubLockable(self._calls)
567
result = _run_with_write_locked_target(
568
lockable, self.func_that_returns_ok)
569
self.assertEqual('ok', result)
570
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
572
def test_exception_unlocks_and_propagates(self):
573
lockable = _StubLockable(self._calls)
574
self.assertRaises(_ErrorFromCallable,
575
_run_with_write_locked_target, lockable, self.func_that_raises)
576
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
578
def test_callable_succeeds_but_error_during_unlock(self):
579
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
580
self.assertRaises(_ErrorFromUnlock,
581
_run_with_write_locked_target, lockable, self.func_that_returns_ok)
582
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
584
def test_error_during_unlock_does_not_mask_original_error(self):
585
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
586
self.assertRaises(_ErrorFromCallable,
587
_run_with_write_locked_target, lockable, self.func_that_raises)
588
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
736
self.assertEqual("No revisions or tags to pull.\n", f.getvalue())