Files
PlantAI-dev/tests/unit/skills/test_gene_identify.py
2026-08-03 18:42:47 +08:00

87 lines
2.7 KiB
Python
Executable File

"""
GeneIdentify技能单元测试
"""
import pytest
from pathlib import Path
from unittest.mock import Mock, patch
PROJECT_ROOT = Path(__file__).resolve().parents[3]
@pytest.mark.unit
class TestGeneIdentifySkill:
"""测试基因鉴定技能"""
def test_skill_exists(self):
"""测试技能目录存在"""
skill_dir = PROJECT_ROOT / "skills" / "gene-identify"
assert skill_dir.exists()
assert (skill_dir / "SKILL.md").exists()
assert (skill_dir / "run.py").exists()
def test_skill_documentation(self):
"""测试技能文档完整"""
skill_doc = PROJECT_ROOT / "skills" / "gene-identify" / "SKILL.md"
content = skill_doc.read_text()
assert "Gene Identify" in content
assert "输入" in content
assert "输出" in content
assert "使用" in content
def test_skill_config(self):
"""测试技能配置存在"""
config_file = PROJECT_ROOT / "skills" / "gene-identify" / "config.yaml"
assert config_file.exists()
def test_required_tools(self):
"""测试必需工具存在"""
tools_dir = PROJECT_ROOT / "skills" / "gene-identify" / "tools"
# 工具目录可以不存在,但技能应该能运行
pass
@pytest.mark.parametrize("input_file,expected", [
("protein.fa", True),
("genes.fa", True),
("", False),
])
def test_input_validation(self, input_file, expected):
"""测试输入验证"""
# 模拟输入验证
is_valid = len(input_file) > 0 and input_file.endswith('.fa')
assert is_valid == expected
def test_output_structure(self):
"""测试输出结构定义"""
expected_outputs = [
"report.md",
"tables/gene_list.csv",
"tables/statistics.csv",
]
for output in expected_outputs:
assert output # 确保输出定义存在
@pytest.mark.unit
class TestSkillRegistry:
"""测试技能注册"""
def test_stage_registry_exists(self):
"""测试StageToolRegistry存在"""
from gfa_core.mas.tools.stage_registry import StageToolRegistry
assert StageToolRegistry is not None
def test_gene_identify_in_registry(self):
"""测试gene-identify在注册表中"""
from gfa_core.mas.tools.stage_registry import create_stage_registry
registry = create_stage_registry()
# 检查是否有gene-identify或类似ID
stage_ids = list(registry._tools.keys())
# 应该有基因鉴定相关的阶段
identify_stages = [s for s in stage_ids if 'identif' in s.lower()]
assert len(identify_stages) > 0