diff options
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/common.py | 13 |
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): |