1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

add private function to evaluate a matcher

A matcher can now return other results than a boolean :
- An AssertionError exception meaning that the matcher failed, with the exception we get the assertion failure message.
- None, in case we do an assert in the matcher, meaning that the assertion has passed, the matcher is considered as a success then.
- Boolean that indicates if a matcher failed or not. If there is no match, a boolean does not give any clue what it is the differences compared to the assertion.
This commit is contained in:
Arthur Hamon
2019-06-12 11:57:54 +02:00
parent de244a968f
commit 940dec1dd6
2 changed files with 53 additions and 12 deletions

View File

@@ -101,6 +101,23 @@ def requests_match(r1, r2, matchers):
return all(m[0] for m in matches)
def _evaluate_matcher(matcher_function, *args):
"""
Evaluate the result of a given matcher as a boolean with an assertion error message if any.
It handles two types of matcher :
- a matcher returning a boolean value.
- a matcher that only makes an assert, returning None or raises an assertion error.
"""
assertion_message = None
try:
match = matcher_function(*args)
match = True if match is None else match
except AssertionError as e:
match = False
assertion_message = str(e)
return match, assertion_message
def get_assertion_message(assertion_details, **format_options):
"""
Get a detailed message about the failing matcher.