11import os
22import subprocess
3+ from pathlib import Path
34from unittest .mock import MagicMock , patch
45
56import pytest
@@ -46,7 +47,7 @@ class TestLlamaCppCLI:
4647
4748 def test_chat_with_llamacpp_success (self , mock_resolve_model_path , mock_subprocess ):
4849 """Test successful CLI chat with llama.cpp."""
49- model_path = f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf'
50+ model_path = str ( Path ( f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf' ))
5051 mock_resolve_model_path .return_value = model_path
5152
5253 mock_result = MagicMock ()
@@ -61,7 +62,7 @@ def test_chat_with_llamacpp_success(self, mock_resolve_model_path, mock_subproce
6162 # Verify correct CLI command structure
6263 args , kwargs = mock_subprocess .call_args
6364 cmd = args [0 ]
64- assert '/data1/llama.cpp/bin/llama-cli' in cmd
65+ assert str ( Path ( '/data1/llama.cpp/bin/llama-cli' )) in cmd
6566 assert '-m' in cmd and model_path in cmd
6667 assert '--n-gpu-layers' in cmd and '40' in cmd
6768 assert '--single-turn' in cmd
@@ -75,7 +76,9 @@ def test_chat_with_llamacpp_model_not_found(self, mock_resolve_model_path):
7576
7677 def test_chat_with_llamacpp_subprocess_error (self , mock_resolve_model_path , mock_subprocess ):
7778 """Test CLI chat when subprocess fails."""
78- mock_resolve_model_path .return_value = f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf'
79+ mock_resolve_model_path .return_value = str (
80+ Path (f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf' )
81+ )
7982
8083 error = subprocess .CalledProcessError (1 , 'cmd' )
8184 error .stderr = b'CUDA out of memory'
@@ -91,9 +94,11 @@ class TestCLIModeRouting:
9194 @pytest .fixture (autouse = True )
9295 def setup_routing_mocks (self ):
9396 """Set up common mocks for routing tests."""
94- with patch ('markus_ai_server.server.chat_with_llamacpp' ) as mock_chat_llamacpp , patch (
95- 'markus_ai_server.server.is_llamacpp_available'
96- ) as mock_available , patch ('markus_ai_server.server.chat_with_ollama' ) as mock_chat_ollama :
97+ with (
98+ patch ('markus_ai_server.server.chat_with_llamacpp' ) as mock_chat_llamacpp ,
99+ patch ('markus_ai_server.server.is_llamacpp_available' ) as mock_available ,
100+ patch ('markus_ai_server.server.chat_with_ollama' ) as mock_chat_ollama ,
101+ ):
97102 self .mock_chat_llamacpp = mock_chat_llamacpp
98103 self .mock_available = mock_available
99104 self .mock_chat_ollama = mock_chat_ollama
@@ -177,7 +182,7 @@ class TestCLIModeIntegration:
177182
178183 def test_complete_cli_flow_with_real_model (self , mock_glob , mock_subprocess ):
179184 """Test complete CLI flow: model resolution → CLI execution."""
180- model_path = f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf'
185+ model_path = str ( Path ( f'/data1/GGUF/{ TEST_LLAMACPP_MODEL } /{ TEST_LLAMACPP_MODEL } .gguf' ))
181186
182187 mock_glob .return_value = [model_path ]
183188 mock_result = MagicMock ()
@@ -204,7 +209,7 @@ def test_complete_cli_fallback_flow_to_ollama(self, mock_glob, mock_ollama):
204209 result = chat_with_model (TEST_OLLAMA_MODEL , 'Fallback test' , llama_mode = 'cli' )
205210
206211 assert result == "Ollama CLI fallback integration test successful!"
207- mock_glob .assert_called_once_with (f'/data1/GGUF/{ TEST_OLLAMA_MODEL } /*.gguf' )
212+ mock_glob .assert_called_once_with (str ( Path ( f'/data1/GGUF/{ TEST_OLLAMA_MODEL } /*.gguf' )) )
208213 mock_ollama .assert_called_once ()
209214
210215 def test_cli_mode_passes_json_schema_to_ollama (self , tmp_path ):
@@ -215,9 +220,10 @@ def test_cli_mode_passes_json_schema_to_ollama(self, tmp_path):
215220 test_schema = {"schema" : {"type" : "object" , "properties" : {"answer" : {"type" : "string" }}}}
216221
217222 # Prepare mocks
218- with patch ('markus_ai_server.server.is_llamacpp_available' , return_value = False ), patch (
219- 'markus_ai_server.server.chat_with_ollama'
220- ) as mock_ollama :
223+ with (
224+ patch ('markus_ai_server.server.is_llamacpp_available' , return_value = False ),
225+ patch ('markus_ai_server.server.chat_with_ollama' ) as mock_ollama ,
226+ ):
221227 mock_ollama .return_value = "schema-aware response"
222228
223229 result = chat_with_model (TEST_OLLAMA_MODEL , "Give me an answer" , llama_mode = 'cli' , json_schema = test_schema )
0 commit comments