From a47b622dc2fbeba88c1abca79cdb41328cd6a7f3 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Fri, 30 Aug 2024 13:44:50 +0100 Subject: [PATCH 1/2] Test coverage of TextIOWrapper (#8936) (cherry picked from commit 76a00d1ed405c87cf33c66f91d410c95e57c0312) --- tests/test_formdata.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_formdata.py b/tests/test_formdata.py index 4bb8aa07587..5a3c57336f0 100644 --- a/tests/test_formdata.py +++ b/tests/test_formdata.py @@ -1,3 +1,4 @@ +import io from unittest import mock import pytest @@ -46,6 +47,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"), encoding="utf-8") + 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"] From 64b57a9d1b2265172924cc729f4a22d7e634dda6 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Fri, 30 Aug 2024 13:48:34 +0100 Subject: [PATCH 2/2] Update tests/test_formdata.py --- tests/test_formdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_formdata.py b/tests/test_formdata.py index 5a3c57336f0..db1a3861c56 100644 --- a/tests/test_formdata.py +++ b/tests/test_formdata.py @@ -47,7 +47,7 @@ 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: +async def test_formdata_textio_charset(buf: bytearray, writer) -> None: form = FormData() body = io.TextIOWrapper(io.BytesIO(b"\xe6\x97\xa5\xe6\x9c\xac"), encoding="utf-8") form.add_field("foo", body, content_type="text/plain; charset=shift-jis")