mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #8038: Addition of unittest.TestCase.assertNotRegexpMatches
This commit is contained in:
parent
25d7976014
commit
a04c7a0f16
3 changed files with 27 additions and 0 deletions
|
@ -952,6 +952,18 @@ class TestCase(object):
|
|||
msg = '%s: %r not found in %r' % (msg, expected_regexp.pattern, text)
|
||||
raise self.failureException(msg)
|
||||
|
||||
def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
|
||||
if isinstance(unexpected_regexp, basestring):
|
||||
unexpected_regexp = re.compile(unexpected_regexp)
|
||||
match = unexpected_regexp.search(text)
|
||||
if match:
|
||||
msg = msg or "Regexp matched"
|
||||
msg = '%s: %r matches %r in %r' % (msg,
|
||||
text[match.start():match.end()],
|
||||
unexpected_regexp.pattern,
|
||||
text)
|
||||
raise self.failureException(msg)
|
||||
|
||||
|
||||
class FunctionTestCase(TestCase):
|
||||
"""A test case that wraps a test function.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue