Rev 5058: (parthm) test to ensure that errors.BzrError subclasses don't use "message" in file:///home/pqm/archives/thelove/bzr/2.2/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Jul 14 15:22:44 BST 2010
At file:///home/pqm/archives/thelove/bzr/2.2/
------------------------------------------------------------
revno: 5058 [merge]
revision-id: pqm at pqm.ubuntu.com-20100714142240-5iwpamdlnhpvv5l2
parent: pqm at pqm.ubuntu.com-20100714112606-5np7a19rr1t1pzm4
parent: parth.malwankar at gmail.com-20100714095447-4oc6xo1jecz65qyc
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.2
timestamp: Wed 2010-07-14 15:22:40 +0100
message:
(parthm) test to ensure that errors.BzrError subclasses don't use "message"
as arg name for __init__ and _fmt (#603461) (Parth Malwankar)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
=== modified file 'NEWS'
--- a/NEWS 2010-07-14 06:34:38 +0000
+++ b/NEWS 2010-07-14 14:22:40 +0000
@@ -14,6 +14,12 @@
Compatibility Breaks
********************
+* BzrError subclasses no longer support the name "message" to be used
+ as an argument for __init__ or in _fmt format specification as this
+ breaks in some Python versions. errors.LockError.__init__ argument
+ is now named "msg" instead of earlier "message".
+ (Parth Malwankar, #603461)
+
New Features
************
@@ -45,6 +51,9 @@
Testing
*******
+* Unit test added to ensure that "message" is not uses as a format variable
+ name in BzrError subclasses as this conflicts with some Python versions.
+ (Parth Malwankar, #603461)
bzr 2.2b4
#########
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2010-07-14 08:53:58 +0000
+++ b/bzrlib/errors.py 2010-07-14 14:22:40 +0000
@@ -947,11 +947,8 @@
# original exception is available as e.original_error
#
# New code should prefer to raise specific subclasses
- def __init__(self, message):
- # Python 2.5 uses a slot for StandardError.message,
- # so use a different variable name. We now work around this in
- # BzrError.__str__, but this member name is kept for compatability.
- self.msg = message
+ def __init__(self, msg):
+ self.msg = msg
class LockActive(LockError):
@@ -1378,12 +1375,12 @@
class WeaveParentMismatch(WeaveError):
- _fmt = "Parents are mismatched between two revisions. %(message)s"
+ _fmt = "Parents are mismatched between two revisions. %(msg)s"
class WeaveInvalidChecksum(WeaveError):
- _fmt = "Text did not match it's checksum: %(message)s"
+ _fmt = "Text did not match it's checksum: %(msg)s"
class WeaveTextDiffers(WeaveError):
@@ -1437,7 +1434,7 @@
class VersionedFileInvalidChecksum(VersionedFileError):
- _fmt = "Text did not match its checksum: %(message)s"
+ _fmt = "Text did not match its checksum: %(msg)s"
class KnitError(InternalBzrError):
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2010-07-14 09:00:12 +0000
+++ b/bzrlib/tests/test_errors.py 2010-07-14 14:22:40 +0000
@@ -16,6 +16,8 @@
"""Tests for the formatting and construction of errors."""
+import inspect
+import re
import socket
import sys
@@ -26,11 +28,36 @@
symbol_versioning,
urlutils,
)
-from bzrlib.tests import TestCase, TestCaseWithTransport
+from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
class TestErrors(TestCaseWithTransport):
+ def test_no_arg_named_message(self):
+ """Ensure the __init__ and _fmt in errors do not have "message" arg.
+
+ This test fails if __init__ or _fmt in errors has an argument
+ named "message" as this can cause errors in some Python versions.
+ Python 2.5 uses a slot for StandardError.message.
+ See bug #603461
+ """
+ fmt_pattern = re.compile("%\(message\)[sir]")
+ subclasses_present = getattr(errors.BzrError, '__subclasses__', None)
+ if not subclasses_present:
+ raise TestSkipped('__subclasses__ attribute required for classes. '
+ 'Requires Python 2.5 or later.')
+ for c in errors.BzrError.__subclasses__():
+ init = getattr(c, '__init__', None)
+ fmt = getattr(c, '_fmt', None)
+ if init:
+ args = inspect.getargspec(init)[0]
+ self.assertFalse('message' in args,
+ ('Argument name "message" not allowed for '
+ '"errors.%s.__init__"' % c.__name__))
+ if fmt and fmt_pattern.search(fmt):
+ self.assertFalse(True, ('"message" not allowed in '
+ '"errors.%s._fmt"' % c.__name__))
+
def test_bad_filename_encoding(self):
error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
self.assertEqualDiff(
More information about the bazaar-commits
mailing list