← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/nicer-regex-fail into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/nicer-regex-fail into lp:testtools.

Requested reviews:
  testtools committers (testtools-committers)

For more details, see:
https://code.launchpad.net/~jml/testtools/nicer-regex-fail/+merge/69825

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
-- 
https://code.launchpad.net/~jml/testtools/nicer-regex-fail/+merge/69825
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'NEWS'
--- NEWS	2011-07-28 09:57:13 +0000
+++ NEWS	2011-07-29 16:19:28 +0000
@@ -17,8 +17,9 @@
 * ``gather_details`` takes two dicts, rather than two detailed objects.
   (Jonathan Lange, #801027)
 
-* ``MatchesRegex`` mismatch now says "<value> does not match <regex>" rather
-  than "<regex> did not match <value>"
+* ``MatchesRegex`` mismatch now says "<value> does not match /<regex>/" rather
+  than "<regex> did not match <value>". The regular expression contains fewer
+  backslashes too. (Jonathan Lange, #818079)
 
 * Tests that run with ``AsynchronousDeferredRunTest`` now have the ``reactor``
   attribute set to the running reactor. (Jonathan Lange, #720749)

=== modified file 'testtools/matchers.py'
--- testtools/matchers.py	2011-07-27 19:47:22 +0000
+++ testtools/matchers.py	2011-07-29 16:19:28 +0000
@@ -730,7 +730,8 @@
 
     def match(self, value):
         if not re.match(self.pattern, value, self.flags):
-            return Mismatch("%r does not match %r" % (value, self.pattern))
+            return Mismatch("%r does not match /%s/" % (
+                    value, self.pattern))
 
 
 class MatchesSetwise(object):

=== modified file 'testtools/tests/test_matchers.py'
--- testtools/tests/test_matchers.py	2011-07-28 09:57:13 +0000
+++ testtools/tests/test_matchers.py	2011-07-29 16:19:28 +0000
@@ -258,7 +258,7 @@
          MatchesException(Exception, 'fo.'))
         ]
     describe_examples = [
-        ("'bar' does not match 'fo.'",
+        ("'bar' does not match /fo./",
          error_bar, MatchesException(ValueError, "fo.")),
         ]
 
@@ -639,7 +639,8 @@
         ]
 
     describe_examples = [
-        ("'c' does not match 'a|b'", 'c', MatchesRegex('a|b')),
+        ("'c' does not match /a|b/", 'c', MatchesRegex('a|b')),
+        ("'c' does not match /a\d/", 'c', MatchesRegex(r'a\d')),
         ]
 
 

=== modified file 'testtools/tests/test_with_with.py'
--- testtools/tests/test_with_with.py	2011-07-27 19:50:41 +0000
+++ testtools/tests/test_with_with.py	2011-07-29 16:19:28 +0000
@@ -32,7 +32,7 @@
                 raise ValueError('mismatch')
         except AssertionError:
             e = sys.exc_info()[1]
-            self.assertEqual("'mismatch' does not match 'tes.'", str(e))
+            self.assertEqual("'mismatch' does not match /tes./", str(e))
         else:
             self.fail('AssertionError not raised.')
 


Follow ups