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

Test coverage of TextIOWrapper #8936

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Changes from 3 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
11 changes: 11 additions & 0 deletions tests/test_formdata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io
from unittest import mock

import pytest
Expand Down Expand Up @@ -48,6 +49,16 @@ def test_invalid_formdata_params2() -> None:
FormData("as") # 2-char str is not allowed


async def test_formdata_textio_charset(buf: bytearray, writer: StreamWriter) -> None:
form = FormData()
body = io.TextIOWrapper(io.BytesIO(b"\xe6\x97\xa5\xe6\x9c\xac"))
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
form.add_field("foo", body, content_type="text/plain; charset=shift-jis")
payload = form()
await payload.write(writer)
assert b"charset=shift-jis" in buf
assert b"\x93\xfa\x96{" in buf


def test_invalid_formdata_content_type() -> None:
form = FormData()
invalid_vals = [0, 0.1, {}, [], b"foo"]
Expand Down
Loading