Files
Video-Tree-TRM5/tests/unit/test_question_gen_api.py
T
iomgaa eecb86e27a feat(question_gen): add generate-v2 CLI subcommand and experiment script
- Add generate-v2 subparser with --config, --store-dir, --db-path,
  --seed, and --dry-run arguments to tools/generate_questions.py
- Implement _run_generate_v2 async handler: config loading, video
  discovery, DI client construction, TreeIndex loading, pipeline
  invocation, and result persistence
- Add scripts/generate_questions_v2.sh following build_trees.sh
  conventions (source .env, conda run python path, MODE=mock support)
- Update app/question_gen/__init__.py to export full v2 public API:
  run_pipeline_v2, PipelineConfig, PipelineResult, QuestionFamilySpec,
  ALL_FAMILIES, CandidateQuestion, generate_one_v2, GateReport, run_gates
- Add QuestionGenStore.load_progress() for pipeline resumption
- Add integration tests for CLI help and dry-run behavior
- Update test_question_gen_api to match expanded __all__

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-07-12 00:04:42 -04:00

59 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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__ 包含预期的公开 APIv1 + v2)。"""
mod = importlib.import_module("app.question_gen")
assert set(mod.__all__) == {
# v1 接口
"load_benchmark",
"stratified_sample",
"TASK_TYPE_LEVEL_MAP",
"AnchorContext",
"generate_one",
"sample_anchor",
# v2 接口
"run_pipeline_v2",
"PipelineConfig",
"PipelineResult",
"QuestionFamilySpec",
"ALL_FAMILIES",
"CandidateQuestion",
"generate_one_v2",
"GateReport",
"run_gates",
}