16
16
from subprocess import SubprocessError
17
17
from unittest .mock import MagicMock , mock_open , patch
18
18
19
- import pytest
20
-
21
19
from ardupilot_methodic_configurator .annotate_params import Par
22
20
from ardupilot_methodic_configurator .backend_filesystem import LocalFilesystem , is_within_tolerance
23
21
@@ -1082,13 +1080,13 @@ def test_user_can_skip_copying_vehicle_image_from_template(
1082
1080
@patch ("ardupilot_methodic_configurator.backend_filesystem.os_path.join" )
1083
1081
@patch ("ardupilot_methodic_configurator.backend_filesystem.shutil_copy2" )
1084
1082
@patch ("ardupilot_methodic_configurator.backend_filesystem.os_path.isdir" )
1085
- def test_copy_vehicle_image_defaults_to_false (self , mock_isdir , mock_copy2 , mock_join , mock_listdir , mock_exists ) -> None : # pylint: disable=unused-argument
1083
+ def test_copy_vehicle_image_defaults_to_false (self , mock_isdir , mock_copy2 , mock_join , mock_listdir , mock_exists ) -> None :
1086
1084
"""
1087
1085
Vehicle image copying defaults to disabled.
1088
1086
1089
1087
GIVEN: A template directory containing a vehicle.jpg file
1090
- WHEN: The user creates a new vehicle without specifying copy_vehicle_image parameter
1091
- THEN: The vehicle.jpg file should not be copied by default
1088
+ WHEN: The user creates a new vehicle with copy_vehicle_image=False
1089
+ THEN: The vehicle.jpg file should not be copied
1092
1090
"""
1093
1091
# Arrange: Set up template directory with vehicle.jpg
1094
1092
mock_exists .side_effect = lambda path : path in ["template_dir" , "new_vehicle_dir" ]
@@ -1100,12 +1098,21 @@ def test_copy_vehicle_image_defaults_to_false(self, mock_isdir, mock_copy2, mock
1100
1098
"vehicle_dir" , "vehicle_type" , "" , allow_editing_template_files = False , save_component_to_system_templates = False
1101
1099
)
1102
1100
1103
- # Act: Copy template files without specifying copy_vehicle_image
1104
- # (this should cause an error since parameter is required)
1105
- with pytest .raises (TypeError ):
1106
- lfs .copy_template_files_to_new_vehicle_dir (
1107
- "template_dir" , "new_vehicle_dir" , blank_change_reason = False , copy_vehicle_image = False
1108
- )
1101
+ # Act: Copy template files with copy_vehicle_image=False
1102
+ result = lfs .copy_template_files_to_new_vehicle_dir (
1103
+ "template_dir" , "new_vehicle_dir" , blank_change_reason = False , copy_vehicle_image = False
1104
+ )
1105
+
1106
+ # Assert: No error and vehicle image should not be copied
1107
+ assert result == "" # No error
1108
+
1109
+ # Verify vehicle.jpg was NOT copied
1110
+ copy_calls = [call .args for call in mock_copy2 .call_args_list ]
1111
+ vehicle_jpg_calls = [call for call in copy_calls if "vehicle.jpg" in str (call )]
1112
+ assert len (vehicle_jpg_calls ) == 0 , "vehicle.jpg should not be copied when copy_vehicle_image=False"
1113
+
1114
+ # Verify other files were copied
1115
+ mock_copy2 .assert_any_call ("template_dir/config.param" , "new_vehicle_dir/config.param" )
1109
1116
1110
1117
@patch ("ardupilot_methodic_configurator.backend_filesystem.os_path.exists" )
1111
1118
@patch ("ardupilot_methodic_configurator.backend_filesystem.os_listdir" )
@@ -1129,7 +1136,7 @@ def test_copy_vehicle_image_with_no_image_file_present(
1129
1136
mock_isdir .return_value = False
1130
1137
1131
1138
lfs = LocalFilesystem (
1132
- "vehicle_dir" , "vehicle_type" , None , allow_editing_template_files = False , save_component_to_system_templates = False
1139
+ "vehicle_dir" , "vehicle_type" , "" , allow_editing_template_files = False , save_component_to_system_templates = False
1133
1140
)
1134
1141
1135
1142
# Act: Copy template files with copy_vehicle_image=True (but no vehicle.jpg exists)
@@ -1146,7 +1153,7 @@ def test_copy_vehicle_image_with_no_image_file_present(
1146
1153
def test_merge_forced_or_derived_parameters_comprehensive () -> None :
1147
1154
"""Test merge_forced_or_derived_parameters with various scenarios."""
1148
1155
lfs = LocalFilesystem (
1149
- "vehicle_dir" , "vehicle_type" , None , allow_editing_template_files = False , save_component_to_system_templates = False
1156
+ "vehicle_dir" , "vehicle_type" , "" , allow_editing_template_files = False , save_component_to_system_templates = False
1150
1157
)
1151
1158
test_file = "test_file"
1152
1159
@@ -1214,7 +1221,7 @@ def test_merge_forced_or_derived_parameters_comprehensive() -> None:
1214
1221
def test_merge_forced_or_derived_parameters_none_parameters () -> None :
1215
1222
"""Test merge_forced_or_derived_parameters handles None parameters."""
1216
1223
lfs = LocalFilesystem (
1217
- "vehicle_dir" , "vehicle_type" , None , allow_editing_template_files = False , save_component_to_system_templates = False
1224
+ "vehicle_dir" , "vehicle_type" , "" , allow_editing_template_files = False , save_component_to_system_templates = False
1218
1225
)
1219
1226
test_file = "test.json"
1220
1227
lfs .file_parameters = {test_file : {}} # Test with empty dict instead of None (None is not valid type)
0 commit comments