-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
41 lines (34 loc) · 1.48 KB
/
test_main.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
34
35
36
37
38
39
40
41
"""Unit tests for the main application module."""
import unittest
from unittest.mock import patch, MagicMock
import main
class TestMainApp(unittest.TestCase):
"""Test cases for the main application functionality."""
@patch('groq.Groq')
def test_generate_questions(self, mock_groq):
"""Test the generate_questions function with mocked Groq client."""
# Mock the Groq client response
mock_response = MagicMock()
mock_response.choices = [MagicMock(message=MagicMock(content="Test question"))]
mock_groq.return_value.chat.completions.create.return_value = mock_response
# Test the generate_questions function
result = main.generate_questions("test lesson")
self.assertEqual(result, "Test question")
# Verify Groq was called with correct parameters
expected_msg = [
{
"role": "system",
"content": "You are an enthusiastic, curious teacher assistant creating thought-provoking questions."
},
{
"role": "user",
"content": "Teacher: test lesson Can you create some engaging, "
"higher-order thinking questions related to this topic? Include interdisciplinary questions."
}
]
mock_groq.return_value.chat.completions.create.assert_called_with(
model="llama-3.1-8b-instant",
messages=expected_msg
)
if __name__ == '__main__':
unittest.main()