mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #20362: Honour TestCase.longMessage correctly in assertRegex.
Patch from Ilia Kurenkov.
This commit is contained in:
parent
807404921a
commit
be6caca534
4 changed files with 29 additions and 8 deletions
|
@ -1279,8 +1279,10 @@ class TestCase(object):
|
|||
assert expected_regex, "expected_regex must not be empty."
|
||||
expected_regex = re.compile(expected_regex)
|
||||
if not expected_regex.search(text):
|
||||
msg = msg or "Regex didn't match"
|
||||
msg = '%s: %r not found in %r' % (msg, expected_regex.pattern, text)
|
||||
standardMsg = "Regex didn't match: %r not found in %r" % (
|
||||
expected_regex.pattern, text)
|
||||
# _formatMessage ensures the longMessage option is respected
|
||||
msg = self._formatMessage(msg, standardMsg)
|
||||
raise self.failureException(msg)
|
||||
|
||||
def assertNotRegex(self, text, unexpected_regex, msg=None):
|
||||
|
@ -1289,11 +1291,12 @@ class TestCase(object):
|
|||
unexpected_regex = re.compile(unexpected_regex)
|
||||
match = unexpected_regex.search(text)
|
||||
if match:
|
||||
msg = msg or "Regex matched"
|
||||
msg = '%s: %r matches %r in %r' % (msg,
|
||||
text[match.start():match.end()],
|
||||
unexpected_regex.pattern,
|
||||
text)
|
||||
standardMsg = 'Regex matched: %r matches %r in %r' % (
|
||||
text[match.start() : match.end()],
|
||||
unexpected_regex.pattern,
|
||||
text)
|
||||
# _formatMessage ensures the longMessage option is respected
|
||||
msg = self._formatMessage(msg, standardMsg)
|
||||
raise self.failureException(msg)
|
||||
|
||||
|
||||
|
@ -1315,6 +1318,7 @@ class TestCase(object):
|
|||
failIf = _deprecate(assertFalse)
|
||||
assertRaisesRegexp = _deprecate(assertRaisesRegex)
|
||||
assertRegexpMatches = _deprecate(assertRegex)
|
||||
assertNotRegexpMatches = _deprecate(assertNotRegex)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue