@@ -160,9 +160,10 @@ def test_save_component_templates_to_file_os_error(self, mock_get_base_dir, mock
160160 @patch ("ardupilot_methodic_configurator.backend_filesystem_vehicle_components.os_path.exists" )
161161 @patch ("builtins.open" , new_callable = mock_open )
162162 @patch ("ardupilot_methodic_configurator.backend_filesystem_vehicle_components.os_makedirs" )
163+ @patch ("ardupilot_methodic_configurator.backend_filesystem_vehicle_components.safe_write" )
163164 @patch ("ardupilot_methodic_configurator.backend_filesystem_program_settings.ProgramSettings.get_templates_base_dir" )
164- def test_save_component_templates_to_file_uses_local_dir_when_local_file_exists (
165- self , mock_get_base_dir , mock_makedirs , mock_file , mock_exists
165+ def test_save_component_templates_to_file_uses_local_dir_when_local_file_exists ( # pylint: disable=too-many-arguments,too-many-positional-arguments
166+ self , mock_get_base_dir , mock_safe_write , mock_makedirs , mock_file , mock_exists
166167 ) -> None :
167168 """
168169 Test that system templates use local directory when local file exists.
@@ -174,15 +175,17 @@ def test_save_component_templates_to_file_uses_local_dir_when_local_file_exists(
174175 mock_get_base_dir .return_value = "/system/templates"
175176 mock_makedirs .return_value = None
176177 mock_exists .return_value = True # Local file exists
178+ mock_safe_write .return_value = None
177179
178180 vehicle_components_system = VehicleComponents (save_component_to_system_templates = True )
179181 templates_to_save = {"Component1" : [{"name" : "Test" , "data" : {}}]}
180182
181183 error , msg = vehicle_components_system .save_component_templates_to_file (templates_to_save )
182184
183185 assert error is False
184- # Should use local dir, which contains "ardupilot_methodic_configurator/vehicle_templates"
185- assert "ardupilot_methodic_configurator/vehicle_templates/system_vehicle_components_template.json" in msg
186+ # Should use local dir, which contains system template filename (path may vary by environment)
187+ assert "system_vehicle_components_template.json" in msg
188+ assert "/system/templates" in msg or "ardupilot_methodic_configurator/vehicle_templates" in msg
186189
187190 @patch .object (VehicleComponents , "_load_system_templates" )
188191 @patch .object (VehicleComponents , "save_component_templates_to_file" )
0 commit comments