MCPcopy Index your code
hub / github.com/python/cpython / assertRegex

Method assertRegex

Lib/unittest/case.py:1435–1445  ·  view source on GitHub ↗

Fail the test unless the text matches the regular expression.

(self, text, expected_regex, msg=None)

Source from the content-addressed store, hash-verified

1433 return context.handle('assertWarnsRegex', args, kwargs)
1434
1435 def assertRegex(self, text, expected_regex, msg=None):
1436 """Fail the test unless the text matches the regular expression."""
1437 if isinstance(expected_regex, (str, bytes)):
1438 assert expected_regex, "expected_regex must not be empty."
1439 expected_regex = re.compile(expected_regex)
1440 if not expected_regex.search(text):
1441 standardMsg = "Regex didn't match: %r not found in %r" % (
1442 expected_regex.pattern, text)
1443 # _formatMessage ensures the longMessage option is respected
1444 msg = self._formatMessage(msg, standardMsg)
1445 raise self.failureException(msg)
1446
1447 def assertNotRegex(self, text, unexpected_regex, msg=None):
1448 """Fail the test if the text matches the regular expression."""

Calls 3

_formatMessageMethod · 0.95
compileMethod · 0.45
searchMethod · 0.45