mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
Updating documentation and adding docstrings to unittest.TestCase.assertRegexpMatches and assertNotRegexpMatches. Issue 8038.
This commit is contained in:
parent
7baf8627bd
commit
959c16d7a4
2 changed files with 5 additions and 3 deletions
|
@ -907,9 +907,9 @@ Test cases
|
||||||
.. method:: assertNotRegexpMatches(text, regexp, msg=None)
|
.. method:: assertNotRegexpMatches(text, regexp, msg=None)
|
||||||
|
|
||||||
Verifies that a *regexp* search does not match *text*. Fails with an error
|
Verifies that a *regexp* search does not match *text*. Fails with an error
|
||||||
message including the pattern and the *text*. *regexp* may be
|
message including the pattern and the part of *text* that matches. *regexp*
|
||||||
a regular expression object or a string containing a regular expression
|
may be a regular expression object or a string containing a regular
|
||||||
suitable for use by :func:`re.search`.
|
expression suitable for use by :func:`re.search`.
|
||||||
|
|
||||||
.. versionadded:: 2.7
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
|
|
@ -945,6 +945,7 @@ class TestCase(object):
|
||||||
callable_obj(*args, **kwargs)
|
callable_obj(*args, **kwargs)
|
||||||
|
|
||||||
def assertRegexpMatches(self, text, expected_regexp, msg=None):
|
def assertRegexpMatches(self, text, expected_regexp, msg=None):
|
||||||
|
"""Fail the test unless the text matches the regular expression."""
|
||||||
if isinstance(expected_regexp, basestring):
|
if isinstance(expected_regexp, basestring):
|
||||||
expected_regexp = re.compile(expected_regexp)
|
expected_regexp = re.compile(expected_regexp)
|
||||||
if not expected_regexp.search(text):
|
if not expected_regexp.search(text):
|
||||||
|
@ -953,6 +954,7 @@ class TestCase(object):
|
||||||
raise self.failureException(msg)
|
raise self.failureException(msg)
|
||||||
|
|
||||||
def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
|
def assertNotRegexpMatches(self, text, unexpected_regexp, msg=None):
|
||||||
|
"""Fail the test if the text matches the regular expression."""
|
||||||
if isinstance(unexpected_regexp, basestring):
|
if isinstance(unexpected_regexp, basestring):
|
||||||
unexpected_regexp = re.compile(unexpected_regexp)
|
unexpected_regexp = re.compile(unexpected_regexp)
|
||||||
match = unexpected_regexp.search(text)
|
match = unexpected_regexp.search(text)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue