summaryrefslogtreecommitdiff
path: root/passlib/tests/utils.py
diff options
context:
space:
mode:
authorEli Collins <elic@astllc.org>2011-08-13 19:36:10 -0400
committerEli Collins <elic@astllc.org>2011-08-13 19:36:10 -0400
commitd2ffaa3eecd9866918a20547d02c3a1b45dc8fdb (patch)
treee06a2663953759593aab433d97133a67d8d7a7fd /passlib/tests/utils.py
parentfd028d3ff7693b9589da674c6dc927e3b40f906c (diff)
downloadpasslib-d2ffaa3eecd9866918a20547d02c3a1b45dc8fdb.tar.gz
test.utils: added backport of assertRegexpMatches for py26/25
Diffstat (limited to 'passlib/tests/utils.py')
-rw-r--r--passlib/tests/utils.py12
1 files changed, 12 insertions, 0 deletions
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
#============================================================