From: Tom Christie Date: Wed, 8 May 2019 12:52:26 +0000 (+0100) Subject: Increase test coverage X-Git-Tag: 0.3.0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e99ffbd7acbffb0d4eddd912ad3a30571f62a499;p=thirdparty%2Fhttpx.git Increase test coverage --- diff --git a/tests/models/test_requests.py b/tests/models/test_requests.py index 77baa774..98eea510 100644 --- a/tests/models/test_requests.py +++ b/tests/models/test_requests.py @@ -3,6 +3,11 @@ import pytest import httpcore +def test_request_repr(): + request = httpcore.Request("GET", "http://example.org") + assert repr(request) == "" + + def test_host_header(): request = httpcore.Request("GET", "http://example.org") request.prepare() diff --git a/tests/models/test_responses.py b/tests/models/test_responses.py index bfe8c113..8ecd37ab 100644 --- a/tests/models/test_responses.py +++ b/tests/models/test_responses.py @@ -15,6 +15,11 @@ def test_response(): assert response.text == "Hello, world!" +def test_response_repr(): + response = httpcore.Response(200, content=b"Hello, world!") + assert repr(response) == "" + + def test_response_content_type_encoding(): """ Use the charset encoding in the Content-Type header if possible. @@ -47,7 +52,7 @@ def test_response_fallback_to_autodetect(): assert response.encoding == "EUC-JP" -def test_response(): +def test_response_default_text_encoding(): """ A media type of 'text/*' with no charset should default to ISO-8859-1. See: https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1 @@ -69,6 +74,16 @@ def test_response_default_encoding(): assert response.encoding == "utf-8" +def test_response_non_text_encoding(): + """ + Default to apparent encoding for non-text content-type headers. + """ + headers = {"Content-Type": "image/png"} + response = httpcore.Response(200, content=b"xyz", headers=headers) + assert response.text == "xyz" + assert response.encoding == "ascii" + + def test_response_set_explicit_encoding(): headers = { "Content-Type": "text-plain; charset=utf-8"