d8a903fb54
app/ports.py 追加 QuestionGenerator Protocol(预留 LLM 出题接口)。 app/question_gen/__init__.py re-export load_benchmark 和 stratified_sample。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
"""app/ports.py QuestionGenerator Protocol 与 app/question_gen 公开 API 测试。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
from app.ports import QuestionGenerator
|
|
|
|
|
|
class TestQuestionGeneratorProtocol:
|
|
def test_importable(self) -> None:
|
|
"""QuestionGenerator 可从 app.ports 导入。"""
|
|
assert QuestionGenerator is not None
|
|
|
|
def test_is_runtime_checkable(self) -> None:
|
|
"""QuestionGenerator 是 runtime_checkable Protocol。"""
|
|
assert hasattr(QuestionGenerator, "__protocol_attrs__") or hasattr(
|
|
QuestionGenerator, "__abstractmethods__"
|
|
)
|
|
|
|
def test_generate_method_exists(self) -> None:
|
|
"""Protocol 定义了 generate 方法。"""
|
|
assert hasattr(QuestionGenerator, "generate")
|
|
|
|
|
|
class TestQuestionGenPublicAPI:
|
|
def test_load_benchmark_importable_from_package(self) -> None:
|
|
"""load_benchmark 可从 app.question_gen 直接导入。"""
|
|
mod = importlib.import_module("app.question_gen")
|
|
assert hasattr(mod, "load_benchmark")
|
|
|
|
def test_stratified_sample_importable_from_package(self) -> None:
|
|
"""stratified_sample 可从 app.question_gen 直接导入。"""
|
|
mod = importlib.import_module("app.question_gen")
|
|
assert hasattr(mod, "stratified_sample")
|
|
|
|
def test_all_exports(self) -> None:
|
|
"""__all__ 包含预期的公开 API。"""
|
|
mod = importlib.import_module("app.question_gen")
|
|
assert set(mod.__all__) == {"load_benchmark", "stratified_sample"}
|