MCPcopy
hub / github.com/urllib3/urllib3 / test_invalid_chunk_length

Method test_invalid_chunk_length

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

Source from the content-addressed store, hash-verified

1790 assert isinstance(orig_ex, httplib_IncompleteRead)
1791
1792 def test_invalid_chunk_length(self) -> None:
1793 stream = [b"foooo", b"bbbbaaaaar"]
1794 fp = MockChunkedInvalidChunkLength(stream)
1795 r = httplib.HTTPResponse(MockSock) # type: ignore[arg-type]
1796 r.fp = fp # type: ignore[assignment]
1797 r.chunked = True
1798 r.chunk_left = None
1799 resp = HTTPResponse(
1800 r, preload_content=False, headers={"transfer-encoding": "chunked"}
1801 )
1802 with pytest.raises(ProtocolError) as ctx:
1803 next(resp.read_chunked())
1804
1805 orig_ex = ctx.value.args[1]
1806 msg = (
1807 "(\"Connection broken: InvalidChunkLength(got length b'ZZZ\\\\r\\\\n', 0 bytes read)\", "
1808 "InvalidChunkLength(got length b'ZZZ\\r\\n', 0 bytes read))"
1809 )
1810 assert str(ctx.value) == msg
1811 assert isinstance(orig_ex, InvalidChunkLength)
1812 assert orig_ex.length == fp.BAD_LENGTH_LINE.encode()
1813
1814 def test_truncated_before_chunk(self) -> None:
1815 stream = [b"foooo", b"bbbbaaaaar"]

Callers

nothing calls this directly

Calls 3

read_chunkedMethod · 0.95
HTTPResponseClass · 0.90

Tested by

no test coverage detected