Files
pyflowx/tests/cli/test_tool_modules.py
T

29 lines
1.0 KiB
Python

"""Tests for pf._TOOL_MODULES 注册表完整性.
防止新增工具时遗漏 ``_TOOL_MODULES`` 注册项, 导致 ``pf <新工具>`` 静默失败.
"""
from __future__ import annotations
import importlib
import pytest
from pyflowx.cli.pf import PfApp
class TestToolModulesComplete:
"""``_TOOL_MODULES`` 必须覆盖 ``_TOOL_ALIASES`` 的所有规范名."""
def test_all_canonical_tools_have_module_path(self) -> None:
"""``_TOOL_ALIASES`` 的每个规范名都应在 ``_TOOL_MODULES`` 中有对应模块路径."""
canonical_names = set(PfApp._TOOL_ALIASES.values())
module_names = set(PfApp._TOOL_MODULES)
missing = canonical_names - module_names
assert not missing, f"未在 _TOOL_MODULES 注册的工具: {missing}"
@pytest.mark.parametrize("tool_name, module_path", sorted(PfApp._TOOL_MODULES.items()))
def test_module_importable(self, tool_name: str, module_path: str) -> None:
"""每个注册的模块路径必须可导入."""
importlib.import_module(module_path)