From 6b2fc182c30d62e138b5fb048c2d28bbb4c9e7de Mon Sep 17 00:00:00 2001 From: Jair Henrique Date: Mon, 26 Jun 2023 15:57:17 -0300 Subject: [PATCH] Improve string format --- tests/unit/test_errors.py | 7 ++++--- vcr/errors.py | 14 +++++++------- vcr/stubs/tornado_stubs.py | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_errors.py b/tests/unit/test_errors.py index 9d331ad..3ecd85b 100644 --- a/tests/unit/test_errors.py +++ b/tests/unit/test_errors.py @@ -64,8 +64,9 @@ def test_CannotOverwriteExistingCassetteException_get_message( failed_request = "request" exception_message = errors.CannotOverwriteExistingCassetteException._get_message(cassette, "request") expected = ( - "Can't overwrite existing cassette ({!r}) in your current record mode ({!r}).\n" - "No match for the request ({!r}) was found.\n" - "{}".format(cassette._path, cassette.record_mode, failed_request, expected_message) + f"Can't overwrite existing cassette ({cassette._path!r}) " + f"in your current record mode ({cassette.record_mode!r}).\n" + f"No match for the request ({failed_request!r}) was found.\n" + f"{expected_message}" ) assert exception_message == expected diff --git a/vcr/errors.py b/vcr/errors.py index 67e2dbf..4072e5f 100644 --- a/vcr/errors.py +++ b/vcr/errors.py @@ -13,9 +13,9 @@ class CannotOverwriteExistingCassetteException(Exception): 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]), + best_matches_msg = ( + f"Found {len(best_matches)} similar requests " + f"with {len(best_matches[0][2])} different matcher(s) :\n" ) for idx, best_match in enumerate(best_matches, start=1): @@ -30,10 +30,10 @@ class CannotOverwriteExistingCassetteException(Exception): 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" - "{}".format(cassette._path, cassette.record_mode, failed_request, best_matches_msg) + f"Can't overwrite existing cassette ({cassette._path!r}) in " + f"your current record mode ({cassette.record_mode!r}).\n" + f"No match for the request ({failed_request!r}) was found.\n" + f"{best_matches_msg}" ) diff --git a/vcr/stubs/tornado_stubs.py b/vcr/stubs/tornado_stubs.py index fbd2e6a..7f61da7 100644 --- a/vcr/stubs/tornado_stubs.py +++ b/vcr/stubs/tornado_stubs.py @@ -29,9 +29,9 @@ def vcr_fetch_impl(cassette, real_fetch_impl): request, 599, error=Exception( - "The request (%s) uses AsyncHTTPClient functionality " + f"The request ({request!r}) uses AsyncHTTPClient functionality " "that is not yet supported by VCR.py. Please make the " - "request outside a VCR.py context." % repr(request), + "request outside a VCR.py context.", ), request_time=self.io_loop.time() - request.start_time, )