mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
* Drop support for legacy Python 2.7 * Upgrade Python syntax with pyupgrade --py3-plus * Trim testing matrix to remove python2 * re-enable python3.8 in travis as tests that are not allowed to fail * Remove some six * The future is now * Remove Python 2 imports * Add back example, but change py27 to py36 * Remove redundant compat.py * Blacken * Credit hugovk in changelog WIP Updating Sphinx Docs and AutoDoc * Fix AutoDoc and update Sphinx theme to python_doc_theme * Fix #420, autodoc even undocumented (docstring-less) method signatures * Doc theme 'nature'. Add global TOC to doc sidebar * Comment last reference to package six * Changelog is now a consistent format * Yet another documentation fix for links and title hierarchy * Start work on new SVG logo test SVG in README trying to test new SVG logo in README Apply centering Apply readme logo centering Trying to align image Trying random shit trying align right add emoji Large logo has higher priority Change title hierarchy Actually use a H1 Try again try and organise badges revert link back to point at master * updated new take on VCR logo as SVG code * Testing modern logo in docs * Add sanitize for rendering SVG * Switch to alabaster theme * Update vcrpy logo (#503) * Add credit for V4 logo changes. * Add rewind and play animation * Add svg into ReadTheDocs static assets so that it can be hosted so the animations work. * Need to embedd the SVG for ReadTheDocs somewhere so I can get the link to later embed in the README Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Sean Bailey <sean@seanbailey.io>
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
class CannotOverwriteExistingCassetteException(Exception):
|
|
def __init__(self, *args, **kwargs):
|
|
self.cassette = kwargs["cassette"]
|
|
self.failed_request = kwargs["failed_request"]
|
|
message = self._get_message(kwargs["cassette"], kwargs["failed_request"])
|
|
super().__init__(message)
|
|
|
|
@staticmethod
|
|
def _get_message(cassette, failed_request):
|
|
"""Get the final message related to the exception"""
|
|
# Get the similar requests in the cassette that
|
|
# have match the most with the request.
|
|
best_matches = cassette.find_requests_with_most_matches(failed_request)
|
|
if best_matches:
|
|
# Build a comprehensible message to put in the exception.
|
|
best_matches_msg = "Found {} similar requests with {} different matcher(s) :\n".format(
|
|
len(best_matches), len(best_matches[0][2])
|
|
)
|
|
|
|
for idx, best_match in enumerate(best_matches, start=1):
|
|
request, succeeded_matchers, failed_matchers_assertion_msgs = best_match
|
|
best_matches_msg += (
|
|
"\n%s - (%r).\n"
|
|
"Matchers succeeded : %s\n"
|
|
"Matchers failed :\n" % (idx, request, succeeded_matchers)
|
|
)
|
|
for failed_matcher, assertion_msg in failed_matchers_assertion_msgs:
|
|
best_matches_msg += "%s - assertion failure :\n" "%s\n" % (failed_matcher, assertion_msg)
|
|
else:
|
|
best_matches_msg = "No similar requests, that have not been played, found."
|
|
return (
|
|
"Can't overwrite existing cassette (%r) in "
|
|
"your current record mode (%r).\n"
|
|
"No match for the request (%r) was found.\n"
|
|
"%s" % (cassette._path, cassette.record_mode, failed_request, best_matches_msg)
|
|
)
|
|
|
|
|
|
class UnhandledHTTPRequestError(KeyError):
|
|
"""Raised when a cassette does not contain the request we want."""
|
|
|
|
pass
|