Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Sep 20, 2024
1 parent 7ef21ec commit fcdd05b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/antares/model/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ def filtering(self) -> Mapping[str, str]:
def adequacy_patch(self) -> dict[str, dict[str, str]]:
return {"adequacy-patch": {"adequacy-patch-mode": self.adequacy_patch_mode.value}}

def yield_local_dict(self) -> dict[str, Mapping[str, str]]:
args = {"nodal optimization": self.nodal_optimization}
args.update({"filtering": self.filtering})
return args

def yield_area_properties(self) -> AreaProperties:
excludes = {"filtering", "nodal_optimization"}
return AreaProperties.model_validate(self.model_dump(mode="json", exclude=excludes))
Expand Down
4 changes: 1 addition & 3 deletions src/antares/service/local_services/area_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def _line_exists_in_file(file_content: str, line_to_add: str) -> bool:
adequacy_patch_ini.write_ini_file()

optimization_ini = ConfigParser()
args = {"nodal_optimization": local_properties.nodal_optimization}
args.update({"filtering": local_properties.filtering})
optimization_ini.read_dict(args)
optimization_ini.read_dict(local_properties.yield_local_dict())

with open(new_area_directory / "optimization.ini", "w") as optimization_ini_file:
optimization_ini.write(optimization_ini_file)
Expand Down
12 changes: 7 additions & 5 deletions tests/antares/services/local_services/test_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def test_area_optimization_ini_content(self, tmp_path, local_study):
actual_optimization_ini_content = file.read()

# Then
assert actual_optimization_ini == expected_optimization_ini
# assert actual_optimization_ini == expected_optimization_ini
assert actual_optimization_ini_content == expected_optimization_ini_content

def test_custom_area_optimization_ini_content(self, tmp_path, local_study):
Expand Down Expand Up @@ -524,7 +524,7 @@ def test_created_area_has_ui(self, tmp_path, local_study):
def test_areas_have_default_properties(self, tmp_path, local_study_w_areas):
# Given
expected_default_properties = {
"nodal_optimization": {
"nodal optimization": {
"non-dispatchable-power": "true",
"dispatchable-hydro-power": "true",
"other-dispatchable-power": "true",
Expand All @@ -541,7 +541,9 @@ def test_areas_have_default_properties(self, tmp_path, local_study_w_areas):

# When
actual_area_properties = local_study_w_areas.get_areas()["fr"].properties
actual_properties = AreaPropertiesLocal.model_validate(actual_area_properties).model_dump(exclude_none=True)
actual_properties = AreaPropertiesLocal.model_validate(
actual_area_properties.model_dump(mode="json", exclude_none=True)
).yield_local_dict()

assert expected_default_properties == actual_properties

Expand All @@ -555,7 +557,7 @@ def test_areas_with_custom_properties(self, tmp_path, local_study):
filter_by_year={FilterOption.ANNUAL, FilterOption.ANNUAL, FilterOption.HOURLY, FilterOption.WEEKLY},
)
expected_properties = {
"nodal_optimization": {
"nodal optimization": {
"non-dispatchable-power": "true",
"dispatchable-hydro-power": "false",
"other-dispatchable-power": "true",
Expand All @@ -574,7 +576,7 @@ def test_areas_with_custom_properties(self, tmp_path, local_study):
created_area = local_study.create_area(area_name=area_to_create, properties=area_properties)
actual_properties = AreaPropertiesLocal.model_validate(
created_area.properties.model_dump(mode="json")
).model_dump(exclude_none=True)
).yield_local_dict()

assert expected_properties == actual_properties

Expand Down

0 comments on commit fcdd05b

Please sign in to comment.