74 lines
2.8 KiB
Python
74 lines
2.8 KiB
Python
from __future__ import annotations
|
|
|
|
from src.rag.qa_v1_1_73 import soft_gate_policy as module
|
|
|
|
|
|
def test_gate_policy_defaults_and_fails_closed_to_legacy():
|
|
assert module.gate_policy({}) == "legacy"
|
|
assert (
|
|
module.gate_policy({"QA_AGENTIC_GATE_POLICY": "soft_compat_v1"})
|
|
== "soft_compat_v1"
|
|
)
|
|
assert module.gate_policy({"QA_AGENTIC_GATE_POLICY": "unexpected"}) == "legacy"
|
|
|
|
|
|
def test_closed_type_compatibility_map_and_answer_slots():
|
|
compatible = [
|
|
("pathogen", ["organism_group"], False),
|
|
("organism_group", ["pathogen"], False),
|
|
("compartment", ["organelle"], False),
|
|
("compartment", ["cellular_component"], False),
|
|
("organelle", ["compartment"], False),
|
|
("transcription_factor", ["gene"], False),
|
|
("transcription_factor", ["protein"], False),
|
|
("gene_group", ["biosynthetic_gene_set"], False),
|
|
("biosynthetic_gene_set", ["gene_group"], False),
|
|
("enzyme", ["enzyme_activity"], False),
|
|
("enzyme_activity", ["enzyme"], False),
|
|
("genetic_variant", ["gene", "condition"], True),
|
|
("gene", ["expression_pattern"], False),
|
|
("tissue", ["regulatory_relationship"], False),
|
|
]
|
|
|
|
for actual, requested, relationship_context in compatible:
|
|
accepted, reason = module.type_compatibility(
|
|
actual,
|
|
requested,
|
|
relationship_context=relationship_context,
|
|
)
|
|
assert accepted, (actual, requested, reason)
|
|
|
|
assert not module.type_compatibility("pathogen", ["phenotype"])[0]
|
|
assert not module.type_compatibility("genetic_variant", ["gene"])[0]
|
|
assert not module.type_compatibility("unknown_new_type", ["gene"])[0]
|
|
|
|
|
|
def test_doi_from_paper_id_accepts_only_unambiguous_internal_form():
|
|
|
|
assert (
|
|
module.doi_from_paper_id("10.3389_fpls.2016.00954")
|
|
== "10.3389/fpls.2016.00954"
|
|
)
|
|
assert (
|
|
module.doi_from_paper_id("10.1016_j.cj.2021.04.004")
|
|
== "10.1016/j.cj.2021.04.004"
|
|
)
|
|
assert module.doi_from_paper_id("10.1093_jxb_ery350") == "10.1093/jxb/ery350"
|
|
assert (
|
|
module.doi_from_paper_id("10.1093_plphys_kiac335")
|
|
== "10.1093/plphys/kiac335"
|
|
)
|
|
assert module.doi_from_paper_id("PMC123") == ""
|
|
assert module.doi_from_paper_id("12345678") == ""
|
|
assert module.doi_from_paper_id("10.3389_fpls_2016_00954") == ""
|
|
assert module.doi_from_paper_id("10.3389/") == ""
|
|
assert module.doi_from_paper_id("not_a_doi") == ""
|
|
|
|
|
|
def test_pmcid_from_paper_id_accepts_only_leading_pmc_accession():
|
|
|
|
assert module.pmcid_from_paper_id("PMC10299364_ijms-24-10165") == "PMC10299364"
|
|
assert module.pmcid_from_paper_id("pmc8508941") == "PMC8508941"
|
|
assert module.pmcid_from_paper_id("prefix_PMC10299364") == ""
|
|
assert module.pmcid_from_paper_id("PMC_10299364") == ""
|