Skip to content

Commit

Permalink
[PR #8936/76a00d1e backport][3.10] Test coverage of TextIOWrapper (#8944
Browse files Browse the repository at this point in the history
)

**This is a backport of PR #8936 as merged into master
(76a00d1).**

---------

Co-authored-by: Sam Bull <git@sambull.org>
  • Loading branch information
patchback[bot] and Dreamsorcerer authored Aug 30, 2024
1 parent 950f72c commit 181c042
Showing 1 changed file with 11 additions and 0 deletions.
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 @@ -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) -> 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"]
Expand Down

0 comments on commit 181c042

Please sign in to comment.