File tree Expand file tree Collapse file tree 3 files changed +12
-20
lines changed Expand file tree Collapse file tree 3 files changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -192,8 +192,9 @@ def __init__( # noqa: C901
192
192
if isinstance (self ._infile , io .IOBase ):
193
193
# not supported (yet) for reading.
194
194
if "r" in mode :
195
- raise ValueError (
196
- "File object not supported for reading through Piped Program."
195
+ raise OSError (
196
+ f"File object not supported for reading through "
197
+ f"{ self .__class__ .__name__ } ."
197
198
)
198
199
path = path .name
199
200
if (
Original file line number Diff line number Diff line change @@ -378,3 +378,12 @@ def test_piped_tool_fails_on_close(tmp_path):
378
378
) as f :
379
379
f .write (b"Hello" )
380
380
assert "exit code 5" in e .value .args [0 ]
381
+
382
+
383
+ def test_piped_tool_fails_read_mode_with_filehandle (tmp_path ):
384
+ test_file = tmp_path / "test.txt.gz"
385
+ test_file .write_bytes (gzip .compress (b"test" ))
386
+ with open (test_file , "rb" ) as filehandle :
387
+ with pytest .raises (OSError ) as error :
388
+ _PipedCompressionProgram (filehandle , "rb" )
389
+ error .match ("File object not supported for reading" )
Original file line number Diff line number Diff line change @@ -578,24 +578,6 @@ def test_pass_file_object_for_reading_no_threads(ext):
578
578
assert f .readline () == CONTENT_LINES [0 ].encode ("utf-8" )
579
579
580
580
581
- @pytest .mark .parametrize ("ext" , extensions )
582
- def test_pass_file_object_for_reading (ext ):
583
- if ext == ".zst" and zstandard is None :
584
- return
585
- # non-compressed file do not raise error
586
- if not ext :
587
- return
588
- # todo : disable the gz modules to force piped compression.
589
- with open (TEST_DIR / f"file.txt{ ext } " , "rb" ) as fh :
590
- with pytest .raises (ValueError ) as e :
591
- with xopen (fh , mode = "rb" , threads = 1 ) as f :
592
- f .readline () # pragma: no cover
593
- assert (
594
- "File object not supported for reading through Piped Program"
595
- in e .value .args [0 ]
596
- )
597
-
598
-
599
581
@pytest .mark .parametrize ("ext" , extensions )
600
582
def test_pass_file_object_for_writing (tmp_path , ext ):
601
583
if ext == ".zst" and zstandard is None :
You can’t perform that action at this time.
0 commit comments