35 lines
993 B
Python
35 lines
993 B
Python
import unittest
|
|
from unittest.mock import AsyncMock
|
|
|
|
from rag.intent import Intent, intent_recognize
|
|
|
|
|
|
class IntentTests(unittest.IsolatedAsyncioTestCase):
|
|
async def test_returns_a_declared_intent_enum(self):
|
|
llm = AsyncMock()
|
|
llm.chat.return_value = "knowledge_qa"
|
|
|
|
result = await intent_recognize("基金是什么", llm_client=llm)
|
|
|
|
self.assertIs(result, Intent.KNOWLEDGE_QA)
|
|
|
|
async def test_invalid_llm_output_returns_no_match(self):
|
|
llm = AsyncMock()
|
|
llm.chat.return_value = "made_up_intent"
|
|
|
|
result = await intent_recognize("随便聊聊", llm_client=llm)
|
|
|
|
self.assertIs(result, Intent.NO_MATCH)
|
|
|
|
async def test_llm_failure_returns_no_match_for_handoff(self):
|
|
llm = AsyncMock()
|
|
llm.chat.side_effect = RuntimeError("LLM down")
|
|
|
|
result = await intent_recognize("我要投诉", llm_client=llm)
|
|
|
|
self.assertIs(result, Intent.NO_MATCH)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|