diff --git a/antarest/study/storage/study_upgrader/upgrader_870.py b/antarest/study/storage/study_upgrader/upgrader_870.py index 5e0fd452f4..0ec1d9ccc9 100644 --- a/antarest/study/storage/study_upgrader/upgrader_870.py +++ b/antarest/study/storage/study_upgrader/upgrader_870.py @@ -33,10 +33,10 @@ def upgrade_870(study_path: Path) -> None: else: df = pandas.read_csv(file, sep="\t", header=None) lt, gt, eq = df.iloc[:, 0], df.iloc[:, 1], df.iloc[:, 2] - for term in [lt, gt, eq]: + for term, suffix in zip([lt, gt, eq], ["lt", "gt", "eq"]): # noinspection PyTypeChecker np.savetxt( - binding_constraints_path / f"{name}_{str(term)}.txt", + binding_constraints_path / f"{name}_{str(suffix)}.txt", cast(npt.NDArray[np.float64], term.values), delimiter="\t", fmt="%.6f", diff --git a/tests/storage/business/assets/little_study_700.zip b/tests/storage/business/assets/little_study_700.zip index 721a9b9f44..e9a34f5f49 100644 Binary files a/tests/storage/business/assets/little_study_700.zip and b/tests/storage/business/assets/little_study_700.zip differ diff --git a/tests/storage/business/test_study_version_upgrader.py b/tests/storage/business/test_study_version_upgrader.py index edeab34415..d1c4d2f659 100644 --- a/tests/storage/business/test_study_version_upgrader.py +++ b/tests/storage/business/test_study_version_upgrader.py @@ -28,12 +28,13 @@ def test_end_to_end_upgrades(tmp_path: Path): shutil.copytree(study_dir, before_upgrade_dir, dirs_exist_ok=True) old_values = get_old_settings_values(study_dir) old_areas_values = get_old_area_values(study_dir) + old_binding_constraint_values = get_old_binding_constraint_values(study_dir) # Only checks if the study_upgrader can go from the first supported version to the last one - target_version = "860" + target_version = "870" upgrade_study(study_dir, target_version) assert_study_antares_file_is_updated(study_dir, target_version) assert_settings_are_updated(study_dir, old_values) - assert_inputs_are_updated(study_dir, old_areas_values) + assert_inputs_are_updated(study_dir, old_areas_values, old_binding_constraint_values) assert not are_same_dir(study_dir, before_upgrade_dir) @@ -138,7 +139,17 @@ def get_old_area_values(tmp_path: Path) -> dict: return dico -def assert_inputs_are_updated(tmp_path: Path, dico: dict) -> None: +def get_old_binding_constraint_values(tmp_path: Path) -> dict: + dico = {} + bd_list = glob.glob(str(tmp_path / "input" / "bindingconstraints" / "*.txt")) + for txt_file in bd_list: + path_txt = Path(txt_file) + df = pandas.read_csv(path_txt, sep="\t", header=None) + dico[str(path_txt.stem)] = df + return dico + + +def assert_inputs_are_updated(tmp_path: Path, old_area_values: dict, old_binding_constraint_values: dict) -> None: input_path = tmp_path / "input" # tests 8.1 upgrade @@ -152,7 +163,7 @@ def assert_inputs_are_updated(tmp_path: Path, dico: dict) -> None: path_txt = Path(txt) old_txt = str(Path(path_txt.parent.name).joinpath(path_txt.stem)).replace("_parameters", "") df = pandas.read_csv(txt, sep="\t", header=None) - assert df.values.all() == dico[old_txt].iloc[:, 2:8].values.all() + assert df.values.all() == old_area_values[old_txt].iloc[:, 2:8].values.all() capacities = glob.glob(str(folder_path / "capacities" / "*")) for direction_txt in capacities: df_capacities = pandas.read_csv(direction_txt, sep="\t", header=None) @@ -160,10 +171,10 @@ def assert_inputs_are_updated(tmp_path: Path, dico: dict) -> None: old_txt = str(Path(direction_path.parent.parent.name).joinpath(direction_path.name)) if "indirect" in old_txt: new_txt = old_txt.replace("_indirect.txt", "") - assert df_capacities[0].values.all() == dico[new_txt].iloc[:, 0].values.all() + assert df_capacities[0].values.all() == old_area_values[new_txt].iloc[:, 0].values.all() else: new_txt = old_txt.replace("_direct.txt", "") - assert df_capacities[0].values.all() == dico[new_txt].iloc[:, 1].values.all() + assert df_capacities[0].values.all() == old_area_values[new_txt].iloc[:, 1].values.all() # tests 8.3 upgrade areas = glob.glob(str(tmp_path / "input" / "areas" / "*")) @@ -184,6 +195,28 @@ def assert_inputs_are_updated(tmp_path: Path, dico: dict) -> None: assert (st_storage_path / "list.ini").exists() assert input_path.joinpath("hydro", "series", area_id, "mingen.txt").exists() + # tests 8.7 upgrade + # binding constraint part + reader = MultipleSameKeysIniReader(DUPLICATE_KEYS) + data = reader.read(input_path / "bindingconstraints" / "bindingconstraints.ini") + binding_constraints_list = list(data.keys()) + for bd in binding_constraints_list: + bd_id = data[bd]["id"] + assert data[bd]["group"] == "default" + for k, term in enumerate(["lt", "gt", "eq"]): + term_path = input_path / "bindingconstraints" / f"{bd_id}_{term}.txt" + df = pandas.read_csv(term_path, sep="\t", header=None) + assert df.values.all() == old_binding_constraint_values[bd_id].iloc[:, k].values.all() + + # thermal cluster part + for area in list_areas: + reader = MultipleSameKeysIniReader(DUPLICATE_KEYS) + thermal_cluster_list = reader.read(tmp_path / "input" / "thermal" / "clusters" / area / "list.ini") + for cluster in thermal_cluster_list: + assert thermal_cluster_list[cluster]["costgeneration"] == "SetManually" + assert thermal_cluster_list[cluster]["efficiency"] == 100 + assert thermal_cluster_list[cluster]["variableomcost"] == 0 + def assert_folder_is_created(path: Path) -> None: assert path.is_dir() diff --git a/tests/storage/study_upgrader/test_upgrade_870.py b/tests/storage/study_upgrader/test_upgrade_870.py new file mode 100644 index 0000000000..ded66d31a6 --- /dev/null +++ b/tests/storage/study_upgrader/test_upgrade_870.py @@ -0,0 +1,17 @@ +from antarest.study.storage.study_upgrader import upgrade_870 +from tests.storage.business.test_study_version_upgrader import are_same_dir +from tests.storage.study_upgrader.conftest import StudyAssets + + +def test_nominal_case(study_assets: StudyAssets): + """ + Check that 'st-storage' folder is created and filled. + """ + + # upgrade the study + upgrade_870(study_assets.study_dir) + + # compare input folders (bindings + thermals) + actual_input_path = study_assets.study_dir.joinpath("input") + expected_input_path = study_assets.expected_dir.joinpath("input") + assert are_same_dir(actual_input_path, expected_input_path) diff --git a/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.expected.zip b/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.expected.zip new file mode 100644 index 0000000000..e8e657ae98 Binary files /dev/null and b/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.expected.zip differ diff --git a/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.zip b/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.zip new file mode 100644 index 0000000000..ee4aef0d34 Binary files /dev/null and b/tests/storage/study_upgrader/upgrade_870/nominal_case/little_study_860.zip differ