summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/case.py
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-08-19 23:13:38 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-08-19 23:13:38 (GMT)
commitf01b16c1fe2c7d350ccde273fb03ac10eab35229 (patch)
treeceb8428de4a929cd715b69eb1d132afadeed9739 /Lib/unittest/case.py
parente4d35dc8b6fb3c071d85e2d8830566876288c180 (diff)
parentbe6caca534a6d35ccae6fe13c15eead76b721e1d (diff)
downloadcpython-f01b16c1fe2c7d350ccde273fb03ac10eab35229.zip
cpython-f01b16c1fe2c7d350ccde273fb03ac10eab35229.tar.gz
cpython-f01b16c1fe2c7d350ccde273fb03ac10eab35229.tar.bz2
Issue #20362: Honour TestCase.longMessage correctly in assertRegex.
Patch from Ilia Kurenkov.
Diffstat (limited to 'Lib/unittest/case.py')
-rw-r--r--Lib/unittest/case.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 7701ad3..a4a0a1f 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -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)