Merge lp:~parthm/bzr/603461-ensure-no-var-named-message into lp:bzr

Proposed by Parth Malwankar
Status: Rejected
Rejected by: Parth Malwankar
Proposed branch: lp:~parthm/bzr/603461-ensure-no-var-named-message
Merge into: lp:bzr
Diff against target: 135 lines (+65/-9)
3 files modified
NEWS (+34/-1)
bzrlib/errors.py (+5/-8)
bzrlib/tests/test_errors.py (+26/-0)
To merge this branch: bzr merge lp:~parthm/bzr/603461-ensure-no-var-named-message
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+29624@code.launchpad.net

Commit message

test to ensure that errors.BzrError subclasses don't use "message" as arg name for __init__ and _fmt (#603461)

Description of the change

This patch adds a test to bt.test_errors to ensure that errors.BzrError subclasses in bzrlib.errors do not have an argument named "message" for __init__ and _fmt as this causes problems with some Python versions (e.g. bug #603461).

To post a comment you must log in.
Revision history for this message
Parth Malwankar (parthm) wrote :

Note that errors.LockError was using "message" and this is also changed to "msg". It doesn't break anything in bzr test suite. I am not sure if any plugins use 'LockError(message="...")' specifically.

5343. By Parth Malwankar

cleanup test case by using isclass rather than catching exception.

5344. By Parth Malwankar

imporved test to check _fmt

5345. By Parth Malwankar

improved assert message.

5346. By Parth Malwankar

improved fmt_pattern and assert message.

Revision history for this message
Parth Malwankar (parthm) wrote :

Unmerged revisions

5346. By Parth Malwankar

improved fmt_pattern and assert message.

5345. By Parth Malwankar

improved assert message.

5344. By Parth Malwankar

imporved test to check _fmt

5343. By Parth Malwankar

cleanup test case by using isclass rather than catching exception.

5342. By Parth Malwankar

updated NEWS

5341. By Parth Malwankar

test case to ensure the errors.exceptions don't use message arg name

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2010-07-08 10:34:12 +0000
+++ NEWS 2010-07-10 05:26:39 +0000
@@ -5,11 +5,44 @@
5.. contents:: List of Releases5.. contents:: List of Releases
6 :depth: 16 :depth: 1
77
8bzr 2.3b1
9#########
10
11:2.3b1: NOT RELEASED YET
12
13Compatibility Breaks
14********************
15
16New Features
17************
18
19Bug Fixes
20*********
21
22Improvements
23************
24
25Documentation
26*************
27
28API Changes
29***********
30
31Internals
32*********
33
34Testing
35*******
36
37* Added test case to disallow argument named "message" for bzrlib.errors
38 exceptions as this breaks on some Python versions.
39 (Parth Malwankar, #603461)
40
8bzr 2.2b441bzr 2.2b4
9#########42#########
1043
11:Codename: Monkey Magic44:Codename: Monkey Magic
12:2.2b4: NOT RELEASED YET45:2.2b4: 2004-07-09
1346
14Compatibility Breaks47Compatibility Breaks
15********************48********************
1649
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2010-07-09 16:16:11 +0000
+++ bzrlib/errors.py 2010-07-10 05:26:39 +0000
@@ -947,11 +947,8 @@
947 # original exception is available as e.original_error947 # original exception is available as e.original_error
948 #948 #
949 # New code should prefer to raise specific subclasses949 # New code should prefer to raise specific subclasses
950 def __init__(self, message):950 def __init__(self, msg):
951 # Python 2.5 uses a slot for StandardError.message,951 self.msg = msg
952 # so use a different variable name. We now work around this in
953 # BzrError.__str__, but this member name is kept for compatability.
954 self.msg = message
955952
956953
957class LockActive(LockError):954class LockActive(LockError):
@@ -1378,12 +1375,12 @@
13781375
1379class WeaveParentMismatch(WeaveError):1376class WeaveParentMismatch(WeaveError):
13801377
1381 _fmt = "Parents are mismatched between two revisions. %(message)s"1378 _fmt = "Parents are mismatched between two revisions. %(msg)s"
13821379
13831380
1384class WeaveInvalidChecksum(WeaveError):1381class WeaveInvalidChecksum(WeaveError):
13851382
1386 _fmt = "Text did not match it's checksum: %(message)s"1383 _fmt = "Text did not match it's checksum: %(msg)s"
13871384
13881385
1389class WeaveTextDiffers(WeaveError):1386class WeaveTextDiffers(WeaveError):
@@ -1437,7 +1434,7 @@
14371434
1438class VersionedFileInvalidChecksum(VersionedFileError):1435class VersionedFileInvalidChecksum(VersionedFileError):
14391436
1440 _fmt = "Text did not match its checksum: %(message)s"1437 _fmt = "Text did not match its checksum: %(msg)s"
14411438
14421439
1443class KnitError(InternalBzrError):1440class KnitError(InternalBzrError):
14441441
=== modified file 'bzrlib/tests/test_errors.py'
--- bzrlib/tests/test_errors.py 2010-07-09 16:16:11 +0000
+++ bzrlib/tests/test_errors.py 2010-07-10 05:26:39 +0000
@@ -16,6 +16,8 @@
1616
17"""Tests for the formatting and construction of errors."""17"""Tests for the formatting and construction of errors."""
1818
19import inspect
20import re
19import socket21import socket
20import sys22import sys
2123
@@ -31,6 +33,30 @@
3133
32class TestErrors(TestCaseWithTransport):34class TestErrors(TestCaseWithTransport):
3335
36 def test_init_arg_names(self):
37 """Ensure the exception.__init__ in errors do not have "message" arg.
38
39 This test fails if any exception.__init__ 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.
42 See bug #603461
43 """
44 fmt_pattern = re.compile("%\(message\)[sir]")
45 for e, v in errors.__dict__.iteritems():
46 init = None
47 fmt = None
48 if inspect.isclass(v) and issubclass(v, errors.BzrError):
49 init = getattr(v, '__init__', None)
50 fmt = getattr(v, '_fmt', None)
51 if init:
52 args = inspect.getargspec(init)[0]
53 self.assertFalse('message' in args,
54 ('Argument name "message" not allowed for '
55 '"errors.%s"' % e))
56 if fmt and fmt_pattern.search(fmt):
57 self.assertFalse(True, ('"message" not allowed in '
58 '"errors.%s._fmt"' % e))
59
34 def test_bad_filename_encoding(self):60 def test_bad_filename_encoding(self):
35 error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')61 error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
36 self.assertEqualDiff(62 self.assertEqualDiff(