diff --git a/tests/python/test_antares_driver.py b/tests/python/test_antares_driver.py index 8f3c8faef..d3ebe4aac 100644 --- a/tests/python/test_antares_driver.py +++ b/tests/python/test_antares_driver.py @@ -2,18 +2,18 @@ import os from pathlib import Path from unittest.mock import patch -import pytest -from packaging import version +import pytest +from antares_xpansion.__version__ import __antares_simulator_version__ from antares_xpansion.antares_driver import AntaresDriver from antares_xpansion.general_data_processor import ( GeneralDataFileExceptions, GeneralDataProcessor, ) -from antares_xpansion.general_data_reader import IniReader, GeneralDataIniReader +from antares_xpansion.general_data_reader import GeneralDataIniReader, IniReader +from packaging import version from tests.build_config_reader import get_antares_solver_path -from antares_xpansion.__version__ import __antares_simulator_version__ SUBPROCESS_RUN = "antares_xpansion.antares_driver.subprocess.run" @@ -111,7 +111,6 @@ def test_values_change_in_general_file_accurate_mode(self, tmp_path): "key2 = value2\n" "[input]\n" "import = blabla\n" - ) gen_data_path.write_text(default_val) @@ -209,15 +208,16 @@ def test_values_change_in_general_file_fast_mode(self, tmp_path): ) def verify_that_general_data_contains_expected_vals( - self, general_data_ini_file, expected_val + self, general_data_ini_file, expected_val ): actual_config = configparser.ConfigParser() actual_config.read(general_data_ini_file) - for (section, key) in expected_val: + for section, key in expected_val: value = actual_config.get(section, key, fallback=None) assert value is not None print( - f"Section {section}, key {key}, value {value}, expected {expected_val[(section, key)]}") + f"Section {section}, key {key}, value {value}, expected {expected_val[(section, key)]}" + ) assert value == expected_val[(section, key)] with open(general_data_ini_file, "r") as reader: @@ -250,9 +250,15 @@ def test_antares_cmd(self, tmp_path): # mock subprocess.run with patch(SUBPROCESS_RUN, autospec=True) as run_function: antares_driver.launch(study_dir, 1) - expected_cmd = [exe_path, study_dir, "--force-parallel", "1", "-z", "--use-ortools", - "--ortools-solver=sirius"] - if (self.nammed_problems): + expected_cmd = [ + exe_path, + study_dir, + "--force-parallel", + "1", + "-z", + "--solver=sirius", + ] + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( @@ -267,9 +273,15 @@ def test_antares_cmd_force_parallel_option(self, tmp_path): with patch(SUBPROCESS_RUN, autospec=True) as run_function: antares_driver.launch(study_dir, n_cpu) - expected_cmd = [exe_path, study_dir, - "--force-parallel", str(n_cpu), "-z", "--use-ortools", "--ortools-solver=sirius"] - if (self.nammed_problems): + expected_cmd = [ + exe_path, + study_dir, + "--force-parallel", + str(n_cpu), + "-z", + "--solver=sirius", + ] + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( expected_cmd, shell=False, stdout=-3, stderr=-3 @@ -288,9 +300,10 @@ def test_invalid_n_cpu(self, tmp_path): study_dir, "--force-parallel", str(expected_n_cpu), - "-z", "--use-ortools", "--ortools-solver=sirius" + "-z", + "--solver=sirius", ] - if (self.nammed_problems): + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( expected_cmd, shell=False, stdout=-3, stderr=-3 @@ -305,9 +318,15 @@ def test_remove_log_file(self, tmp_path): antares_driver = AntaresDriver(exe_path) with patch(SUBPROCESS_RUN, autospec=True) as run_function: antares_driver.launch(study_dir, n_cpu) - expected_cmd = [str(exe_path), study_dir, - "--force-parallel", str(n_cpu), "-z", "--use-ortools", "--ortools-solver=sirius"] - if (self.nammed_problems): + expected_cmd = [ + str(exe_path), + study_dir, + "--force-parallel", + str(n_cpu), + "-z", + "--solver=sirius", + ] + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( expected_cmd, shell=False, stdout=-3, stderr=-3 @@ -368,9 +387,15 @@ def test_preserve_adequacy_option_after_run(self, tmp_path): antares_driver = AntaresDriver(exe_path) with patch(SUBPROCESS_RUN, autospec=True) as run_function: antares_driver.launch(study_dir, n_cpu) - expected_cmd = [str(exe_path), study_dir, - "--force-parallel", str(n_cpu), "-z", "--use-ortools", "--ortools-solver=sirius"] - if (self.nammed_problems): + expected_cmd = [ + str(exe_path), + study_dir, + "--force-parallel", + str(n_cpu), + "-z", + "--solver=sirius", + ] + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( expected_cmd, shell=False, stdout=-3, stderr=-3 @@ -380,8 +405,7 @@ def test_preserve_adequacy_option_after_run(self, tmp_path): config_reader.read(gen_data_path) assert config_reader.getboolean("adequacy patch", "dummy") is False assert config_reader.get("adequacy patch", "foo") == "bar" - assert config_reader.getboolean( - "adequacy patch", "include-adq-patch") is True + assert config_reader.getboolean("adequacy patch", "include-adq-patch") is True def test_preserve_general_file_section_missing(self, tmp_path): settings_dir = TestGeneralDataProcessor.get_settings_dir(tmp_path) @@ -394,9 +418,15 @@ def test_preserve_general_file_section_missing(self, tmp_path): antares_driver = AntaresDriver(exe_path) with patch(SUBPROCESS_RUN, autospec=True) as run_function: antares_driver.launch(study_dir, n_cpu) - expected_cmd = [str(exe_path), study_dir, - "--force-parallel", str(n_cpu), "-z", "--use-ortools", "--ortools-solver=sirius"] - if (self.nammed_problems): + expected_cmd = [ + str(exe_path), + study_dir, + "--force-parallel", + str(n_cpu), + "-z", + "--solver=sirius", + ] + if self.nammed_problems: expected_cmd.append("--named-mps-problems") run_function.assert_called_once_with( expected_cmd, shell=False, stdout=-3, stderr=-3