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

Proposed by Parth Malwankar on 2010-07-10
Status: Rejected
Rejected by: Parth Malwankar on 2010-07-14
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 2010-07-10 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.
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 on 2010-07-10

cleanup test case by using isclass rather than catching exception.

5344. By Parth Malwankar on 2010-07-10

imporved test to check _fmt

5345. By Parth Malwankar on 2010-07-10

improved assert message.

5346. By Parth Malwankar on 2010-07-10

improved fmt_pattern and assert message.

Parth Malwankar (parthm) wrote :

Unmerged revisions

5346. By Parth Malwankar on 2010-07-10

improved fmt_pattern and assert message.

5345. By Parth Malwankar on 2010-07-10

improved assert message.

5344. By Parth Malwankar on 2010-07-10

imporved test to check _fmt

5343. By Parth Malwankar on 2010-07-10

cleanup test case by using isclass rather than catching exception.

5342. By Parth Malwankar on 2010-07-10

updated NEWS

5341. By Parth Malwankar on 2010-07-10

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
1=== modified file 'NEWS'
2--- NEWS 2010-07-08 10:34:12 +0000
3+++ NEWS 2010-07-10 05:26:39 +0000
4@@ -5,11 +5,44 @@
5 .. contents:: List of Releases
6 :depth: 1
7
8+bzr 2.3b1
9+#########
10+
11+:2.3b1: NOT RELEASED YET
12+
13+Compatibility Breaks
14+********************
15+
16+New Features
17+************
18+
19+Bug Fixes
20+*********
21+
22+Improvements
23+************
24+
25+Documentation
26+*************
27+
28+API Changes
29+***********
30+
31+Internals
32+*********
33+
34+Testing
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+
41 bzr 2.2b4
42 #########
43
44 :Codename: Monkey Magic
45-:2.2b4: NOT RELEASED YET
46+:2.2b4: 2004-07-09
47
48 Compatibility Breaks
49 ********************
50
51=== modified file 'bzrlib/errors.py'
52--- bzrlib/errors.py 2010-07-09 16:16:11 +0000
53+++ bzrlib/errors.py 2010-07-10 05:26:39 +0000
54@@ -947,11 +947,8 @@
55 # original exception is available as e.original_error
56 #
57 # New code should prefer to raise specific subclasses
58- def __init__(self, message):
59- # Python 2.5 uses a slot for StandardError.message,
60- # so use a different variable name. We now work around this in
61- # BzrError.__str__, but this member name is kept for compatability.
62- self.msg = message
63+ def __init__(self, msg):
64+ self.msg = msg
65
66
67 class LockActive(LockError):
68@@ -1378,12 +1375,12 @@
69
70 class WeaveParentMismatch(WeaveError):
71
72- _fmt = "Parents are mismatched between two revisions. %(message)s"
73+ _fmt = "Parents are mismatched between two revisions. %(msg)s"
74
75
76 class WeaveInvalidChecksum(WeaveError):
77
78- _fmt = "Text did not match it's checksum: %(message)s"
79+ _fmt = "Text did not match it's checksum: %(msg)s"
80
81
82 class WeaveTextDiffers(WeaveError):
83@@ -1437,7 +1434,7 @@
84
85 class VersionedFileInvalidChecksum(VersionedFileError):
86
87- _fmt = "Text did not match its checksum: %(message)s"
88+ _fmt = "Text did not match its checksum: %(msg)s"
89
90
91 class KnitError(InternalBzrError):
92
93=== modified file 'bzrlib/tests/test_errors.py'
94--- bzrlib/tests/test_errors.py 2010-07-09 16:16:11 +0000
95+++ bzrlib/tests/test_errors.py 2010-07-10 05:26:39 +0000
96@@ -16,6 +16,8 @@
97
98 """Tests for the formatting and construction of errors."""
99
100+import inspect
101+import re
102 import socket
103 import sys
104
105@@ -31,6 +33,30 @@
106
107 class TestErrors(TestCaseWithTransport):
108
109+ def test_init_arg_names(self):
110+ """Ensure the exception.__init__ in errors do not have "message" arg.
111+
112+ This test fails if any exception.__init__ in errors has an argument
113+ named "message" as this can cause errors in some Python versions.
114+ Python 2.5 uses a slot for StandardError.message.
115+ See bug #603461
116+ """
117+ fmt_pattern = re.compile("%\(message\)[sir]")
118+ for e, v in errors.__dict__.iteritems():
119+ init = None
120+ fmt = None
121+ if inspect.isclass(v) and issubclass(v, errors.BzrError):
122+ init = getattr(v, '__init__', None)
123+ fmt = getattr(v, '_fmt', None)
124+ if init:
125+ args = inspect.getargspec(init)[0]
126+ self.assertFalse('message' in args,
127+ ('Argument name "message" not allowed for '
128+ '"errors.%s"' % e))
129+ if fmt and fmt_pattern.search(fmt):
130+ self.assertFalse(True, ('"message" not allowed in '
131+ '"errors.%s._fmt"' % e))
132+
133 def test_bad_filename_encoding(self):
134 error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
135 self.assertEqualDiff(