@@ -68,6 +68,9 @@ def _exists(p):
6868 # Allow access to the default config file
6969 if str (p ).endswith ("config/models.yaml" ):
7070 return True
71+ # Allow access to the default log directory
72+ if str (p ).endswith (".vec-inf-logs" ):
73+ return True
7174 # Use mock_exists for other paths
7275 return mock_exists (p )
7376
@@ -143,14 +146,27 @@ def test_paths():
143146def mock_truediv (test_paths ):
144147 """Fixture providing path joining mock."""
145148
146- def _mock_truediv (self , other ):
147- if str (self ) == str (test_paths ["weights_dir" ]) and other == "unknown-model" :
148- return test_paths ["unknown_model" ]
149- if str (self ) == str (test_paths ["log_dir" ]):
150- return test_paths ["log_dir" ] / other
151- if str (self ) == str (test_paths ["log_dir" ] / "model_family_placeholder" ):
152- return test_paths ["log_dir" ] / "model_family_placeholder" / other
153- return Path (str (self )) / str (other )
149+ def _mock_truediv (* args ):
150+ # Handle the case where it's called with just one argument
151+ if len (args ) == 1 :
152+ other = args [0 ]
153+ return test_paths .get (other , Path (str (other )))
154+
155+ # Normal case with self and other
156+ self , other = args
157+ specific_paths = {
158+ (str (test_paths ["weights_dir" ]), "unknown-model" ): test_paths [
159+ "unknown_model"
160+ ],
161+ (str (test_paths ["log_dir" ]), other ): test_paths ["log_dir" ] / other ,
162+ (
163+ str (test_paths ["log_dir" ] / "model_family_placeholder" ),
164+ other ,
165+ ): test_paths ["log_dir" ] / "model_family_placeholder" / other ,
166+ ("/home/user" , ".vec-inf-logs" ): test_paths ["log_dir" ],
167+ }
168+
169+ return specific_paths .get ((str (self ), other ), Path (str (self )) / str (other ))
154170
155171 return _mock_truediv
156172
@@ -201,12 +217,26 @@ def base_patches(test_paths, mock_truediv, debug_helper):
201217 "pathlib.Path.parent" , return_value = debug_helper .config_file .parent .parent
202218 ),
203219 patch ("pathlib.Path.__truediv__" , side_effect = mock_truediv ),
220+ patch ("pathlib.Path.iterdir" , return_value = []), # Mock empty directory listing
204221 patch ("json.dump" ),
205222 patch ("pathlib.Path.touch" ),
206223 patch ("vec_inf.cli._helper.Path" , return_value = test_paths ["weights_dir" ]),
224+ patch (
225+ "pathlib.Path.home" , return_value = Path ("/home/user" )
226+ ), # Mock home directory
207227 ]
208228
209229
230+ @pytest .fixture
231+ def apply_base_patches (base_patches ):
232+ """Fixture to apply all base patches."""
233+ with ExitStack () as stack :
234+ # Apply all patches
235+ for patch_obj in base_patches :
236+ stack .enter_context (patch_obj )
237+ yield
238+
239+
210240def test_launch_command_success (runner , mock_launch_output , path_exists , debug_helper ):
211241 """Test successful model launch with minimal required arguments."""
212242 test_log_dir = Path ("/tmp/test_vec_inf_logs" )
@@ -374,7 +404,7 @@ def test_list_single_model(runner):
374404
375405
376406def test_metrics_command_pending_server (
377- runner , mock_status_output , path_exists , debug_helper
407+ runner , mock_status_output , path_exists , debug_helper , apply_base_patches
378408):
379409 """Test metrics command when server is pending."""
380410 with (
@@ -398,7 +428,7 @@ def test_metrics_command_pending_server(
398428
399429
400430def test_metrics_command_server_not_ready (
401- runner , mock_status_output , path_exists , debug_helper
431+ runner , mock_status_output , path_exists , debug_helper , apply_base_patches
402432):
403433 """Test metrics command when server is running but not ready."""
404434 with (
@@ -420,7 +450,7 @@ def test_metrics_command_server_not_ready(
420450
421451@patch ("vec_inf.cli._helper.requests.get" )
422452def test_metrics_command_server_ready (
423- mock_get , runner , mock_status_output , path_exists , debug_helper
453+ mock_get , runner , mock_status_output , path_exists , debug_helper , apply_base_patches
424454):
425455 """Test metrics command when server is ready and returning metrics."""
426456 metrics_response = """
@@ -459,7 +489,7 @@ def test_metrics_command_server_ready(
459489
460490@patch ("vec_inf.cli._helper.requests.get" )
461491def test_metrics_command_request_failed (
462- mock_get , runner , mock_status_output , path_exists , debug_helper
492+ mock_get , runner , mock_status_output , path_exists , debug_helper , apply_base_patches
463493):
464494 """Test metrics command when request to metrics endpoint fails."""
465495 mock_get .side_effect = requests .exceptions .RequestException ("Connection refused" )
0 commit comments