CourseDesign/tests/test_agent.py

28 lines
920 B
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.

import os
# 设置虚拟 key 以避免测试收集期间 pydantic-ai 初始化错误
os.environ["DEEPSEEK_API_KEY"] = "dummy_key_for_testing"
import sys
sys.path.append(os.getcwd())
from src.agent_app import predict_student
# 注意: 我们直接测试工具函数,而不是完整的 agent 循环
# 因为 agent 需要 API key而 CI/测试环境中可能未设置。
from unittest.mock import patch
def test_tool_wrapper():
# 测试 Agent wrapper 函数是否能正确调用到底层 infer
# 我们 mock 底层的 predict_pass_prob这样测试就不依赖于实际的模型文件是否存在
with patch("src.agent_app.predict_pass_prob") as mock_predict:
mock_predict.return_value = 0.85
prob = predict_student(None, 12, 8, 0.9, 2, "Self")
# 验证调用
assert prob == 0.85
mock_predict.assert_called_once_with(12, 8, 0.9, 2, "Self")