MCPcopy Index your code
hub / github.com/RustPython/RustPython / assertRegex

Method assertRegex

Lib/unittest/case.py:1440–1450  ·  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

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

Calls 4

_formatMessageMethod · 0.95
isinstanceFunction · 0.85
compileMethod · 0.45
searchMethod · 0.45