From d2ffaa3eecd9866918a20547d02c3a1b45dc8fdb Mon Sep 17 00:00:00 2001 From: Eli Collins Date: Sat, 13 Aug 2011 19:36:10 -0400 Subject: test.utils: added backport of assertRegexpMatches for py26/25 --- passlib/tests/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'passlib') diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 2adc68c..7aa9797 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -293,6 +293,18 @@ class TestCase(unittest.TestCase): msg = self._formatMessage(msg, standardMsg) raise self.failureException(msg) + if not hasattr(unittest.TestCase, "assertRegexpMatches"): + #added in 2.7/UT2 and 3.1 + def assertRegexpMatches(self, text, expected_regex, msg=None): + """Fail the test unless the text matches the regular expression.""" + if isinstance(expected_regex, basestring): + 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) + raise self.failureException(msg) + #============================================================ #add some custom methods #============================================================ -- cgit v1.2.1