MCPcopy
hub / github.com/urllib3/urllib3 / test_io

Method test_io

test/test_response.py:1017–1051  ·  view source on GitHub ↗
(self, sock: socket.socket)

Source from the content-addressed store, hash-verified

1015 resp.close()
1016
1017 def test_io(self, sock: socket.socket) -> None:
1018 fp = BytesIO(b"foo")
1019 resp = HTTPResponse(fp, preload_content=False)
1020
1021 assert not resp.closed
1022 assert resp.readable()
1023 assert not resp.writable()
1024 with pytest.raises(IOError):
1025 resp.fileno()
1026
1027 resp.close()
1028 assert resp.closed
1029
1030 # Try closing with an `httplib.HTTPResponse`, because it has an
1031 # `isclosed` method.
1032 try:
1033 hlr = httplib.HTTPResponse(sock)
1034 resp2 = HTTPResponse(hlr, preload_content=False)
1035 assert not resp2.closed
1036 resp2.close()
1037 assert resp2.closed
1038 finally:
1039 hlr.close()
1040
1041 # also try when only data is present.
1042 resp3 = HTTPResponse("foodata")
1043 with pytest.raises(IOError):
1044 resp3.fileno()
1045
1046 resp3._fp = 2
1047 # A corner case where _fp is present but doesn't have `closed`,
1048 # `isclosed`, or `fileno`. Unlikely, but possible.
1049 assert resp3.closed
1050 with pytest.raises(IOError):
1051 resp3.fileno()
1052
1053 def test_io_closed_consistently_by_read(self, sock: socket.socket) -> None:
1054 try:

Callers

nothing calls this directly

Calls 5

readableMethod · 0.95
filenoMethod · 0.95
closeMethod · 0.95
HTTPResponseClass · 0.90
writableMethod · 0.45

Tested by

no test coverage detected