Skip to content

Commit 43c68c8

Browse files
authored
Test pickling of InvalidChunkLength (#5247)
1 parent 308b279 commit 43c68c8

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

‎test/test_exceptions.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import io
34
import pickle
45
import socket
56
from email.errors import MessageDefect
@@ -16,12 +17,14 @@
1617
HeaderParsingError,
1718
HostChangedError,
1819
HTTPError,
20+
InvalidChunkLength,
1921
LocationParseError,
2022
MaxRetryError,
2123
NameResolutionError,
2224
NewConnectionError,
2325
ReadTimeoutError,
2426
)
27+
from urllib3.response import HTTPResponse
2528

2629

2730
class TestPickle:
@@ -65,6 +68,24 @@ def test_exceptions(self, exception: Exception) -> None:
6568
# reason is likely an exception so do string comparison instead
6669
assert str(exception._reason) == str(result._reason) # type: ignore[attr-defined]
6770

71+
def test_invalid_chunk_length(self) -> None:
72+
response = HTTPResponse(
73+
body=io.BytesIO(b"abcdef"),
74+
headers={"Content-Length": "10"},
75+
preload_content=False,
76+
)
77+
response.read(3)
78+
exception = InvalidChunkLength(response, b"zz")
79+
assert exception.partial == 3
80+
assert exception.expected == 7
81+
82+
result = pickle.loads(pickle.dumps(exception))
83+
assert isinstance(result, InvalidChunkLength)
84+
assert result.partial == exception.partial
85+
assert result.expected == exception.expected
86+
assert result.length == exception.length
87+
assert repr(result) == repr(exception)
88+
6889

6990
class TestFormat:
7091
def test_header_parsing_errors(self) -> None:

0 commit comments

Comments
 (0)