31
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
29
from bzrlib.tests import TestCase, TestCaseWithTransport
34
32
class TestErrors(TestCaseWithTransport):
36
def test_no_arg_named_message(self):
37
"""Ensure the __init__ and _fmt in errors do not have "message" arg.
39
This test fails if __init__ or _fmt in errors has an argument
40
named "message" as this can cause errors in some Python versions.
41
Python 2.5 uses a slot for StandardError.message.
44
fmt_pattern = re.compile("%\(message\)[sir]")
45
subclasses_present = getattr(errors.BzrError, '__subclasses__', None)
46
if not subclasses_present:
47
raise TestSkipped('__subclasses__ attribute required for classes. '
48
'Requires Python 2.5 or later.')
49
for c in errors.BzrError.__subclasses__():
50
init = getattr(c, '__init__', None)
51
fmt = getattr(c, '_fmt', None)
53
args = inspect.getargspec(init)[0]
54
self.assertFalse('message' in args,
55
('Argument name "message" not allowed for '
56
'"errors.%s.__init__"' % c.__name__))
57
if fmt and fmt_pattern.search(fmt):
58
self.assertFalse(True, ('"message" not allowed in '
59
'"errors.%s._fmt"' % c.__name__))
61
34
def test_bad_filename_encoding(self):
62
35
error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
63
36
self.assertEqualDiff(
159
132
"cannot be broken.",
162
def test_lock_corrupt(self):
163
error = errors.LockCorrupt("corruption info")
164
self.assertEqualDiff("Lock is apparently held, but corrupted: "
166
"Use 'bzr break-lock' to clear it",
169
135
def test_knit_data_stream_incompatible(self):
170
136
error = errors.KnitDataStreamIncompatible(
171
137
'stream format', 'target format')
694
660
self.assertEqualDiff("Invalid pattern(s) found. Bad pattern msg.",
697
def test_recursive_bind(self):
663
def test_invalid_pattern(self):
698
664
error = errors.RecursiveBind('foo_bar_branch')
699
665
msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
700
666
'Please use `bzr unbind` to fix.')