Allow value_re to be a matcher

This commit is contained in:
Jonathan Lange
2011-07-20 19:43:31 +01:00
parent 152ebc4ef8
commit 5e4f617729
2 changed files with 21 additions and 1 deletions

View File

@@ -417,7 +417,7 @@ class MatchesException(Matcher):
"""
Matcher.__init__(self)
self.expected = exception
if value_re:
if istext(value_re):
value_re = MatchesRegex(value_re)
self.value_re = value_re
self._is_instance = type(self.expected) not in classtypes()

View File

@@ -262,6 +262,26 @@ class TestMatchesExceptionTypeReInterface(TestCase, TestMatchersInterface):
]
class TestMatchesExceptionTypeMatcherInterface(TestCase, TestMatchersInterface):
matches_matcher = MatchesException(
ValueError, AfterPreproccessing(str, Equals('foo')))
error_foo = make_error(ValueError, 'foo')
error_sub = make_error(UnicodeError, 'foo')
error_bar = make_error(ValueError, 'bar')
matches_matches = [error_foo, error_sub]
matches_mismatches = [error_bar]
str_examples = [
("MatchesException(%r)" % Exception,
MatchesException(Exception))
]
describe_examples = [
("'bar' does not match 'fo.'",
error_bar, MatchesException(ValueError, "fo.")),
]
class TestNotInterface(TestCase, TestMatchersInterface):
matches_matcher = Not(Equals(1))