11from unittest .mock import MagicMock , patch
22
3+ import pytest
4+
35from hier_config_gpt .clients .anthropic import ClaudeGPTClient
46from hier_config_gpt .clients .models import GPTPlanResponse
57from hier_config_gpt .clients .ollama import OllamaGPTClient
@@ -20,7 +22,7 @@ def test_init(self, mock_openai_class):
2022 assert client .temp == 0
2123
2224 # Check constructor was called
23- mock_openai_class .assert_called_once_with (api_key = "test-key" )
25+ mock_openai_class .assert_called_once_with (api_key = "test-key" , timeout = 60.0 )
2426
2527 @patch ("hier_config_gpt.clients.openai.OpenAI" )
2628 def test_chat (self , mock_openai_class ):
@@ -56,7 +58,7 @@ def test_chat(self, mock_openai_class):
5658
5759 # Verify mock was called with correct parameters
5860 mock_completions .create .assert_called_once_with (
59- model = "gpt-4 " ,
61+ model = "gpt-4o " ,
6062 messages = [{"role" : "user" , "content" : "Test prompt" }],
6163 max_tokens = 1000 ,
6264 temperature = 0 ,
@@ -96,7 +98,7 @@ def test_generate_plan(self, mock_openai_class):
9698
9799 # Verify mock was called with correct parameters
98100 mock_completions .create .assert_called_once_with (
99- model = "gpt-4 " ,
101+ model = "gpt-4o " ,
100102 messages = [{"role" : "user" , "content" : "Test prompt" }],
101103 max_tokens = 1000 ,
102104 temperature = 0 ,
@@ -145,7 +147,7 @@ def test_init(self, mock_anthropic_class):
145147 assert client .temp == 0
146148
147149 # Check constructor was called
148- mock_anthropic_class .assert_called_once_with (api_key = "test-key" )
150+ mock_anthropic_class .assert_called_once_with (api_key = "test-key" , timeout = 60.0 )
149151
150152 @patch ("hier_config_gpt.clients.anthropic.Anthropic" )
151153 def test_chat (self , mock_anthropic_class ):
@@ -176,7 +178,7 @@ def test_chat(self, mock_anthropic_class):
176178
177179 # Verify mock was called with correct parameters
178180 mock_messages .create .assert_called_once_with (
179- model = "claude-3-opus-20240229 " ,
181+ model = "claude-3-5-sonnet-20241022 " ,
180182 messages = [{"role" : "user" , "content" : "Test prompt" }],
181183 max_tokens = 1024 ,
182184 temperature = 0 ,
@@ -211,7 +213,7 @@ def test_generate_plan(self, mock_anthropic_class):
211213
212214 # Verify mock was called with correct parameters
213215 mock_messages .create .assert_called_once_with (
214- model = "claude-3-opus-20240229 " ,
216+ model = "claude-3-5-sonnet-20241022 " ,
215217 messages = [{"role" : "user" , "content" : "Test prompt" }],
216218 max_tokens = 1024 ,
217219 temperature = 0 ,
@@ -248,7 +250,9 @@ def test_init(self, mock_ollama):
248250 assert client .temp == 0
249251
250252 # Check client was created correctly
251- mock_ollama .Client .assert_called_once_with (host = "http://localhost:12345" )
253+ mock_ollama .Client .assert_called_once_with (
254+ host = "http://localhost:12345" , timeout = 60.0
255+ )
252256
253257 @patch ("hier_config_gpt.clients.ollama.ollama" )
254258 def test_chat (self , mock_ollama ):
@@ -271,9 +275,9 @@ def test_chat(self, mock_ollama):
271275
272276 # Verify mock was called with correct parameters
273277 mock_client .chat .assert_called_once_with (
274- model = "llama3" ,
278+ model = "llama3.2 " ,
275279 messages = [{"role" : "user" , "content" : "Test prompt" }],
276- options = {"num_predict" : 1024 , "temperature" : 0 },
280+ options = {"num_predict" : 1024 , "temperature" : 0.0 },
277281 )
278282
279283 @patch ("hier_config_gpt.clients.ollama.ollama" )
@@ -299,9 +303,9 @@ def test_generate_plan(self, mock_ollama):
299303
300304 # Verify mock was called with correct parameters
301305 mock_client .chat .assert_called_once_with (
302- model = "llama3" ,
306+ model = "llama3.2 " ,
303307 messages = [{"role" : "user" , "content" : "Test prompt" }],
304- options = {"num_predict" : 1024 , "temperature" : 0 },
308+ options = {"num_predict" : 1024 , "temperature" : 0.0 },
305309 )
306310
307311 def test_process_response (self ):
@@ -344,10 +348,7 @@ def test_generate_plan_exception_handling(self, mock_ollama):
344348
345349 mock_ollama .Client .return_value = mock_client
346350
347- # Create client and call method
351+ # Create client and verify exception is raised after retries
348352 client = OllamaGPTClient ()
349- result = client .generate_plan ("Test prompt" )
350-
351- # Verify expectations
352- assert len (result .plan ) == 1
353- assert "Error generating plan: Connection error" in result .plan [0 ]
353+ with pytest .raises (Exception , match = "Connection error" ):
354+ client .generate_plan ("Test prompt" )
0 commit comments