Rev 5015: Fix per_branch/test_hooks.py imports. in file:///home/vila/src/bzr/cleanup/test-imports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Feb 5 14:06:57 GMT 2010
At file:///home/vila/src/bzr/cleanup/test-imports/
------------------------------------------------------------
revno: 5015
revision-id: v.ladeuil+lp at free.fr-20100205140657-vuf3jmbfa99zf8dq
parent: v.ladeuil+lp at free.fr-20100205135614-r8n0j0siarz4bmr8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: test-imports
timestamp: Fri 2010-02-05 15:06:57 +0100
message:
Fix per_branch/test_hooks.py imports.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_branch/test_hooks.py'
--- a/bzrlib/tests/per_branch/test_hooks.py 2010-01-08 05:28:17 +0000
+++ b/bzrlib/tests/per_branch/test_hooks.py 2010-02-05 14:06:57 +0000
@@ -16,15 +16,17 @@
"""Tests that branch classes implement hook callouts correctly."""
-from bzrlib.branch import Branch, ChangeBranchTipParams
-from bzrlib.errors import HookFailed, TipChangeRejected
-from bzrlib.remote import RemoteBranch
-from bzrlib.revision import NULL_REVISION
+from bzrlib import (
+ branch as _mod_branch,
+ errors,
+ remote,
+ revision,
+ tests,
+ )
from bzrlib.smart import server
-from bzrlib.tests import TestCaseWithMemoryTransport
-
-
-class ChangeBranchTipTestCase(TestCaseWithMemoryTransport):
+
+
+class ChangeBranchTipTestCase(tests.TestCaseWithMemoryTransport):
"""Base TestCase for testing pre/post_change_branch_tip hooks."""
def install_logging_hook(self, prefix):
@@ -33,7 +35,7 @@
:returns: the list that the calls will be appended to.
"""
hook_calls = []
- Branch.hooks.install_named_hook(
+ _mod_branch.Branch.hooks.install_named_hook(
prefix + '_change_branch_tip', hook_calls.append, None)
return hook_calls
@@ -53,7 +55,7 @@
pre=False):
if hook_calls is None:
hook_calls = self.hook_calls
- if isinstance(branch, RemoteBranch):
+ if isinstance(branch, remote.RemoteBranch):
# For a remote branch, both the server and the client will raise
# this hook, and we see both in the test environment. The remote
# instance comes in between the clients - the client doe pre, the
@@ -72,7 +74,7 @@
def setUp(self):
self.hook_calls = []
- TestCaseWithMemoryTransport.setUp(self)
+ super(TestSetRevisionHistoryHook, self).setUp()
def capture_set_rh_hook(self, branch, rev_history):
"""Capture post set-rh hook calls to self.hook_calls.
@@ -84,8 +86,8 @@
def test_set_rh_empty_history(self):
branch = self.make_branch('source')
- Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
- None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'set_rh', self.capture_set_rh_hook, None)
branch.set_revision_history([])
expected_params = ('set_rh', branch, [], True)
self.assertHookCalls(expected_params, branch)
@@ -98,8 +100,8 @@
tree.commit('empty commit', rev_id='foo')
tree.unlock()
branch = tree.branch
- Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
- None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'set_rh', self.capture_set_rh_hook, None)
# some branches require that their history be set to a revision in the
# repository
branch.set_revision_history(['f\xc2\xb5'])
@@ -108,23 +110,23 @@
def test_set_rh_branch_is_locked(self):
branch = self.make_branch('source')
- Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
- None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'set_rh', self.capture_set_rh_hook, None)
branch.set_revision_history([])
expected_params = ('set_rh', branch, [], True)
self.assertHookCalls(expected_params, branch)
def test_set_rh_calls_all_hooks_no_errors(self):
branch = self.make_branch('source')
- Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
- None)
- Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
- None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'set_rh', self.capture_set_rh_hook, None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'set_rh', self.capture_set_rh_hook, None)
branch.set_revision_history([])
expected_calls = [('set_rh', branch, [], True),
('set_rh', branch, [], True),
]
- if isinstance(branch, RemoteBranch):
+ if isinstance(branch, remote.RemoteBranch):
# For a remote branch, both the server and the client will raise
# set_rh, and the server will do so first because that is where
# the change takes place.
@@ -134,19 +136,20 @@
self.assertEqual(expected_calls, self.hook_calls)
-class TestOpen(TestCaseWithMemoryTransport):
+class TestOpen(tests.TestCaseWithMemoryTransport):
def capture_hook(self, branch):
self.hook_calls.append(branch)
def install_hook(self):
self.hook_calls = []
- Branch.hooks.install_named_hook('open', self.capture_hook, None)
+ _mod_branch.Branch.hooks.install_named_hook(
+ 'open', self.capture_hook, None)
def test_create(self):
self.install_hook()
b = self.make_branch('.')
- if isinstance(b, RemoteBranch):
+ if isinstance(b, remote.RemoteBranch):
# RemoteBranch creation:
if (self.transport_readonly_server ==
server.ReadonlySmartTCPServer_for_testing_v2_only):
@@ -170,8 +173,8 @@
def test_open(self):
branch_url = self.make_branch('.').bzrdir.root_transport.base
self.install_hook()
- b = Branch.open(branch_url)
- if isinstance(b, RemoteBranch):
+ b = _mod_branch.Branch.open(branch_url)
+ if isinstance(b, remote.RemoteBranch):
self.assertEqual(3, len(self.hook_calls))
# open_branchV2 RPC
self.assertRealBranch(self.hook_calls[0])
@@ -185,8 +188,8 @@
def assertRealBranch(self, b):
# Branches opened on the server don't have comparable URLs, so we just
# assert that it is not a RemoteBranch.
- self.assertIsInstance(b, Branch)
- self.assertFalse(isinstance(b, RemoteBranch))
+ self.assertIsInstance(b, _mod_branch.Branch)
+ self.assertFalse(isinstance(b, remote.RemoteBranch))
class TestPreChangeBranchTip(ChangeBranchTipTestCase):
@@ -203,9 +206,9 @@
def assertBranchAtRevision1(params):
self.assertEquals(
(1, 'revid-one'), params.branch.last_revision_info())
- Branch.hooks.install_named_hook(
+ _mod_branch.Branch.hooks.install_named_hook(
'pre_change_branch_tip', assertBranchAtRevision1, None)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
def test_hook_failure_prevents_change(self):
"""If a hook raises an exception, the change does not take effect."""
@@ -215,19 +218,20 @@
pass
def hook_that_raises(params):
raise PearShapedError()
- Branch.hooks.install_named_hook(
+ _mod_branch.Branch.hooks.install_named_hook(
'pre_change_branch_tip', hook_that_raises, None)
hook_failed_exc = self.assertRaises(
- PearShapedError, branch.set_last_revision_info, 0, NULL_REVISION)
+ PearShapedError,
+ branch.set_last_revision_info, 0, revision.NULL_REVISION)
# The revision info is unchanged.
self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
def test_empty_history(self):
branch = self.make_branch('source')
hook_calls = self.install_logging_hook('pre')
- branch.set_last_revision_info(0, NULL_REVISION)
- expected_params = ChangeBranchTipParams(
- branch, 0, 0, NULL_REVISION, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
+ expected_params = _mod_branch.ChangeBranchTipParams(
+ branch, 0, 0, revision.NULL_REVISION, revision.NULL_REVISION)
self.assertHookCalls(expected_params, branch, hook_calls, pre=True)
def test_nonempty_history(self):
@@ -238,7 +242,7 @@
'one-\xc2\xb5', 'two-\xc2\xb5')
hook_calls = self.install_logging_hook('pre')
branch.set_last_revision_info(1, 'one-\xc2\xb5')
- expected_params = ChangeBranchTipParams(
+ expected_params = _mod_branch.ChangeBranchTipParams(
branch, 2, 1, 'two-\xc2\xb5', 'one-\xc2\xb5')
self.assertHookCalls(expected_params, branch, hook_calls, pre=True)
@@ -246,9 +250,9 @@
branch = self.make_branch('source')
def assertBranchIsLocked(params):
self.assertTrue(params.branch.is_locked())
- Branch.hooks.install_named_hook(
+ _mod_branch.Branch.hooks.install_named_hook(
'pre_change_branch_tip', assertBranchIsLocked, None)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
def test_calls_all_hooks_no_errors(self):
"""If multiple hooks are registered, all are called (if none raise
@@ -258,9 +262,9 @@
hook_calls_1 = self.install_logging_hook('pre')
hook_calls_2 = self.install_logging_hook('pre')
self.assertIsNot(hook_calls_1, hook_calls_2)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
# Both hooks are called.
- if isinstance(branch, RemoteBranch):
+ if isinstance(branch, remote.RemoteBranch):
count = 2
else:
count = 1
@@ -275,11 +279,12 @@
branch = self.make_branch_with_revision_ids(
'one-\xc2\xb5', 'two-\xc2\xb5')
def hook_that_rejects(params):
- raise TipChangeRejected('rejection message')
- Branch.hooks.install_named_hook(
+ raise errors.TipChangeRejected('rejection message')
+ _mod_branch.Branch.hooks.install_named_hook(
'pre_change_branch_tip', hook_that_rejects, None)
self.assertRaises(
- TipChangeRejected, branch.set_last_revision_info, 0, NULL_REVISION)
+ errors.TipChangeRejected,
+ branch.set_last_revision_info, 0, revision.NULL_REVISION)
# The revision info is unchanged.
self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
@@ -297,17 +302,17 @@
branch = self.make_branch_with_revision_ids('revid-one')
def assertBranchAtRevision1(params):
self.assertEquals(
- (0, NULL_REVISION), params.branch.last_revision_info())
- Branch.hooks.install_named_hook(
+ (0, revision.NULL_REVISION), params.branch.last_revision_info())
+ _mod_branch.Branch.hooks.install_named_hook(
'post_change_branch_tip', assertBranchAtRevision1, None)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
def test_empty_history(self):
branch = self.make_branch('source')
hook_calls = self.install_logging_hook('post')
- branch.set_last_revision_info(0, NULL_REVISION)
- expected_params = ChangeBranchTipParams(
- branch, 0, 0, NULL_REVISION, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
+ expected_params = _mod_branch.ChangeBranchTipParams(
+ branch, 0, 0, revision.NULL_REVISION, revision.NULL_REVISION)
self.assertHookCalls(expected_params, branch, hook_calls)
def test_nonempty_history(self):
@@ -318,7 +323,7 @@
'one-\xc2\xb5', 'two-\xc2\xb5')
hook_calls = self.install_logging_hook('post')
branch.set_last_revision_info(1, 'one-\xc2\xb5')
- expected_params = ChangeBranchTipParams(
+ expected_params = _mod_branch.ChangeBranchTipParams(
branch, 2, 1, 'two-\xc2\xb5', 'one-\xc2\xb5')
self.assertHookCalls(expected_params, branch, hook_calls)
@@ -327,9 +332,9 @@
branch = self.make_branch('source')
def assertBranchIsLocked(params):
self.assertTrue(params.branch.is_locked())
- Branch.hooks.install_named_hook(
+ _mod_branch.Branch.hooks.install_named_hook(
'post_change_branch_tip', assertBranchIsLocked, None)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
def test_calls_all_hooks_no_errors(self):
"""If multiple hooks are registered, all are called (if none raise
@@ -339,9 +344,9 @@
hook_calls_1 = self.install_logging_hook('post')
hook_calls_2 = self.install_logging_hook('post')
self.assertIsNot(hook_calls_1, hook_calls_2)
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
# Both hooks are called.
- if isinstance(branch, RemoteBranch):
+ if isinstance(branch, remote.RemoteBranch):
count = 2
else:
count = 1
@@ -373,7 +378,7 @@
"""
# Check for the number of invocations expected. One invocation is
# local, one is remote (if the branch is remote).
- if smart_enabled and isinstance(branch, RemoteBranch):
+ if smart_enabled and isinstance(branch, remote.RemoteBranch):
length = 2
else:
length = 1
@@ -387,12 +392,12 @@
def test_set_last_revision_info(self):
branch = self.make_branch('')
- branch.set_last_revision_info(0, NULL_REVISION)
+ branch.set_last_revision_info(0, revision.NULL_REVISION)
self.assertPreAndPostHooksWereInvoked(branch, True)
def test_generate_revision_history(self):
branch = self.make_branch('')
- branch.generate_revision_history(NULL_REVISION)
+ branch.generate_revision_history(revision.NULL_REVISION)
# NB: for HPSS protocols < v3, the server does not invoke branch tip
# change events on generate_revision_history, as the change is done
# directly by the client over the VFS.
More information about the bazaar-commits
mailing list