Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid private imports in test cases. #3403

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

import httpx
from httpx._content import encode_json

method = "POST"
url = "https://www.example.com"
Expand Down Expand Up @@ -489,24 +488,20 @@ def test_response_invalid_argument():

def test_ensure_ascii_false_with_french_characters():
data = {"greeting": "Bonjour, ça va ?"}
headers, byte_stream = encode_json(data)
json_output = b"".join(byte_stream).decode("utf-8")

response = httpx.Response(200, json=data)
assert (
"ça va" in json_output
"ça va" in response.text
), "ensure_ascii=False should preserve French accented characters"
assert headers["Content-Type"] == "application/json"
assert response.headers["Content-Type"] == "application/json"


def test_separators_for_compact_json():
data = {"clé": "valeur", "liste": [1, 2, 3]}
headers, byte_stream = encode_json(data)
json_output = b"".join(byte_stream).decode("utf-8")

response = httpx.Response(200, json=data)
assert (
json_output == '{"clé":"valeur","liste":[1,2,3]}'
response.text == '{"clé":"valeur","liste":[1,2,3]}'
), "separators=(',', ':') should produce a compact representation"
assert headers["Content-Type"] == "application/json"
assert response.headers["Content-Type"] == "application/json"


def test_allow_nan_false():
Expand All @@ -516,8 +511,8 @@ def test_allow_nan_false():
with pytest.raises(
ValueError, match="Out of range float values are not JSON compliant"
):
encode_json(data_with_nan)
httpx.Response(200, json=data_with_nan)
with pytest.raises(
ValueError, match="Out of range float values are not JSON compliant"
):
encode_json(data_with_inf)
httpx.Response(200, json=data_with_inf)