9
10
from bzrlib import errors
10
11
from bzrlib.branch import Branch
11
12
from bzrlib.bzrdir import format_registry
13
from bzrlib import trace
12
14
from bzrlib.tests import (
13
multiply_tests, TestCaseWithTransport, TestLoader, TestNotApplicable)
15
multiply_tests, TestCase, TestCaseWithTransport, TestLoader,
15
18
from bzrlib.tests.per_branch import TestCaseWithBzrDir, branch_scenarios
16
19
except ImportError:
17
20
from bzrlib.tests.branch_implementations import (
18
21
TestCaseWithBzrDir, branch_scenarios)
19
22
from lp.codehosting.bzrutils import (
20
DenyingServer, get_branch_stacked_on_url, is_branch_stackable)
23
add_exception_logging_hook, DenyingServer, get_branch_stacked_on_url,
24
is_branch_stackable, remove_exception_logging_hook)
21
25
from lp.codehosting.tests.helpers import TestResultWrapper
45
49
def testGetBranchStackedOnUrl(self):
46
50
# get_branch_stacked_on_url returns the URL of the stacked-on branch.
47
stacked_on_branch = self.make_branch('stacked-on')
51
self.make_branch('stacked-on')
48
52
stacked_branch = self.make_branch('stacked')
50
54
stacked_branch.set_stacked_on_url('../stacked-on')
130
134
Branch.open(branch.base)
137
class TestExceptionLoggingHooks(TestCase):
139
def logException(self, exception):
140
"""Log exception with Bazaar's exception logger."""
143
except exception.__class__:
144
trace.log_exception_quietly()
146
def test_calls_hook_when_added(self):
147
# add_exception_logging_hook adds a hook function that's called
148
# whenever Bazaar logs an exception.
151
exceptions.append(sys.exc_info()[:2])
152
add_exception_logging_hook(hook)
153
self.addCleanup(remove_exception_logging_hook, hook)
154
exception = RuntimeError('foo')
155
self.logException(exception)
156
self.assertEqual([(RuntimeError, exception)], exceptions)
158
def test_doesnt_call_hook_when_removed(self):
159
# remove_exception_logging_hook removes the hook function, ensuring
160
# it's not called when Bazaar logs an exception.
163
exceptions.append(sys.exc_info()[:2])
164
add_exception_logging_hook(hook)
165
remove_exception_logging_hook(hook)
166
self.logException(RuntimeError('foo'))
167
self.assertEqual([], exceptions)
133
170
def load_tests(basic_tests, module, loader):
134
171
"""Parametrize the tests of get_branch_stacked_on_url by branch format."""
135
172
result = loader.suiteClass()