@@ -178,6 +178,25 @@ def test_check_is_skipped_for_o2m(self, mock_sort: MagicMock) -> None:
178178 assert "strategy" not in import_plan
179179 mock_sort .assert_not_called ()
180180
181+ @patch ("odoo_data_flow.lib.preflight.sort.sort_for_self_referencing" )
182+ def test_check_handles_sort_function_error (self , mock_sort : MagicMock ) -> None :
183+ """Verify the check handles errors from sort_for_self_referencing gracefully."""
184+ # Mock sort function to return False indicating an error
185+ mock_sort .return_value = False
186+ import_plan : dict [str , Any ] = {}
187+
188+ result = preflight .self_referencing_check (
189+ preflight_mode = PreflightMode .NORMAL ,
190+ filename = "file.csv" ,
191+ import_plan = import_plan ,
192+ )
193+
194+ # Should return False when sort function encounters an error
195+ assert result is False
196+ # Should not modify import plan when there's an error
197+ assert "strategy" not in import_plan
198+ mock_sort .assert_called_once ()
199+
181200
182201class TestInternalHelpers :
183202 """Tests for internal helper functions in the preflight module."""
@@ -311,6 +330,28 @@ def test_missing_languages_user_confirms_install_success(
311330 mock_confirm .assert_called_once ()
312331 mock_installer .assert_called_once_with ("" , ["fr_FR" ])
313332
333+ @patch ("odoo_data_flow.lib.preflight._get_installed_languages" , return_value = None )
334+ def test_language_check_handles_get_installed_languages_failure (
335+ self , mock_get_langs : MagicMock , mock_polars_read_csv : MagicMock
336+ ) -> None :
337+ """Tests that language_check handles when _get_installed_languages fails."""
338+ # Setup CSV data with languages that would require checking
339+ (
340+ mock_polars_read_csv .return_value .get_column .return_value .unique .return_value .drop_nulls .return_value .to_list .return_value
341+ ) = ["fr_FR" ]
342+
343+ result = preflight .language_check (
344+ preflight_mode = PreflightMode .NORMAL ,
345+ model = "res.partner" ,
346+ filename = "file.csv" ,
347+ config = "" ,
348+ headless = False ,
349+ )
350+
351+ # Should return False when _get_installed_languages fails
352+ assert result is False
353+ mock_get_langs .assert_called_once_with ("" )
354+
314355 @patch ("odoo_data_flow.lib.preflight.Confirm.ask" , return_value = True )
315356 @patch (
316357 "odoo_data_flow.lib.actions.language_installer.run_language_installation" ,
@@ -944,7 +985,7 @@ def test_type_correction_check_odoo_error_handling(tmp_path: Path) -> None:
944985def test_type_correction_check_empty_file (tmp_path : Path ) -> None :
945986 """Test type correction check handles empty file gracefully."""
946987 csv_file = tmp_path / "empty.csv"
947- with open (csv_file , "w" , newline = "" , encoding = "utf-8" ) as f :
988+ with open (csv_file , "w" , newline = "" , encoding = "utf-8" ):
948989 pass # Create empty file
949990
950991 config = {"test" : "config" }
@@ -1114,7 +1155,8 @@ def test_type_correction_check_main_exception_handler(tmp_path: Path) -> None:
11141155 "price" : {"type" : "integer" },
11151156 }
11161157
1117- # Mock polars.read_csv to raise an exception to trigger the main exception handler
1158+ # Mock polars.read_csv to raise an exception to trigger the main
1159+ # exception handler
11181160 with patch ("odoo_data_flow.lib.preflight.pl.read_csv" ) as mock_read_csv :
11191161 mock_read_csv .side_effect = Exception ("Simulated Polars read error" )
11201162
@@ -1181,7 +1223,8 @@ def test_type_correction_check_casting_exception_handler(tmp_path: Path) -> None
11811223
11821224 # Should still return True even when casting raises exception
11831225 assert result is True
1184- # Should still proceed and may or may not create corrected file depending on flow
1226+ # Should still proceed and may or may not create corrected file depending
1227+ # on flow
11851228 # Mock _get_odoo_fields to return integer fields to trigger correction logic
11861229 with patch ("odoo_data_flow.lib.preflight._get_odoo_fields" ) as mock_get_fields :
11871230 mock_get_fields .return_value = {
@@ -1211,4 +1254,5 @@ def test_type_correction_check_casting_exception_handler(tmp_path: Path) -> None
12111254
12121255 # Should still return True even when casting raises exception
12131256 assert result is True
1214- # Should still proceed and may or may not create corrected file depending on flow
1257+ # Should still proceed and may or may not create corrected file depending
1258+ # on flow
0 commit comments