Files
duocthu/ingestion/tests/test_validation_readiness.py

73 lines
2.2 KiB
Python

from ingestion.validation.readiness import evaluate, evaluate_chunks
def _count(monographs, gate_name):
return next(g.count for g in evaluate(monographs) if g.name == gate_name)
def test_readiness_rejects_a_part_without_source_span_provenance():
corpus = [{
"drug_id": "testdrug",
"source_page_range": [100, 100],
"sections": {
"ma_atc": {
"text": "N00AA00",
"parts": [{"kind": "prose", "text": "N00AA00", "source_span_ids": []}],
},
},
"tables": [],
}]
assert _count(corpus, "section_without_provenance") == 0
assert _count(corpus, "part_without_source_span_ids") == 1
def test_readiness_accepts_part_level_source_span_provenance():
corpus = [{
"drug_id": "testdrug",
"source_page_range": [100, 100],
"sections": {
"ma_atc": {
"text": "N00AA00",
"parts": [{
"kind": "prose", "text": "N00AA00",
"source_span_ids": ["p100_b1_l0_s0"],
}],
},
},
"tables": [],
}]
assert _count(corpus, "part_without_source_span_ids") == 0
def test_readiness_rejects_duplicate_physical_region_ids():
corpus = [{
"drug_id": "testdrug",
"source_page_range": [100, 100],
"sections": {},
"tables": [
{"table_id": "p100_t0", "quarantined": True},
{"table_id": "p100_t0", "quarantined": True},
],
}]
assert _count(corpus, "duplicate_table_id") == 1
def test_chunk_readiness_requires_a_verified_printed_page_range():
chunk = {
"chunk_id": "drug__dose__0",
"drug_id": "drug",
"section_key": "dose",
"chunk_kind": "prose",
"text": "Dose.",
"est_tokens": 2,
"attachments": [],
}
gates = evaluate_chunks([], [chunk])
missing = next(g for g in gates if g.name == "chunk_without_printed_page_range")
assert missing.count == 1
chunk["printed_page_range"] = [101, 102]
gates = evaluate_chunks([], [chunk])
present = next(g for g in gates if g.name == "chunk_without_printed_page_range")
assert present.count == 0