From 48bf3f783e202ce3a62500377a141300506c6784 Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Mon, 10 Mar 2025 10:52:54 +0000 Subject: [PATCH 1/2] Fix stupid du test Closes #330 --- tests/test_core.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index 2f4aa838..a4cca200 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,3 +1,4 @@ +import subprocess import sys import numpy as np @@ -231,16 +232,14 @@ def test_examples(self, chunk_size, size, start, stop): @pytest.mark.skipif(sys.platform != "linux", reason="Only valid on Linux") @pytest.mark.parametrize( - ("path", "expected"), + "path", [ - # NOTE: this data is generated using du -sb on a Linux system. - # It works in CI on Linux, but it'll probably break at some point. - # It's also necessary to update these numbers each time a new data - # file gets added - ("tests/data", 4983044), - ("tests/data/vcf", 4970907), - ("tests/data/vcf/sample.vcf.gz", 1089), + "tests/data", + "tests/data/vcf", + "tests/data/vcf/sample.vcf.gz", ], ) -def test_du(path, expected): - assert core.du(path) == expected +def test_du(path): + s = subprocess.check_output(["du", "-sb", "--apparent-size", str(path)]).decode() + value = int(s.split()[0]) + assert core.du(path) == value From 46de3af27cf6318735a7dd8b34bbf7c4a6b35bd1 Mon Sep 17 00:00:00 2001 From: Jerome Kelleher Date: Mon, 10 Mar 2025 14:47:43 +0000 Subject: [PATCH 2/2] Copy directory tree to /tmp --- tests/test_core.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_core.py b/tests/test_core.py index a4cca200..e36904ce 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,5 +1,7 @@ +import pathlib import subprocess import sys +import tempfile import numpy as np import pytest @@ -240,6 +242,11 @@ def test_examples(self, chunk_size, size, start, stop): ], ) def test_du(path): - s = subprocess.check_output(["du", "-sb", "--apparent-size", str(path)]).decode() - value = int(s.split()[0]) - assert core.du(path) == value + with tempfile.TemporaryDirectory() as tmp_dir: + subprocess.check_call(["cp", "-pR", "tests", tmp_dir]) + copy_path = pathlib.Path(tmp_dir) / path + s = subprocess.check_output( + ["du", "-sb", "--apparent-size", str(copy_path)] + ).decode() + value = int(s.split()[0]) + assert core.du(path) == value