from datetime import date import pytest from edf_files import small_edf from models.tea.eeg.read import FileNotValid, Header, _kept, header def test_header_reads_the_facts(tmp_path): data = small_edf(tmp_path / "a.edf") assert header(data) == Header( "N1001", "F", date(2025, 1, 5), date(2026, 3, 2), "LAB-1", 20.0, 3 ) def test_placeholders_are_none(tmp_path): data = small_edf( tmp_path / "a.edf", patient_code="X", sex="X", birthdate=None, startdate=date(1985, 1, 1), record_code="X", ) # fmt: skip assert header(data) == Header(None, None, None, None, None, 20.0, 3) def test_header_does_not_read_the_signal(tmp_path): data = small_edf(tmp_path / "a.edf") truncated = data[: int(data[184:192])] assert header(truncated) == header(data) assert header(truncated).duration_s == 20.0 with pytest.warns(UserWarning, match="Updating header"): with pytest.raises(FileNotValid, match="truncated"): _kept(truncated) def test_zero_signal_header_is_valid(tmp_path): data = small_edf(tmp_path / "a.edf") zero = data[:184] + b"256 " + data[192:252] + b"0 " assert header(zero).channels == 0 with pytest.raises(FileNotValid, match="ZeroDivisionError"): _kept(zero) @pytest.mark.parametrize("data", [b"", b"x" * 100, b"x" * 300]) def test_not_an_edf_is_not_valid(data): with pytest.raises(FileNotValid): header(data) def test_kept_channels_are_unchanged(tmp_path): data = small_edf(tmp_path / "a.edf") assert _kept(data) == [("Fp1", "Fp1"), ("Fp2", "Fp2"), ("Cz", "Cz")]