Merge lp:~jml/testtools/nicer-regex-fail into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 220
Proposed branch: lp:~jml/testtools/nicer-regex-fail
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 64 lines (+9/-6)
4 files modified
NEWS (+3/-2)
testtools/matchers.py (+2/-1)
testtools/tests/test_matchers.py (+3/-2)
testtools/tests/test_with_with.py (+1/-1)
To merge this branch: bzr merge lp:~jml/testtools/nicer-regex-fail
Reviewer Review Type Date Requested Status
testtools committers Pending
Review via email: mp+69825@code.launchpad.net

Description of the change

Changes the way regexes are displayed:
 * Wraps them in /<regex>/, rather than quotes
 * Uses %s rather than %r, to avoid excess escaping of double slashes

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2011-07-28 09:57:13 +0000
3+++ NEWS 2011-07-29 16:19:34 +0000
4@@ -17,8 +17,9 @@
5 * ``gather_details`` takes two dicts, rather than two detailed objects.
6 (Jonathan Lange, #801027)
7
8-* ``MatchesRegex`` mismatch now says "<value> does not match <regex>" rather
9- than "<regex> did not match <value>"
10+* ``MatchesRegex`` mismatch now says "<value> does not match /<regex>/" rather
11+ than "<regex> did not match <value>". The regular expression contains fewer
12+ backslashes too. (Jonathan Lange, #818079)
13
14 * Tests that run with ``AsynchronousDeferredRunTest`` now have the ``reactor``
15 attribute set to the running reactor. (Jonathan Lange, #720749)
16
17=== modified file 'testtools/matchers.py'
18--- testtools/matchers.py 2011-07-27 19:47:22 +0000
19+++ testtools/matchers.py 2011-07-29 16:19:34 +0000
20@@ -730,7 +730,8 @@
21
22 def match(self, value):
23 if not re.match(self.pattern, value, self.flags):
24- return Mismatch("%r does not match %r" % (value, self.pattern))
25+ return Mismatch("%r does not match /%s/" % (
26+ value, self.pattern))
27
28
29 class MatchesSetwise(object):
30
31=== modified file 'testtools/tests/test_matchers.py'
32--- testtools/tests/test_matchers.py 2011-07-28 09:57:13 +0000
33+++ testtools/tests/test_matchers.py 2011-07-29 16:19:34 +0000
34@@ -258,7 +258,7 @@
35 MatchesException(Exception, 'fo.'))
36 ]
37 describe_examples = [
38- ("'bar' does not match 'fo.'",
39+ ("'bar' does not match /fo./",
40 error_bar, MatchesException(ValueError, "fo.")),
41 ]
42
43@@ -639,7 +639,8 @@
44 ]
45
46 describe_examples = [
47- ("'c' does not match 'a|b'", 'c', MatchesRegex('a|b')),
48+ ("'c' does not match /a|b/", 'c', MatchesRegex('a|b')),
49+ ("'c' does not match /a\d/", 'c', MatchesRegex(r'a\d')),
50 ]
51
52
53
54=== modified file 'testtools/tests/test_with_with.py'
55--- testtools/tests/test_with_with.py 2011-07-27 19:50:41 +0000
56+++ testtools/tests/test_with_with.py 2011-07-29 16:19:34 +0000
57@@ -32,7 +32,7 @@
58 raise ValueError('mismatch')
59 except AssertionError:
60 e = sys.exc_info()[1]
61- self.assertEqual("'mismatch' does not match 'tes.'", str(e))
62+ self.assertEqual("'mismatch' does not match /tes./", str(e))
63 else:
64 self.fail('AssertionError not raised.')
65

Subscribers

People subscribed via source and target branches