Skip to content

Commit 15d59db

Browse files
committed
check if lz4 is present in the system. avoid errors on windows
1 parent f59fa84 commit 15d59db

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

tests/test_xopen.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_roundtrip(ext, tmp_path, threads, mode):
114114
if ext == ".zst" and threads == 0 and zstandard is None:
115115
return
116116
if ext == ".lz4" and shutil.which("lz4") is None:
117-
return
117+
pytest.skip("lz4 not installed")
118118
path = tmp_path / f"file{ext}"
119119
data = b"Hello" if mode == "b" else "Hello"
120120
with xopen(path, "w" + mode, threads=threads) as f:
@@ -209,6 +209,8 @@ def test_next(fname):
209209

210210

211211
def test_has_iter_method(ext, tmp_path):
212+
if ext == ".lz4" and shutil.which("lz4") is None:
213+
pytest.skip("lz4 not installed")
212214
path = tmp_path / f"out{ext}"
213215
with xopen(path, mode="w") as f:
214216
# Writing anything isn’t strictly necessary, but if we don’t, then
@@ -276,6 +278,8 @@ def test_invalid_compression_level(tmp_path):
276278
def test_append(ext, threads, tmp_path):
277279
if ext == ".zst" and zstandard is None and threads == 0:
278280
pytest.skip("No zstandard installed")
281+
if ext == ".lz4" and shutil.which("lz4") is None:
282+
pytest.skip("lz4 not installed")
279283
text = b"AB"
280284
reference = text + text
281285
path = tmp_path / f"the-file{ext}"
@@ -292,6 +296,8 @@ def test_append(ext, threads, tmp_path):
292296

293297
@pytest.mark.parametrize("ext", extensions)
294298
def test_append_text(ext, tmp_path):
299+
if ext == ".lz4" and shutil.which("lz4") is None:
300+
pytest.skip("lz4 not installed")
295301
text = "AB"
296302
reference = text + text
297303
path = tmp_path / f"the-file{ext}"
@@ -385,6 +391,8 @@ def test_read_no_threads(ext):
385391

386392

387393
def test_write_threads(tmp_path, ext):
394+
if ext == ".lz4" and shutil.which("lz4") is None:
395+
pytest.skip("lz4 not installed")
388396
path = tmp_path / f"out.{ext}"
389397
with xopen(path, mode="w", threads=3) as f:
390398
f.write("hello")
@@ -465,6 +473,8 @@ def test_read_pathlib_binary(fname):
465473

466474

467475
def test_write_pathlib(ext, tmp_path):
476+
if ext == ".lz4" and shutil.which("lz4") is None:
477+
pytest.skip("lz4 not installed")
468478
path = tmp_path / f"hello.txt{ext}"
469479
with xopen(path, mode="wt") as f:
470480
f.write("hello")
@@ -473,6 +483,8 @@ def test_write_pathlib(ext, tmp_path):
473483

474484

475485
def test_write_pathlib_binary(ext, tmp_path):
486+
if ext == ".lz4" and shutil.which("lz4") is None:
487+
pytest.skip("lz4 not installed")
476488
path = tmp_path / f"hello.txt{ext}"
477489
with xopen(path, mode="wb") as f:
478490
f.write(b"hello")
@@ -510,6 +522,8 @@ def test_falls_back_to_lzma_open(lacking_xz_permissions):
510522

511523

512524
def test_open_many_writers(tmp_path, ext):
525+
if ext == ".lz4" and shutil.which("lz4") is None:
526+
pytest.skip("lz4 not installed")
513527
files = []
514528
# Because lzma.open allocates a lot of memory,
515529
# open fewer files to avoid MemoryError on 32-bit architectures
@@ -555,6 +569,8 @@ def test_override_output_format_wrong_format(tmp_path):
555569
@pytest.mark.parametrize("opener", OPENERS)
556570
@pytest.mark.parametrize("extension", extensions)
557571
def test_text_encoding_newline_passthrough(opener, extension, tmp_path):
572+
if extension == ".lz4" and shutil.which("lz4") is None:
573+
pytest.skip("lz4 not installed")
558574
if extension == ".zst" and zstandard is None:
559575
return
560576
# "Eén ree\nTwee reeën\n" latin-1 encoded with \r for as line separator.
@@ -570,6 +586,8 @@ def test_text_encoding_newline_passthrough(opener, extension, tmp_path):
570586
@pytest.mark.parametrize("opener", OPENERS)
571587
@pytest.mark.parametrize("extension", extensions)
572588
def test_text_encoding_errors(opener, extension, tmp_path):
589+
if extension == ".lz4" and shutil.which("lz4") is None:
590+
pytest.skip("lz4 not installed")
573591
if extension == ".zst" and zstandard is None:
574592
return
575593
# "Eén ree\nTwee reeën\n" latin-1 encoded. This is not valid ascii.
@@ -709,6 +727,8 @@ def test_xopen_read_from_pipe(ext, threads):
709727

710728
@pytest.mark.parametrize("threads", (0, 1))
711729
def test_xopen_write_to_pipe(threads, ext):
730+
if ext == ".lz4" and shutil.which("lz4") is None:
731+
pytest.skip("lz4 not installed")
712732
if ext == ".zst" and zstandard is None:
713733
return
714734
format = ext.lstrip(".")

0 commit comments

Comments
 (0)