From b4f25c2c95cf71fd24d9127abe94f1b52453da7d Mon Sep 17 00:00:00 2001 From: Florian OMNES Date: Mon, 16 Dec 2024 10:31:02 +0100 Subject: [PATCH 1/4] Try to fix dummy-3areas-3candidates-3links example --- .../dummy-3areas-3candidates-3links/settings/generaldata.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/data_test/examples/dummy-3areas-3candidates-3links/settings/generaldata.ini b/data_test/examples/dummy-3areas-3candidates-3links/settings/generaldata.ini index 03ea230ed..a82676dbf 100644 --- a/data_test/examples/dummy-3areas-3candidates-3links/settings/generaldata.ini +++ b/data_test/examples/dummy-3areas-3candidates-3links/settings/generaldata.ini @@ -90,3 +90,5 @@ seed-thermal-costs = 8005489 seed-hydro-costs = 9005489 seed-initial-reservoir-levels = 10005489 +[compatibility] +hydro-pmax = hourly \ No newline at end of file From cc5f8e0bb5603cfee160795b512528ddd7dbde96 Mon Sep 17 00:00:00 2001 From: Thomas Bittar Date: Mon, 16 Dec 2024 11:09:00 +0100 Subject: [PATCH 2/4] Fix test --- tests/end_to_end/cucumber/features/steps/steps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/end_to_end/cucumber/features/steps/steps.py b/tests/end_to_end/cucumber/features/steps/steps.py index c54f9d671..13180d379 100644 --- a/tests/end_to_end/cucumber/features/steps/steps.py +++ b/tests/end_to_end/cucumber/features/steps/steps.py @@ -239,7 +239,7 @@ def get_results_file_path_from_logs(logs: bytes) -> str: @then('Simulator has been launched with solver "{string}"') def check_simulator_solver(context, string): - string_to_find = f"ortools solver {string} used for problem resolution" + string_to_find = f"solver {string} used for problem resolution" assert(find_in_simulator_log(context.tmp_study / "output", string_to_find)) @then('Benders has been launched with solver "{string}"') From ccac65d06a3a59f548d03553d8157530da18b7c3 Mon Sep 17 00:00:00 2001 From: Thomas Bittar Date: Mon, 16 Dec 2024 13:05:16 +0100 Subject: [PATCH 3/4] Fix test --- tests/end_to_end/cucumber/features/steps/steps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/end_to_end/cucumber/features/steps/steps.py b/tests/end_to_end/cucumber/features/steps/steps.py index 13180d379..96b701a9d 100644 --- a/tests/end_to_end/cucumber/features/steps/steps.py +++ b/tests/end_to_end/cucumber/features/steps/steps.py @@ -239,7 +239,7 @@ def get_results_file_path_from_logs(logs: bytes) -> str: @then('Simulator has been launched with solver "{string}"') def check_simulator_solver(context, string): - string_to_find = f"solver {string} used for problem resolution" + string_to_find = f"solver {string} is used for problem resolution" assert(find_in_simulator_log(context.tmp_study / "output", string_to_find)) @then('Benders has been launched with solver "{string}"') From b54256bb90e97805057926378402d43439fde1c8 Mon Sep 17 00:00:00 2001 From: Thomas Bittar Date: Mon, 16 Dec 2024 13:23:51 +0100 Subject: [PATCH 4/4] Fix antares driver tests --- tests/python/test_antares_driver.py | 84 +++++++++++++++++++---------- 1 file changed, 57 insertions(+), 27 deletions(-) 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