(self)
| 1164 | assert not resp.isclosed() |
| 1165 | |
| 1166 | def test_io_bufferedreader(self) -> None: |
| 1167 | fp = BytesIO(b"foo") |
| 1168 | resp = HTTPResponse(fp, preload_content=False) |
| 1169 | br = BufferedReader(resp) |
| 1170 | |
| 1171 | assert br.read() == b"foo" |
| 1172 | |
| 1173 | br.close() |
| 1174 | assert resp.closed |
| 1175 | |
| 1176 | # HTTPResponse.read() by default closes the response |
| 1177 | # https://github.com/urllib3/urllib3/issues/1305 |
| 1178 | fp = BytesIO(b"hello\nworld") |
| 1179 | resp = HTTPResponse(fp, preload_content=False) |
| 1180 | with pytest.raises(ValueError, match="readline of closed file"): |
| 1181 | list(BufferedReader(resp)) |
| 1182 | |
| 1183 | b = b"fooandahalf" |
| 1184 | fp = BytesIO(b) |
| 1185 | resp = HTTPResponse(fp, preload_content=False) |
| 1186 | br = BufferedReader(resp, 5) |
| 1187 | |
| 1188 | br.read(1) # sets up the buffer, reading 5 |
| 1189 | assert len(fp.read()) == (len(b) - 5) |
| 1190 | |
| 1191 | # This is necessary to make sure the "no bytes left" part of `readinto` |
| 1192 | # gets tested. |
| 1193 | while not br.closed: |
| 1194 | br.read(5) |
| 1195 | |
| 1196 | def test_readinto_with_memoryview(self) -> None: |
| 1197 | data = b"hello world" |
nothing calls this directly
no test coverage detected