-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
33 lines (28 loc) · 1.2 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import unittest
from main import ChatSessionManager, chain
class TestPsychotherapistChatBot(unittest.TestCase):
def setUp(self):
self.chat_manager = ChatSessionManager()
self.chain = chain
def test_emotion_recognition(self):
inputs = [
("I feel very sad today", "Sorry to hear that"),
("I am really angry right now", "Can I help you manage your anger?")
]
for inp, expected in inputs:
with self.subTest(input=inp):
self.chat_manager.add_message(inp, "user")
response = self.chain.run(text=inp)
self.assertIn(expected, response)
def test_history_management(self):
self.chat_manager.add_message("Hello", "user")
self.chat_manager.add_message("How can I help you?", "assistant")
self.assertEqual(len(self.chat_manager.history), 2)
def test_input_handling(self):
inputs = ["", " ", "!@#$%^&*()"]
for inp in inputs:
with self.subTest(input=inp):
response = self.chain.run(text=inp)
self.assertNotEqual(response, None)
if __name__ == '__main__':
unittest.main()