Nicer error message for regex fail.
This commit is contained in:
@@ -730,7 +730,8 @@ class MatchesRegex(object):
|
|||||||
|
|
||||||
def match(self, value):
|
def match(self, value):
|
||||||
if not re.match(self.pattern, value, self.flags):
|
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):
|
class MatchesSetwise(object):
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ class TestMatchesExceptionTypeReInterface(TestCase, TestMatchersInterface):
|
|||||||
MatchesException(Exception, 'fo.'))
|
MatchesException(Exception, 'fo.'))
|
||||||
]
|
]
|
||||||
describe_examples = [
|
describe_examples = [
|
||||||
("'bar' does not match 'fo.'",
|
("'bar' does not match /fo./",
|
||||||
error_bar, MatchesException(ValueError, "fo.")),
|
error_bar, MatchesException(ValueError, "fo.")),
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -639,7 +639,8 @@ class TestMatchesRegex(TestCase, TestMatchersInterface):
|
|||||||
]
|
]
|
||||||
|
|
||||||
describe_examples = [
|
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')
|
raise ValueError('mismatch')
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
e = sys.exc_info()[1]
|
e = sys.exc_info()[1]
|
||||||
self.assertEqual("'mismatch' does not match 'tes.'", str(e))
|
self.assertEqual("'mismatch' does not match /tes./", str(e))
|
||||||
else:
|
else:
|
||||||
self.fail('AssertionError not raised.')
|
self.fail('AssertionError not raised.')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user