Files
tea/tests/test_verify.py
T
AlbertoPMDM 0e942e04c1 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.
2026-11-19 01:28:54 -06:00

85 lines
3.2 KiB
Python

"""The cluster checks (verification/, outside the package): input guards, privacy, ages."""
from datetime import date
import numpy as np
import pytest
from verification import common, hk1k, issste
@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_hk1k_guard_refuses_other_prefixes(p):
with pytest.raises(PermissionError):
hk1k.guard(p)
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 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
@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):
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