Files
stack/tests/pfs/test_book.py
kert 550f53112b
Some checks failed
CI / lint (push) Successful in 52s
CI / notebooks-smoke (push) Successful in 2m27s
Deploy / changes (push) Successful in 58s
CI / test (push) Failing after 5m46s
Infra CI / notebooks (push) Successful in 1m43s
Infra CI / zotero (push) Successful in 26s
Deploy / report (push) Has been cancelled
Deploy / notebooks (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Infra CI / docs (push) Successful in 2m3s
Infra CI / llm (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
Infra CI / api (push) Has been cancelled
Infra CI / bcda (push) Has been cancelled
feat(lex): the book registry and the dossier sliced per view (S1)
2026-11-13 02:23:34 -05:00

74 lines
2.4 KiB
Python

"""The book registry (lex S1 Task 2)."""
from __future__ import annotations
from pathlib import Path
import pytest
from pfs.book import DOMAINS, BookEntry, load_book
def _yaml(tmp_path: Path, body: str) -> Path:
p = tmp_path / "book.yaml"
p.write_text("families:\n" + body, encoding="utf-8")
return p
def test_book_build_order() -> None:
book = load_book()
assert list(book)[:2] == ["HOME-VISITS", "OFFICE-EM"]
assert len(book) == 13
assert book["APCM"].domains[-1] == "APM linkage"
assert book["CCM"].codes.startswith("99490")
assert isinstance(book["HOME-VISITS"], BookEntry)
assert all(e.phase == 1 for e in book.values())
assert all(d in DOMAINS for e in book.values() for d in e.domains)
def test_domains_are_the_specs_nine_in_order() -> None:
assert len(DOMAINS) == 9 and DOMAINS[0] == "primary care"
assert DOMAINS[-1] == "prevention"
def test_book_normalizes_keys(tmp_path: Path) -> None:
p = _yaml(tmp_path, " ccm:\n name: Chronic\n phase: 2\n")
e = load_book(p)["CCM"]
assert (e.name, e.phase, e.domains, e.codes) == ("Chronic", 2, (), "")
def test_book_rejects_unknown_domain(tmp_path: Path) -> None:
p = _yaml(tmp_path, " XFAM:\n name: X\n phase: 1\n domains: [nope]\n")
with pytest.raises(ValueError, match="XFAM"):
load_book(p)
@pytest.mark.parametrize("phase", ["0", "4", "'1'", "true"])
def test_book_rejects_bad_phase(tmp_path: Path, phase: str) -> None:
p = _yaml(tmp_path, f" XFAM:\n name: X\n phase: {phase}\n")
with pytest.raises(ValueError, match="XFAM"):
load_book(p)
def test_book_rejects_empty_name(tmp_path: Path) -> None:
p = _yaml(tmp_path, " XFAM:\n name: ' '\n phase: 1\n")
with pytest.raises(ValueError, match="XFAM"):
load_book(p)
def test_book_rejects_duplicate_key(tmp_path: Path) -> None:
body = " XFAM:\n name: X\n phase: 1\n xfam:\n name: Y\n phase: 1\n"
with pytest.raises(ValueError, match="XFAM"):
load_book(_yaml(tmp_path, body))
body = " XFAM:\n name: X\n phase: 1\n XFAM:\n name: Y\n phase: 1\n"
with pytest.raises(ValueError, match="XFAM"):
load_book(_yaml(tmp_path, body))
def test_book_without_families_is_empty(tmp_path: Path) -> None:
p = tmp_path / "b.yaml"
p.write_text("other: 1\n", encoding="utf-8")
assert load_book(p) == {}
p.write_text("", encoding="utf-8")
assert load_book(p) == {}