Nicer error message for regex fail.
This commit is contained in:
@@ -730,7 +730,8 @@ class MatchesRegex(object):
|
||||
|
||||
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):
|
||||
|
||||
@@ -258,7 +258,7 @@ class TestMatchesExceptionTypeReInterface(TestCase, TestMatchersInterface):
|
||||
MatchesException(Exception, 'fo.'))
|
||||
]
|
||||
describe_examples = [
|
||||
("'bar' does not match 'fo.'",
|
||||
("'bar' does not match /fo./",
|
||||
error_bar, MatchesException(ValueError, "fo.")),
|
||||
]
|
||||
|
||||
@@ -639,7 +639,8 @@ class TestMatchesRegex(TestCase, TestMatchersInterface):
|
||||
]
|
||||
|
||||
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')),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestExpectedException(TestCase):
|
||||
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.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user