Skip to content

Commit bf32deb

Browse files
committed
remove lz4 as optional dependency from test_xopen.py
1 parent 8e474a8 commit bf32deb

1 file changed

Lines changed: 2 additions & 33 deletions

File tree

tests/test_xopen.py

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def test_binary(fname):
111111
def test_roundtrip(ext, tmp_path, threads, mode):
112112
if ext == ".zst" and threads == 0 and zstandard is None:
113113
return
114-
if ext == ".lz4" and threads == 0 and lz4 is None:
115-
pytest.skip("lz4 not installed")
116114
path = tmp_path / f"file{ext}"
117115
data = b"Hello" if mode == "b" else "Hello"
118116
with xopen(path, "w" + mode, threads=threads) as f:
@@ -124,8 +122,6 @@ def test_roundtrip(ext, tmp_path, threads, mode):
124122
def test_binary_no_isal_no_threads(fname, xopen_without_igzip):
125123
if fname.endswith(".zst") and zstandard is None:
126124
return
127-
if fname.endswith(".lz4") and lz4 is None:
128-
pytest.skip("lz4 not installed")
129125
with xopen_without_igzip(fname, "rb", threads=0) as f:
130126
lines = list(f)
131127
assert len(lines) == 2
@@ -276,8 +272,6 @@ def test_invalid_compression_level(tmp_path):
276272
def test_append(ext, threads, tmp_path):
277273
if ext == ".zst" and zstandard is None and threads == 0:
278274
pytest.skip("No zstandard installed")
279-
if ext == ".lz4" and lz4 is None and threads == 0:
280-
pytest.skip("No lz4 installed")
281275
text = b"AB"
282276
reference = text + text
283277
path = tmp_path / f"the-file{ext}"
@@ -359,14 +353,11 @@ def test_read_no_threads(ext):
359353
".gz": gzip.GzipFile,
360354
".xz": lzma.LZMAFile,
361355
".zst": io.BufferedReader,
356+
".lz4": lz4.frame.LZ4FrameFile,
362357
"": io.BufferedReader,
363358
}
364359
if ext == ".zst" and zstandard is None:
365360
return
366-
if ext == ".lz4" and lz4 is None:
367-
pytest.skip("lz4 not installed")
368-
elif ext == ".lz4" and lz4:
369-
klasses[".lz4"] = lz4.frame.LZ4FrameFile
370361
klass = klasses[ext]
371362
with xopen(TEST_DIR / f"file.txt{ext}", "rb", threads=0) as f:
372363
assert isinstance(f, klass), f
@@ -393,18 +384,13 @@ def test_write_no_threads(tmp_path, ext):
393384
".bz2": bz2.BZ2File,
394385
".gz": gzip.GzipFile,
395386
".xz": lzma.LZMAFile,
387+
".lz4": lz4.frame.LZ4FrameFile,
396388
"": io.BufferedWriter,
397389
}
398390
if ext == ".zst":
399391
# Skip zst because if python-zstandard is not installed,
400392
# we fall back to an external process even when threads=0
401393
return
402-
if ext == ".lz4" and lz4 is None:
403-
# if lz4 is not installed, we skip this test
404-
pytest.skip("lz4 not installed")
405-
elif ext == ".lz4" and lz4:
406-
# test if lz4 is installed
407-
klasses[".lz4"] = lz4.frame.LZ4FrameFile
408394
klass = klasses[ext]
409395
with xopen(tmp_path / f"out{ext}", "wb", threads=0) as f:
410396
if isinstance(f, io.BufferedWriter):
@@ -546,8 +532,6 @@ def test_override_output_format_wrong_format(tmp_path):
546532
def test_text_encoding_newline_passthrough(opener, extension, tmp_path):
547533
if extension == ".zst" and zstandard is None:
548534
return
549-
if extension == ".lz4" and lz4 is None:
550-
pytest.skip("lz4 not installed")
551535
# "Eén ree\nTwee reeën\n" latin-1 encoded with \r for as line separator.
552536
encoded_text = b"E\xe9n ree\rTwee ree\xebn\r"
553537
path = tmp_path / f"test.txt{extension}"
@@ -563,8 +547,6 @@ def test_text_encoding_newline_passthrough(opener, extension, tmp_path):
563547
def test_text_encoding_errors(opener, extension, tmp_path):
564548
if extension == ".zst" and zstandard is None:
565549
return
566-
if extension == ".lz4" and lz4 is None:
567-
pytest.skip("lz4 not installed")
568550
# "Eén ree\nTwee reeën\n" latin-1 encoded. This is not valid ascii.
569551
encoded_text = b"E\xe9n ree\nTwee ree\xebn\n"
570552
path = tmp_path / f"test.txt{extension}"
@@ -621,9 +603,6 @@ def test_xopen_zst_long_window_size(threads):
621603
def test_pass_file_object_for_reading(ext, threads):
622604
if ext == ".zst" and zstandard is None:
623605
return
624-
if ext == ".lz4" and lz4 is None:
625-
pytest.skip("lz4 not installed")
626-
627606
with open(TEST_DIR / f"file.txt{ext}", "rb") as fh:
628607
with xopen(fh, mode="rb", threads=threads) as f:
629608
assert f.readline() == CONTENT_LINES[0].encode("utf-8")
@@ -651,8 +630,6 @@ def test_pass_bytesio_for_reading_and_writing(ext, threads):
651630
format = None
652631
if ext == ".zst" and zstandard is None:
653632
return
654-
if ext == ".lz4" and lz4 is None:
655-
pytest.skip("lz4 not installed")
656633
first_line = CONTENT_LINES[0].encode("utf-8")
657634
writer = xopen(filelike, "wb", format=format, threads=threads)
658635
writer.write(first_line)
@@ -668,8 +645,6 @@ def test_pass_bytesio_for_reading_and_writing(ext, threads):
668645
def test_xopen_stdin(monkeypatch, ext, threads):
669646
if ext == ".zst" and zstandard is None:
670647
return
671-
if ext == ".lz4" and lz4 is None:
672-
pytest.skip("lz4 not installed")
673648
# Add encoding to suppress encoding warnings
674649
with open(TEST_DIR / f"file.txt{ext}", "rt", encoding="latin-1") as in_file:
675650
monkeypatch.setattr("sys.stdin", in_file)
@@ -693,8 +668,6 @@ def test_xopen_stdout(monkeypatch):
693668
def test_xopen_read_from_pipe(ext, threads):
694669
if ext == ".zst" and zstandard is None:
695670
return
696-
if ext == ".lz4" and lz4 is None:
697-
pytest.skip("lz4 not installed")
698671
in_file = TEST_DIR / f"file.txt{ext}"
699672
process = subprocess.Popen(("cat", str(in_file)), stdout=subprocess.PIPE)
700673
with xopen(process.stdout, "rt", threads=threads) as f:
@@ -708,8 +681,6 @@ def test_xopen_read_from_pipe(ext, threads):
708681
def test_xopen_write_to_pipe(threads, ext):
709682
if ext == ".zst" and zstandard is None:
710683
return
711-
if ext == ".lz4" and lz4 is None:
712-
pytest.skip("lz4 not installed")
713684
format = ext.lstrip(".")
714685
if format == "":
715686
format = None
@@ -731,8 +702,6 @@ def test_xopen_write_to_pipe(threads, ext):
731702
def test_xopen_dev_stdin_read(threads, ext):
732703
if ext == ".zst" and zstandard is None:
733704
return
734-
if ext == ".lz4" and lz4 is None:
735-
pytest.skip("lz4 not installed")
736705
file = str(Path(__file__).parent / f"file.txt{ext}")
737706
result = subprocess.run(
738707
f"cat {file} | python -c 'import xopen; "

0 commit comments

Comments
 (0)