File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class StringIOWithLargeCursorPositions(StringIO):
1111 def seek (self , offset , whence ):
1212 input_offset , output_offset = 0 , 0
1313 if offset != 0 :
14- input_offset = - 2 ** 64
14+ input_offset = - ( 2 ** 64 )
1515 if whence == SEEK_CUR :
1616 output_offset = 2 ** 64
1717 if whence == SEEK_END :
@@ -56,3 +56,26 @@ def make_unseekable_bytesio(s: str):
5656 return make_unseekable_bytesio
5757 else :
5858 assert False
59+
60+
61+ # TODO: Factor out commonalities with ^
62+ @pytest .fixture (params = ["bytes" , "bytes-unseekable" ])
63+ def bytes_to_bytes_buf (request ):
64+ """
65+ Provides function that takes bytes and returns a bytes buffer.
66+
67+ Causes dependent test to be repeated for all relevant byte buffer types
68+ (seekable, unseekable).
69+ """
70+ if request .param == "bytes" :
71+ return lambda b : BytesIO (b )
72+ elif request .param == "bytes-unseekable" :
73+
74+ def make_unseekable_bytesio (b : bytes ):
75+ bio = BytesIO (b )
76+ bio .seekable = lambda : False
77+ return bio
78+
79+ return make_unseekable_bytesio
80+ else :
81+ assert False
Original file line number Diff line number Diff line change @@ -42,3 +42,12 @@ def test_invalid_character_code():
4242 ),
4343 ):
4444 list (load (StringIO (r'"\uz"' )))
45+
46+
47+ def test_malformed_utf8 (bytes_to_bytes_buf ):
48+ buf = bytes_to_bytes_buf (bytes ([129 ]))
49+ with pytest .raises (
50+ OSError ,
51+ match = re .escape ("malformed UTF-8 of 1 bytes at line 1 char 1" ),
52+ ):
53+ list (load (buf ))
You can’t perform that action at this time.
0 commit comments