summaryrefslogtreecommitdiffstats
path: root/testsuite/common.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 13:35:31 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 13:35:31 -0400
commit3ef084721034424f15c2a8e731dcaa424afbdf24 (patch)
tree6ecfd1c9c57c71209fe9d8d2877f27fb7bbdf414 /testsuite/common.py
parente5b939ee32ae7b7b3fbe8f18246e078766647949 (diff)
downloadbcfg2-3ef084721034424f15c2a8e731dcaa424afbdf24.tar.gz
bcfg2-3ef084721034424f15c2a8e731dcaa424afbdf24.tar.bz2
bcfg2-3ef084721034424f15c2a8e731dcaa424afbdf24.zip
added assertRegexpMatches to Bcfg2TestCase for compat
Diffstat (limited to 'testsuite/common.py')
-rw-r--r--testsuite/common.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/testsuite/common.py b/testsuite/common.py
index 42efe9fd6..403d3dda7 100644
--- a/testsuite/common.py
+++ b/testsuite/common.py
@@ -126,7 +126,7 @@ if not hasattr(unittest.TestCase, "assertItemsEqual"):
return result
-if not hasattr(unittest.TestCase, "assertIn"):
+if True or not hasattr(unittest.TestCase, "assertIn"):
# versions of TestCase before python 2.7 and python 3.1 lacked a
# lot of the really handy convenience methods, so we provide them
# -- at least the easy ones and the ones we use.
@@ -143,6 +143,12 @@ if not hasattr(unittest.TestCase, "assertIn"):
assert predicate(*args, **kwargs), msg
return inner
+ def _regex_matches(val, regex):
+ if hasattr(regex, 'search'):
+ return regex.search(val)
+ else:
+ return re.search(regex, val)
+
class Bcfg2TestCase(unittest.TestCase):
if needs_assertItemsEqual:
@@ -176,6 +182,11 @@ class Bcfg2TestCase(unittest.TestCase):
assertLess = _assertion(lambda a, b: a < b, "%s is not less than %s")
assertLessEqual = _assertion(lambda a, b: a <= b,
"%s is not less than or equal to %s")
+ assertRegexpMatches = _assertion(lambda s, r: _regex_matches(s, r),
+ "%s does not contain /%s/")
+ assertNotRegexpMatches = \
+ _assertion(lambda s, r: not _regex_matches(s, r),
+ "%s contains /%s/")
def assertXMLEqual(self, el1, el2, msg=None):