@@ -350,34 +350,20 @@ def test_meta2_page(datapath):
350
350
assert len (df ) == 1000
351
351
352
352
353
- @pytest .mark .parametrize ("test_file" , ["test2.sas7bdat" , "test3.sas7bdat" ])
354
- def test_exception_propagation_rdc_rle_decompress (datapath , monkeypatch , test_file ):
355
- """Errors in RLE/RDC decompression should propagate the same error."""
356
- orig_np_zeros = np .zeros
357
-
358
- def _patched_zeros (size , dtype ):
359
- if isinstance (size , int ):
360
- # np.zeros() call in {rdc,rle}_decompress
361
- raise Exception ("Test exception" )
362
- else :
363
- # Other calls to np.zeros
364
- return orig_np_zeros (size , dtype )
365
-
366
- monkeypatch .setattr (np , "zeros" , _patched_zeros )
367
-
368
- with pytest .raises (Exception , match = "^Test exception$" ):
369
- pd .read_sas (datapath ("io" , "sas" , "data" , test_file ))
370
-
371
-
372
- def test_exception_propagation_rle_decompress (tmp_path , datapath ):
373
- """Illegal control byte in RLE decompressor should raise the correct ValueError."""
374
- with open (datapath ("io" , "sas" , "data" , "test2.sas7bdat" ), "rb" ) as f :
353
+ @pytest .mark .parametrize (
354
+ "test_file, override_offset, override_value, expected_msg" ,
355
+ [
356
+ ("test2.sas7bdat" , 0x10000 + 55229 , 0x80 | 0x0F , "Out of bounds" ),
357
+ ("test2.sas7bdat" , 0x10000 + 55229 , 0x10 , "unknown control byte" ),
358
+ ("test3.sas7bdat" , 118170 , 184 , "Out of bounds" ),
359
+ ],
360
+ )
361
+ def test_rle_rdc_exceptions (
362
+ datapath , test_file , override_offset , override_value , expected_msg
363
+ ):
364
+ """Errors in RLE/RDC decompression should propagate."""
365
+ with open (datapath ("io" , "sas" , "data" , test_file ), "rb" ) as f :
375
366
data = bytearray (f .read ())
376
- invalid_control_byte = 0x10
377
- page_offset = 0x10000
378
- control_byte_pos = 55229
379
- data [page_offset + control_byte_pos ] = invalid_control_byte
380
- tmp_file = tmp_path / "test2.sas7bdat"
381
- tmp_file .write_bytes (data )
382
- with pytest .raises (ValueError , match = "unknown control byte" ):
383
- pd .read_sas (tmp_file )
367
+ data [override_offset ] = override_value
368
+ with pytest .raises (Exception , match = expected_msg ):
369
+ pd .read_sas (io .BytesIO (data ), format = "sas7bdat" )
0 commit comments