Skip to content

Commit ed6ed6d

Browse files
committed
Skip lz4 tests only if neither the bindings nor the lz4 binary are installed
1 parent 4c18c24 commit ed6ed6d

1 file changed

Lines changed: 3 additions & 24 deletions

File tree

tests/test_xopen.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
TEST_DIR = Path(__file__).parent
3333
CONTENT_LINES = ["Testing, testing ...\n", "The second line.\n"]
3434
CONTENT = "".join(CONTENT_LINES)
35-
extensions = ["", ".gz", ".bz2", ".xz", ".lz4"]
35+
extensions = ["", ".gz", ".bz2", ".xz"]
3636
if shutil.which("zstd") or zstandard:
3737
extensions += [".zst"]
38+
if shutil.which("lz4") or lz4:
39+
extensions += [".lz4"]
3840
base = os.path.join(os.path.dirname(__file__), "file.txt")
3941
files = [base + ext for ext in extensions]
4042

@@ -113,8 +115,6 @@ def test_binary(fname):
113115
def test_roundtrip(ext, tmp_path, threads, mode):
114116
if ext == ".zst" and threads == 0 and zstandard is None:
115117
return
116-
if ext == ".lz4" and shutil.which("lz4") is None:
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,8 +209,6 @@ 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")
214212
path = tmp_path / f"out{ext}"
215213
with xopen(path, mode="w") as f:
216214
# Writing anything isn’t strictly necessary, but if we don’t, then
@@ -278,8 +276,6 @@ def test_invalid_compression_level(tmp_path):
278276
def test_append(ext, threads, tmp_path):
279277
if ext == ".zst" and zstandard is None and threads == 0:
280278
pytest.skip("No zstandard installed")
281-
if ext == ".lz4" and shutil.which("lz4") is None:
282-
pytest.skip("lz4 not installed")
283279
text = b"AB"
284280
reference = text + text
285281
path = tmp_path / f"the-file{ext}"
@@ -296,8 +292,6 @@ def test_append(ext, threads, tmp_path):
296292

297293
@pytest.mark.parametrize("ext", extensions)
298294
def test_append_text(ext, tmp_path):
299-
if ext == ".lz4" and shutil.which("lz4") is None:
300-
pytest.skip("lz4 not installed")
301295
text = "AB"
302296
reference = text + text
303297
path = tmp_path / f"the-file{ext}"
@@ -391,8 +385,6 @@ def test_read_no_threads(ext):
391385

392386

393387
def test_write_threads(tmp_path, ext):
394-
if ext == ".lz4" and shutil.which("lz4") is None:
395-
pytest.skip("lz4 not installed")
396388
path = tmp_path / f"out.{ext}"
397389
with xopen(path, mode="w", threads=3) as f:
398390
f.write("hello")
@@ -420,7 +412,6 @@ def test_write_no_threads(tmp_path, ext):
420412
# we fall back to an external process even when threads=0
421413
return
422414
if ext == ".lz4" and lz4 is None:
423-
# Skip lz4 if lz4 is not installed
424415
return
425416
if ext == ".lz4" and lz4.frame is not None:
426417
klasses[".lz4"] = lz4.frame.LZ4FrameFile
@@ -473,8 +464,6 @@ def test_read_pathlib_binary(fname):
473464

474465

475466
def test_write_pathlib(ext, tmp_path):
476-
if ext == ".lz4" and shutil.which("lz4") is None:
477-
pytest.skip("lz4 not installed")
478467
path = tmp_path / f"hello.txt{ext}"
479468
with xopen(path, mode="wt") as f:
480469
f.write("hello")
@@ -483,8 +472,6 @@ def test_write_pathlib(ext, tmp_path):
483472

484473

485474
def test_write_pathlib_binary(ext, tmp_path):
486-
if ext == ".lz4" and shutil.which("lz4") is None:
487-
pytest.skip("lz4 not installed")
488475
path = tmp_path / f"hello.txt{ext}"
489476
with xopen(path, mode="wb") as f:
490477
f.write(b"hello")
@@ -522,8 +509,6 @@ def test_falls_back_to_lzma_open(lacking_xz_permissions):
522509

523510

524511
def test_open_many_writers(tmp_path, ext):
525-
if ext == ".lz4" and shutil.which("lz4") is None:
526-
pytest.skip("lz4 not installed")
527512
files = []
528513
# Because lzma.open allocates a lot of memory,
529514
# open fewer files to avoid MemoryError on 32-bit architectures
@@ -569,8 +554,6 @@ def test_override_output_format_wrong_format(tmp_path):
569554
@pytest.mark.parametrize("opener", OPENERS)
570555
@pytest.mark.parametrize("extension", extensions)
571556
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")
574557
if extension == ".zst" and zstandard is None:
575558
return
576559
# "Eén ree\nTwee reeën\n" latin-1 encoded with \r for as line separator.
@@ -586,8 +569,6 @@ def test_text_encoding_newline_passthrough(opener, extension, tmp_path):
586569
@pytest.mark.parametrize("opener", OPENERS)
587570
@pytest.mark.parametrize("extension", extensions)
588571
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")
591572
if extension == ".zst" and zstandard is None:
592573
return
593574
# "Eén ree\nTwee reeën\n" latin-1 encoded. This is not valid ascii.
@@ -727,8 +708,6 @@ def test_xopen_read_from_pipe(ext, threads):
727708

728709
@pytest.mark.parametrize("threads", (0, 1))
729710
def test_xopen_write_to_pipe(threads, ext):
730-
if ext == ".lz4" and shutil.which("lz4") is None:
731-
pytest.skip("lz4 not installed")
732711
if ext == ".zst" and zstandard is None:
733712
return
734713
format = ext.lstrip(".")

0 commit comments

Comments
 (0)