85 lines
2.8 KiB
Python
85 lines
2.8 KiB
Python
"""tests/test_catalog.py —— 阶段目录(映射表驱动 + 参数 schema + 前置补全)。"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
pytestmark = pytest.mark.bioflow_unit
|
|
|
|
|
|
def test_stage_names(catalog):
|
|
names = catalog.stage_names()
|
|
assert "identify" in names
|
|
assert "phylogeny" in names
|
|
assert len(names) >= 7
|
|
|
|
|
|
def test_has_and_get(catalog):
|
|
assert catalog.has("identify")
|
|
assert not catalog.has("fake_stage_xyz")
|
|
entry = catalog.get("identify")
|
|
assert entry.name == "identify"
|
|
assert entry.image == "bioflow-gf"
|
|
assert entry.module == "cli.run_identify"
|
|
assert entry.executable is True
|
|
assert entry.description == "基因家族鉴定"
|
|
assert entry.estimated_time == 5
|
|
assert entry.to_dict()["image"] == "bioflow-gf"
|
|
|
|
|
|
def test_params_schema(catalog):
|
|
entry = catalog.get("identify")
|
|
assert entry.params
|
|
for p in entry.params:
|
|
assert {"name", "type", "default", "source", "help"} <= set(p.keys())
|
|
names = {p["name"] for p in entry.params}
|
|
assert "cpu" in names and "required_pfams" in names
|
|
|
|
|
|
def test_inputs_outputs(catalog):
|
|
entry = catalog.get("identify")
|
|
assert any(i["name"] == "protein_fasta" for i in entry.inputs)
|
|
assert any(o["name"] == "final_members" for o in entry.outputs)
|
|
# 下游阶段通用跨阶段输入
|
|
entry2 = catalog.get("phylogeny")
|
|
assert entry2.inputs
|
|
|
|
|
|
def test_family_chain(catalog):
|
|
chain = catalog.family_chain()
|
|
assert chain[0] == "genome_prepare"
|
|
assert "identify" in chain
|
|
assert len(chain) == 5 # 测试映射表的 family_chain
|
|
|
|
|
|
def test_validate_chain(catalog):
|
|
assert catalog.validate_chain(["identify", "phylogeny"]) == []
|
|
assert catalog.validate_chain(["fake_stage_xyz"]) == ["fake_stage_xyz"]
|
|
|
|
|
|
def test_auto_fill_prerequisites(catalog):
|
|
"""FR-BIO-003:前置补全 + 拓扑排序(依赖在前)。"""
|
|
ordered, added = catalog.auto_fill_prerequisites(["motif", "phylogeny"])
|
|
assert "identify" in ordered
|
|
assert ordered.index("identify") < ordered.index("phylogeny")
|
|
assert ordered.index("phylogeny") < ordered.index("motif")
|
|
assert "identify" in added # 明示补全
|
|
|
|
|
|
def test_topo_order():
|
|
from app.services.bioflow.catalog import topo_order
|
|
# reference_classification 依赖 identify/phylogeny/motif/structure/domain/combo
|
|
ordered = topo_order(["reference_classification", "identify"])
|
|
assert ordered[0] == "identify"
|
|
assert ordered[-1] == "reference_classification"
|
|
|
|
|
|
def test_note_passthrough(catalog):
|
|
entry = catalog.get("expression")
|
|
assert entry.note.startswith("跨环境")
|
|
assert entry.to_dict()["note"] == entry.note
|
|
|
|
|
|
def test_dependencies(catalog):
|
|
assert "identify" in catalog.dependencies("phylogeny")
|
|
assert catalog.dependencies("identify") == []
|