323
323
def test_layout(self):
324
324
branch = self.make_branch('a', format=self.get_format_name())
325
self.failUnlessExists('a/.bzr/branch/last-revision')
326
self.failIfExists('a/.bzr/branch/revision-history')
327
self.failIfExists('a/.bzr/branch/references')
325
self.assertPathExists('a/.bzr/branch/last-revision')
326
self.assertPathDoesNotExist('a/.bzr/branch/revision-history')
327
self.assertPathDoesNotExist('a/.bzr/branch/references')
329
329
def test_config(self):
330
330
"""Ensure that all configuration data is stored in the branch"""
331
331
branch = self.make_branch('a', format=self.get_format_name())
332
332
branch.set_parent('http://example.com')
333
self.failIfExists('a/.bzr/branch/parent')
333
self.assertPathDoesNotExist('a/.bzr/branch/parent')
334
334
self.assertEqual('http://example.com', branch.get_parent())
335
335
branch.set_push_location('sftp://example.com')
336
336
config = branch.get_config()._get_branch_data_config()
337
337
self.assertEqual('sftp://example.com',
338
338
config.get_user_option('push_location'))
339
339
branch.set_bound_location('ftp://example.com')
340
self.failIfExists('a/.bzr/branch/bound')
340
self.assertPathDoesNotExist('a/.bzr/branch/bound')
341
341
self.assertEqual('ftp://example.com', branch.get_bound_location())
343
343
def test_set_revision_history(self):
349
349
branch = builder.get_branch()
350
350
branch.lock_write()
351
351
self.addCleanup(branch.unlock)
352
branch.set_revision_history(['foo', 'bar'])
353
branch.set_revision_history(['foo'])
352
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
353
branch.set_revision_history, ['foo', 'bar'])
354
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
355
branch.set_revision_history, ['foo'])
354
356
self.assertRaises(errors.NotLefthandHistory,
355
branch.set_revision_history, ['bar'])
357
self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)),
358
branch.set_revision_history, ['bar'])
357
360
def do_checkout_test(self, lightweight=False):
358
361
tree = self.make_branch_and_tree('source',
371
374
subtree.commit('a subtree file')
372
375
subsubtree.commit('a subsubtree file')
373
376
tree.branch.create_checkout('target', lightweight=lightweight)
374
self.failUnlessExists('target')
375
self.failUnlessExists('target/subtree')
376
self.failUnlessExists('target/subtree/file')
377
self.failUnlessExists('target/subtree/subsubtree/file')
377
self.assertPathExists('target')
378
self.assertPathExists('target/subtree')
379
self.assertPathExists('target/subtree/file')
380
self.assertPathExists('target/subtree/subsubtree/file')
378
381
subbranch = _mod_branch.Branch.open('target/subtree/subsubtree')
380
383
self.assertEndsWith(subbranch.base, 'source/subtree/subsubtree/')
709
712
self.assertEqual("No revisions to pull.\n", f.getvalue())
712
class _StubLockable(object):
713
"""Helper for TestRunWithWriteLockedTarget."""
715
def __init__(self, calls, unlock_exc=None):
717
self.unlock_exc = unlock_exc
719
def lock_write(self):
720
self.calls.append('lock_write')
723
self.calls.append('unlock')
724
if self.unlock_exc is not None:
725
raise self.unlock_exc
728
class _ErrorFromCallable(Exception):
729
"""Helper for TestRunWithWriteLockedTarget."""
732
class _ErrorFromUnlock(Exception):
733
"""Helper for TestRunWithWriteLockedTarget."""
736
class TestRunWithWriteLockedTarget(tests.TestCase):
737
"""Tests for _run_with_write_locked_target."""
740
tests.TestCase.setUp(self)
743
def func_that_returns_ok(self):
744
self._calls.append('func called')
747
def func_that_raises(self):
748
self._calls.append('func called')
749
raise _ErrorFromCallable()
751
def test_success_unlocks(self):
752
lockable = _StubLockable(self._calls)
753
result = _mod_branch._run_with_write_locked_target(
754
lockable, self.func_that_returns_ok)
755
self.assertEqual('ok', result)
756
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
758
def test_exception_unlocks_and_propagates(self):
759
lockable = _StubLockable(self._calls)
760
self.assertRaises(_ErrorFromCallable,
761
_mod_branch._run_with_write_locked_target,
762
lockable, self.func_that_raises)
763
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
765
def test_callable_succeeds_but_error_during_unlock(self):
766
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
767
self.assertRaises(_ErrorFromUnlock,
768
_mod_branch._run_with_write_locked_target,
769
lockable, self.func_that_returns_ok)
770
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)
772
def test_error_during_unlock_does_not_mask_original_error(self):
773
lockable = _StubLockable(self._calls, unlock_exc=_ErrorFromUnlock())
774
self.assertRaises(_ErrorFromCallable,
775
_mod_branch._run_with_write_locked_target,
776
lockable, self.func_that_raises)
777
self.assertEqual(['lock_write', 'func called', 'unlock'], self._calls)