Files
tea/tests/test_plan.py
T

53 lines
1.7 KiB
Python

"""PreprocessPlan: checks, round trip, hash."""
from __future__ import annotations
import json
import pytest
from tea.preprocessing import (
DIRECTOR_CLI,
DIRECTOR_CLUSTER,
PreprocessPlan,
StepSpec,
VariantSpec,
)
def test_round_trip_through_json():
for plan in (DIRECTOR_CLUSTER, DIRECTOR_CLI):
d = json.loads(json.dumps(plan.to_dict()))
again = PreprocessPlan.from_dict(d)
assert again == plan
assert again.content_hash() == plan.content_hash() == d["hash"]
def test_hash_ignores_reasons_and_bads_but_not_parameters():
p = DIRECTOR_CLUSTER
assert p.without("Fz", reason="test").content_hash() == p.content_hash()
assert p.with_step("lowpass", hz=70).content_hash() != p.content_hash()
def test_checks():
with pytest.raises(ValueError, match="unknown step"):
StepSpec("wavelet")
with pytest.raises(ValueError, match="reference"):
VariantSpec("x", 0.5, "ipsilateral")
with pytest.raises(ValueError, match="below the lowpass"):
DIRECTOR_CLUSTER.with_step("lowpass", hz=0.4)
with pytest.raises(ValueError, match="one line-removal"):
DIRECTOR_CLUSTER.with_step("zapline")
with pytest.raises(ValueError, match="unknown plan keys"):
PreprocessPlan.from_dict({**DIRECTOR_CLUSTER.to_dict(), "lowpas": 3})
with pytest.raises(ValueError, match="reason"):
DIRECTOR_CLUSTER.without("Fz", reason=" ")
def test_route_differences_are_data():
c, l = DIRECTOR_CLUSTER, DIRECTOR_CLI
assert c.step("lowpass").params["hz"] == 100 and l.step("lowpass").params["hz"] == 45
assert c.state.cutoffs == "hk1k" and l.state.cutoffs == "cohort"
assert c.state.mask and not l.state.mask
assert l.state.use_n3 and not c.state.use_n3