verification/ out of the package; ISSSTELEÓN check; a Dask-level task failure is an error row
- verification/ (hk1k, issste, common) moved out of src/: not in the wheel; the image imports it with PYTHONPATH=/opt/tea-modulo. - python -m verification issste: every biomarker, legacy and modern, on processed/eeg-edf-2025|2026; age from the EDF header inside the task; group numbers only (file names, paths, dates and rows stay in the job). - Pipeline.map (Dask): a task that dies (KilledWorker) becomes an error row instead of stopping the batch. - deploy/verify.sh [hk1k|issste]; issste uses 3 workers x 6 GiB per pod.
This commit is contained in:
@@ -22,7 +22,6 @@ EXTRA = {
|
||||
"validation": {"fhir"},
|
||||
"serving": {"mlflow"},
|
||||
"pipeline": {"dask", "distributed", "s3fs", "fsspec", "psutil"},
|
||||
"verify": {"dask", "distributed", "s3fs", "fsspec"},
|
||||
"export": set(),
|
||||
}
|
||||
# lazy imports inside the director's figure / HDF5 helpers (never reached by legacy)
|
||||
@@ -90,8 +89,6 @@ def test_imports_respect_boundaries(path):
|
||||
if top == "tea_modulo":
|
||||
if unit and unit[0] == "export":
|
||||
ok = mod == own or mod.startswith(own + ".")
|
||||
elif unit == ("verify",):
|
||||
ok = True # an application: it wires everything, like tests do
|
||||
elif not unit:
|
||||
ok = mod in ("tea_modulo", "tea_modulo.contracts") or mod.startswith("tea_modulo.contracts.")
|
||||
else:
|
||||
|
||||
+14
-1
@@ -93,6 +93,19 @@ def test_no_posterior_channels_is_not_an_error(tmp_path):
|
||||
assert not np.isfinite(t.posterior_rhythm_hz.iloc[0]), impl
|
||||
|
||||
|
||||
def _inverse(x):
|
||||
return 1 / x
|
||||
|
||||
|
||||
def test_task_failure_becomes_a_row_not_a_stopped_batch():
|
||||
"""A task that fails at the Dask level (KilledWorker on the cluster) must not stop the batch."""
|
||||
out = dask_runner.run(_inverse, [(1,), (0,), (4,)], cluster="local", n_workers=1,
|
||||
memory_per_worker="1GiB", on_error=lambda a, e: f"{type(e).__name__} {a[0]}")
|
||||
assert out == [1.0, "ZeroDivisionError 0", 0.25]
|
||||
with pytest.raises(ZeroDivisionError):
|
||||
dask_runner.run(_inverse, [(0,)], cluster="local", n_workers=1, memory_per_worker="1GiB")
|
||||
|
||||
|
||||
def test_positive_priority_refused():
|
||||
with pytest.raises(ValueError, match="positive priorities"):
|
||||
dask_runner.run(lambda: 1, [()], cluster="sync", priority=1)
|
||||
@@ -137,6 +150,6 @@ def test_study_raises_not_valid(edfs):
|
||||
def test_remote_equals_sync(edfs):
|
||||
"""On the cluster job: the synthetic files are local to the job pod, so they are
|
||||
read by the driver-side sync run only; the remote run uses the HK1K check instead
|
||||
(tea_modulo.verify). Here we only check the remote scheduler answers a trivial graph."""
|
||||
(verification/, python -m verification hk1k). Here we only check the remote scheduler answers a trivial graph."""
|
||||
out = dask_runner.run(lambda x: x * 2, [(1,), (2,)], cluster="remote")
|
||||
assert out == [2, 4]
|
||||
|
||||
+66
-9
@@ -1,27 +1,84 @@
|
||||
"""The HK1K verification command refuses everything but the public HK1K prefix."""
|
||||
"""The cluster checks (verification/, outside the package): input guards, privacy, ages."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from tea_modulo.verify import hk1k
|
||||
from verification import common, hk1k, issste
|
||||
|
||||
|
||||
@pytest.mark.parametrize("p", ["raw/eeg-data/eeg_001/x.edf", "processed/eeg-edf/eeg_001/eeg_001.edf",
|
||||
@pytest.mark.parametrize("p", ["raw/eeg-data/eeg_001/x.edf", "processed/eeg-edf-2025/a/x.edf",
|
||||
"raw/2021-204/a.edf", "raw/eeg-helsinki/../eeg-data/x.edf"])
|
||||
def test_guard_refuses_other_prefixes(p):
|
||||
def test_hk1k_guard_refuses_other_prefixes(p):
|
||||
with pytest.raises(PermissionError):
|
||||
hk1k.guard(p)
|
||||
|
||||
|
||||
def test_guard_accepts_hk1k():
|
||||
def test_hk1k_guard_accepts_hk1k():
|
||||
assert hk1k.guard("s3://raw/eeg-helsinki/sub-1/x.edf") == "raw/eeg-helsinki/sub-1/x.edf"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("p", ["raw/eeg-data/eeg_001/x.edf", "raw/eeg-data-2026/a/x.erd",
|
||||
"raw/2021-204/a.edf", "processed/eeg-edf/eeg_001.edf",
|
||||
"processed/eeg-edf-2025/../cohort-edf-2025/x.edf", "raw/eeg-helsinki/x.edf"])
|
||||
def test_issste_guard_refuses_other_prefixes(p):
|
||||
with pytest.raises(PermissionError):
|
||||
issste.guard(p)
|
||||
|
||||
|
||||
def test_issste_guard_accepts_the_two_lots():
|
||||
for lot in ("2025", "2026"):
|
||||
p = f"processed/eeg-edf-{lot}/a/b.edf"
|
||||
assert issste.guard("s3://" + p) == p
|
||||
|
||||
|
||||
def test_group_stats_suppresses_small_groups():
|
||||
assert hk1k.group_stats([1.0, 2.0, 3.0]) == {"n": 3, "suppressed": True}
|
||||
s = hk1k.group_stats([6.0, 6.5, 7.0, 7.5, 8.0])
|
||||
assert common.group_stats([1.0, 2.0, 3.0]) == {"n": 3, "suppressed": True}
|
||||
s = common.group_stats([6.0, 6.5, 7.0, 7.5, 8.0])
|
||||
assert s["n"] == 5 and s["median"] == 7.0
|
||||
|
||||
|
||||
def test_summary_writes_only_to_user_area():
|
||||
@pytest.mark.parametrize("out", ["processed/eeg-edf-2025/", "raw/x/", "processed/usuarios/../eeg-edf/"])
|
||||
def test_summary_writes_only_to_user_area(out):
|
||||
with pytest.raises(PermissionError):
|
||||
hk1k.write_summary("{}", "processed/eeg-edf/", "x.json")
|
||||
common.write_summary("{}", out, "x.json")
|
||||
|
||||
|
||||
def test_clean_removes_paths_file_names_and_study_codes():
|
||||
msg = ("ValueError: bad header in /tmp/tea_s3_x/PEREZ~ GARCIA_1a2b.edf (eeg_017) "
|
||||
"and 'LOPEZ_3c.edf', [MARTINEZ.EDF]")
|
||||
out = common.clean(msg)
|
||||
for s in ("PEREZ", "GARCIA", "LOPEZ", "MARTINEZ", "eeg_017", "/tmp", ".edf", ".EDF"):
|
||||
assert s not in out, (s, out)
|
||||
assert out.startswith("ValueError: bad header")
|
||||
|
||||
|
||||
def test_age_from_a_real_edf_header(tmp_path):
|
||||
from edfio import Edf, EdfSignal, Patient, Recording
|
||||
p = tmp_path / "a.edf"
|
||||
Edf([EdfSignal(np.zeros(256), 256.0, label="Fz")],
|
||||
patient=Patient(birthdate=date(2023, 1, 15)),
|
||||
recording=Recording(startdate=date(2025, 4, 1))).write(p)
|
||||
head = p.read_bytes()[:256]
|
||||
assert issste.age_from_header(head) == round((date(2025, 4, 1) - date(2023, 1, 15)).days / 30.4375, 1)
|
||||
|
||||
|
||||
def test_age_missing_or_impossible_is_none(tmp_path):
|
||||
from edfio import Edf, EdfSignal, Patient, Recording
|
||||
p = tmp_path / "b.edf"
|
||||
Edf([EdfSignal(np.zeros(256), 256.0, label="Fz")], patient=Patient(),
|
||||
recording=Recording(startdate=date(2025, 4, 1))).write(p)
|
||||
assert issste.age_from_header(p.read_bytes()[:256]) is None
|
||||
assert issste.age_from_header(b"short") is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("m, g", [(15.9, "<16"), (16.0, "16-36"), (36.9, "16-36"), (37.0, "37-48"),
|
||||
(49.0, ">48"), (None, "no age"), (float("nan"), "no age")])
|
||||
def test_age_groups(m, g):
|
||||
assert issste.age_group(m) == g
|
||||
|
||||
|
||||
def test_verification_is_not_in_the_package():
|
||||
import importlib.util
|
||||
assert importlib.util.find_spec("tea_modulo.verify") is None
|
||||
|
||||
Reference in New Issue
Block a user