Allow value_re to be a matcher
This commit is contained in:
@@ -417,7 +417,7 @@ class MatchesException(Matcher):
|
|||||||
"""
|
"""
|
||||||
Matcher.__init__(self)
|
Matcher.__init__(self)
|
||||||
self.expected = exception
|
self.expected = exception
|
||||||
if value_re:
|
if istext(value_re):
|
||||||
value_re = MatchesRegex(value_re)
|
value_re = MatchesRegex(value_re)
|
||||||
self.value_re = value_re
|
self.value_re = value_re
|
||||||
self._is_instance = type(self.expected) not in classtypes()
|
self._is_instance = type(self.expected) not in classtypes()
|
||||||
|
|||||||
@@ -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):
|
class TestNotInterface(TestCase, TestMatchersInterface):
|
||||||
|
|
||||||
matches_matcher = Not(Equals(1))
|
matches_matcher = Not(Equals(1))
|
||||||
|
|||||||
Reference in New Issue
Block a user