From 24281bb462a367659fe20c596ef1f19ca0e341db Mon Sep 17 00:00:00 2001 From: jjkochan-metro Date: Tue, 29 Oct 2024 15:25:24 -0500 Subject: [PATCH 1/3] Add \!r to error message for improved clarity on file paths --- src/requests/adapters.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/requests/adapters.py b/src/requests/adapters.py index 9a58b16025..6142fc40f3 100644 --- a/src/requests/adapters.py +++ b/src/requests/adapters.py @@ -327,7 +327,7 @@ def cert_verify(self, conn, url, verify, cert): if not os.path.exists(cert_loc): raise OSError( f"Could not find a suitable TLS CA certificate bundle, " - f"invalid path: {cert_loc}" + f"invalid path: {cert_loc!r}" ) if not os.path.isdir(cert_loc): @@ -349,11 +349,11 @@ def cert_verify(self, conn, url, verify, cert): if conn.cert_file and not os.path.exists(conn.cert_file): raise OSError( f"Could not find the TLS certificate file, " - f"invalid path: {conn.cert_file}" + f"invalid path: {conn.cert_file!r}" ) if conn.key_file and not os.path.exists(conn.key_file): raise OSError( - f"Could not find the TLS key file, invalid path: {conn.key_file}" + f"Could not find the TLS key file, invalid path: {conn.key_file!r}" ) def build_response(self, req, resp): From 442dbec227dbca0e4b834e30e3b5570cf95cd266 Mon Sep 17 00:00:00 2001 From: jjkochan2 Date: Tue, 10 Jun 2025 10:16:40 -0500 Subject: [PATCH 2/3] Fix tests to match repr formatting in error messages --- tests/test_requests.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 75d2deff2e..672dab84f1 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -962,9 +962,7 @@ def test_invalid_ca_certificate_path(self, httpbin_secure): requests.get(httpbin_secure(), verify=INVALID_PATH) assert str( e.value - ) == "Could not find a suitable TLS CA certificate bundle, invalid path: {}".format( - INVALID_PATH - ) + ) == f"Could not find a suitable TLS CA certificate bundle, invalid path: {INVALID_PATH!r}" def test_invalid_ssl_certificate_files(self, httpbin_secure): INVALID_PATH = "/garbage" @@ -972,14 +970,12 @@ def test_invalid_ssl_certificate_files(self, httpbin_secure): requests.get(httpbin_secure(), cert=INVALID_PATH) assert str( e.value - ) == "Could not find the TLS certificate file, invalid path: {}".format( - INVALID_PATH - ) + ) == f"Could not find the TLS certificate file, invalid path: {INVALID_PATH!r}" with pytest.raises(IOError) as e: requests.get(httpbin_secure(), cert=(".", INVALID_PATH)) assert str(e.value) == ( - f"Could not find the TLS key file, invalid path: {INVALID_PATH}" + f"Could not find the TLS key file, invalid path: {INVALID_PATH!r}" ) @pytest.mark.parametrize( From 58ba5c51c63d20bca36728758492f36a5b17cfa8 Mon Sep 17 00:00:00 2001 From: jjkochan2 Date: Tue, 10 Jun 2025 10:56:08 -0500 Subject: [PATCH 3/3] Fix formatting of test_requests.py with black --- tests/test_requests.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 672dab84f1..2f65368ad7 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -960,17 +960,19 @@ def test_invalid_ca_certificate_path(self, httpbin_secure): INVALID_PATH = "/garbage" with pytest.raises(IOError) as e: requests.get(httpbin_secure(), verify=INVALID_PATH) - assert str( - e.value - ) == f"Could not find a suitable TLS CA certificate bundle, invalid path: {INVALID_PATH!r}" + assert ( + str(e.value) + == f"Could not find a suitable TLS CA certificate bundle, invalid path: {INVALID_PATH!r}" + ) def test_invalid_ssl_certificate_files(self, httpbin_secure): INVALID_PATH = "/garbage" with pytest.raises(IOError) as e: requests.get(httpbin_secure(), cert=INVALID_PATH) - assert str( - e.value - ) == f"Could not find the TLS certificate file, invalid path: {INVALID_PATH!r}" + assert ( + str(e.value) + == f"Could not find the TLS certificate file, invalid path: {INVALID_PATH!r}" + ) with pytest.raises(IOError) as e: requests.get(httpbin_secure(), cert=(".", INVALID_PATH)) @@ -2456,7 +2458,6 @@ def test_expires_none(self): class TestMorselToCookieMaxAge: - """Tests for morsel_to_cookie when morsel contains max-age.""" def test_max_age_valid_int(self):