@@ -110,15 +110,43 @@ def test_rename_parameter_files(self) -> None:
110110 expected_new = os_path .join ("/mock/dir" , "new_file.param" )
111111 mock_rename .assert_called_once_with (expected_old , expected_new )
112112
113- def test_vehicle_configuration_file_exists (self ) -> None :
114- """Test checking if a specific configuration file exists."""
113+ def test_vehicle_configuration_file_exists_comprehensive (self ) -> None :
114+ """Test checking if a specific configuration file exists with comprehensive path and size checks ."""
115115 mock_vehicle_dir = "/mock/dir"
116- filesystem = LocalFilesystem (mock_vehicle_dir , "ArduCopter" , "4.3.0" , False ) # noqa: FBT003
116+ filesystem = LocalFilesystem (mock_vehicle_dir , "ArduCopter" , "4.3.0" , allow_editing_template_files = False )
117117
118- with patch ("os.path.exists" , return_value = True ), patch ("os.path.isfile" , return_value = True ):
118+ # Test with all conditions met (file exists, is a file, and has size > 0)
119+ with (
120+ patch ("os.path.exists" , return_value = True ) as mock_exists ,
121+ patch ("os.path.isfile" , return_value = True ) as mock_isfile ,
122+ patch ("os.path.getsize" , return_value = 100 ) as mock_getsize ,
123+ patch ("os.path.join" , side_effect = os_path .join ) as mock_join ,
124+ ):
119125 assert filesystem .vehicle_configuration_file_exists ("test.param" )
126+ mock_exists .assert_called_once ()
127+ mock_isfile .assert_called_once ()
128+ mock_getsize .assert_called_once ()
129+ mock_join .assert_called_once_with (mock_vehicle_dir , "test.param" )
130+
131+ # Test with file that exists but is empty
132+ with (
133+ patch ("os.path.exists" , return_value = True ),
134+ patch ("os.path.isfile" , return_value = True ),
135+ patch ("os.path.getsize" , return_value = 0 ),
136+ patch ("os.path.join" , side_effect = os_path .join ),
137+ ):
138+ assert not filesystem .vehicle_configuration_file_exists ("empty.param" )
139+
140+ # Test with directory instead of file
141+ with (
142+ patch ("os.path.exists" , return_value = True ),
143+ patch ("os.path.isfile" , return_value = False ),
144+ patch ("os.path.join" , side_effect = os_path .join ),
145+ ):
146+ assert not filesystem .vehicle_configuration_file_exists ("dir.param" )
120147
121- with patch ("os.path.exists" , return_value = False ):
148+ # Test with nonexistent file
149+ with patch ("os.path.exists" , return_value = False ), patch ("os.path.join" , side_effect = os_path .join ):
122150 assert not filesystem .vehicle_configuration_file_exists ("nonexistent.param" )
123151
124152 @patch ("os.path.exists" )
0 commit comments