Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "dummy" example #974

Merged
merged 4 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ seed-thermal-costs = 8005489
seed-hydro-costs = 9005489
seed-initial-reservoir-levels = 10005489

[compatibility]
hydro-pmax = hourly
2 changes: 1 addition & 1 deletion tests/end_to_end/cucumber/features/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} 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}"')
Expand Down
84 changes: 57 additions & 27 deletions tests/python/test_antares_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
Loading