From 3ef084721034424f15c2a8e731dcaa424afbdf24 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 4 Sep 2012 13:35:31 -0400 Subject: added assertRegexpMatches to Bcfg2TestCase for compat --- testsuite/common.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'testsuite') 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): -- cgit v1.2.3-1-g7c22