MCPcopy
hub / github.com/urllib3/urllib3 / test_io_not_autoclose_textiowrapper

Method test_io_not_autoclose_textiowrapper

test/test_response.py:1254–1271  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1252 list(TextIOWrapper(resp)) # type: ignore[type-var]
1253
1254 def test_io_not_autoclose_textiowrapper(self) -> None:
1255 fp = BytesIO(
1256 b"\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f\n\xce\xb1\xce\xb2\xce\xb3\xce\xb4"
1257 )
1258 resp = HTTPResponse(fp, preload_content=False, auto_close=False)
1259 reader = TextIOWrapper(resp, encoding="utf8") # type: ignore[type-var]
1260 assert list(reader) == ["äöüß\n", "αβγδ"]
1261
1262 assert not reader.closed
1263 assert not resp.closed
1264 with pytest.raises(StopIteration):
1265 next(reader)
1266
1267 reader.close()
1268 assert reader.closed
1269 assert resp.closed
1270 with pytest.raises(ValueError, match="I/O operation on closed file.?"):
1271 next(reader)
1272
1273 def test_read_with_illegal_mix_decode_toggle(self) -> None:
1274 data = zlib.compress(b"foo")

Callers

nothing calls this directly

Calls 2

HTTPResponseClass · 0.90
closeMethod · 0.45

Tested by

no test coverage detected