From 54bc6467eba4c2c9f59a74310b3dbafa17658531 Mon Sep 17 00:00:00 2001 From: Allan Crooks Date: Sun, 21 Jan 2024 15:50:46 +0000 Subject: [PATCH] Run linters. --- tests/integration/test_httpx.py | 7 +++++-- vcr/stubs/httpx_stubs.py | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/integration/test_httpx.py b/tests/integration/test_httpx.py index e508f6d..d261927 100644 --- a/tests/integration/test_httpx.py +++ b/tests/integration/test_httpx.py @@ -1,11 +1,14 @@ -import pytest import os + +import pytest + import vcr +from ..assertions import assert_is_json_bytes + asyncio = pytest.importorskip("asyncio") httpx = pytest.importorskip("httpx") -from ..assertions import assert_is_json_bytes @pytest.fixture(params=["https", "http"]) def scheme(request): diff --git a/vcr/stubs/httpx_stubs.py b/vcr/stubs/httpx_stubs.py index 8fc63e7..759cb72 100644 --- a/vcr/stubs/httpx_stubs.py +++ b/vcr/stubs/httpx_stubs.py @@ -7,8 +7,8 @@ from unittest.mock import MagicMock, patch import httpx from vcr.errors import CannotOverwriteExistingCassetteException -from vcr.request import Request as VcrRequest from vcr.filters import decode_response +from vcr.request import Request as VcrRequest from vcr.serializers.compat import convert_body_to_bytes _httpx_signature = inspect.signature(httpx.Client.request) @@ -37,7 +37,6 @@ def _transform_headers(httpx_response): async def _to_serialized_response(resp, aread): - # The content shouldn't already have been read in by HTTPX. assert not hasattr(resp, "_decoder") @@ -49,7 +48,7 @@ async def _to_serialized_response(resp, aread): resp.read() result = { - "status": dict(code=resp.status_code, message=resp.reason_phrase), + "status": {"code": resp.status_code, "message": resp.reason_phrase}, "headers": _transform_headers(resp), "body": {"string": resp.content}, } @@ -60,6 +59,7 @@ async def _to_serialized_response(resp, aread): resp._content = resp._get_content_decoder().decode(resp.content) return result + def _from_serialized_headers(headers): """ httpx accepts headers as list of tuples of header key and value. @@ -75,16 +75,19 @@ def _from_serialized_headers(headers): @patch("httpx.Response.close", MagicMock()) @patch("httpx.Response.read", MagicMock()) def _from_serialized_response(request, serialized_response, history=None): - # Cassette format generated for HTTPX requests by older versions of # vcrpy. We restructure the content to resemble what a regular # cassette looks like. if "status_code" in serialized_response: - serialized_response = decode_response(convert_body_to_bytes({ - 'headers': serialized_response['headers'], - 'body': {'string': serialized_response['content']}, - 'status': {'code': serialized_response['status_code']}, - })) + serialized_response = decode_response( + convert_body_to_bytes( + { + "headers": serialized_response["headers"], + "body": {"string": serialized_response["content"]}, + "status": {"code": serialized_response["status_code"]}, + }, + ), + ) extensions = None else: extensions = {"reason_phrase": serialized_response["status"]["message"].encode()}