diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-01-02 14:19:28 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-01-02 14:19:28 -0500 |
| commit | f80685ffefcb1c0ab29f543039fd0707bcf7342e (patch) | |
| tree | 1ef6686bfbcea648ea3e148ef90e3adf3f3c3c9f /passlib/tests | |
| parent | b6b686f395ce9ea9ec0b56c9d5534d1e68409a1d (diff) | |
| download | passlib-f80685ffefcb1c0ab29f543039fd0707bcf7342e.tar.gz | |
tests use assertRegex instead of assertRegexpMatches
Diffstat (limited to 'passlib/tests')
| -rw-r--r-- | passlib/tests/utils.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index c0a9eae..03abca2 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -293,17 +293,21 @@ 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, sb_types): - 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) + if not hasattr(unittest.TestCase, "assertRegex"): + # assertRegexpMatches() added in 2.7/UT2 and 3.1, renamed to + # assertRegex() in 3.2; this code ensures assertRegex() is defined. + if hasattr(unittest.TestCase, "assertRegexpMatches"): + assertRegex = unittest.TestCase.assertRegexpMatches + else: + def assertRegex(self, text, expected_regex, msg=None): + """Fail the test unless the text matches the regular expression.""" + if isinstance(expected_regex, sb_types): + 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 @@ -344,7 +348,7 @@ class TestCase(unittest.TestCase): if message: self.assertEqual(str(warning), message, msg) if message_re: - self.assertRegexpMatches(str(warning), message_re, msg) + self.assertRegex(str(warning), message_re, msg) if category: self.assertIsInstance(warning, category, msg) @@ -361,7 +365,7 @@ class TestCase(unittest.TestCase): ## if filename: ## self.assertEqual(real, filename, msg) ## if filename_re: - ## self.assertRegexpMatches(real, filename_re, msg) + ## self.assertRegex(real, filename_re, msg) ##if lineno: ## if not wmsg: ## raise TypeError("can't read lineno from warning object") @@ -1227,6 +1231,7 @@ except ImportError: if self._record: log = [] def showwarning(*args, **kwargs): +# self._showwarning(*args, **kwargs) log.append(WarningMessage(*args, **kwargs)) self._module.showwarning = showwarning return log |
