Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Sep 25, 2024
1 parent d6b4c50 commit 29c58c7
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion antarest/launcher/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def run_study(
job_uuid = self._generate_new_id()
logger.info(f"New study launch (study={study_uuid}, job_id={job_uuid})")
study_info = self.study_service.get_study_information(uuid=study_uuid, params=params)
solver_version = study_version or study_info.version.__format__(format_spec="ddd")
solver_version = study_version or study_info.version.__str__()

self._assert_launcher_is_initialized(launcher)
assert_permission(
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/areas/st_storage_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def update_storages_props(

# Convert the DTO to a configuration object and update the configuration file.
properties = create_st_storage_config(
study.version, **new_cluster.model_dump(by_alias=False, exclude_none=True)
StudyVersion.parse(study.version), **new_cluster.model_dump(by_alias=False, exclude_none=True)
)
path = _STORAGE_LIST_PATH.format(area_id=area_id, storage_id=storage_id)
cmd = UpdateConfig(
Expand Down
2 changes: 1 addition & 1 deletion antarest/study/business/areas/thermal_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def validate_series(self, study: Study, area_id: str, cluster_id: str) -> bool:
lower_cluster_id = cluster_id.lower()
thermal_cluster_path = Path(f"input/thermal/series/{area_id}/{lower_cluster_id}")
series_path = [thermal_cluster_path / "series"]
if StudyVersion(study.version) >= 870:
if StudyVersion.parse(study.version) >= 870:
series_path.append(thermal_cluster_path / "CO2Cost")
series_path.append(thermal_cluster_path / "fuelCost")

Expand Down
4 changes: 2 additions & 2 deletions antarest/study/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ class StudyMetadataDTO(BaseModel):
folder: t.Optional[str] = None
tags: t.List[str] = []

@field_serializer('version', when_used='json')
def serialize_version(self, version: StudyVersion):
@field_serializer('version')
def serialize_version(self, version: StudyVersion) -> int:
return version.__int__()

@field_validator("horizon", mode="before")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _parse_version(path: Path) -> StudyVersion:
inside_root_path=Path("study.antares"),
file_type=FileType.SIMPLE_INI,
)
version = study_info.get("antares", {}).get("version", -1)
version = study_info.get("antares", {}).get("version", 0)
return StudyVersion.parse(version)


Expand Down
11 changes: 10 additions & 1 deletion antarest/study/storage/rawstudy/model/filesystem/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pathlib import Path

from antares.study.version import StudyVersion
from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field, model_validator, field_serializer, field_validator

from antarest.core.utils.utils import DTO
from antarest.study.business.enum_ignore_case import EnumIgnoreCase
Expand Down Expand Up @@ -318,6 +318,15 @@ class FileStudyTreeConfigDTO(BaseModel):
enr_modelling: str = str(EnrModelling.AGGREGATED)
zip_path: t.Optional[Path] = None

@field_serializer('version')
def serialize_version(self, version: StudyVersion) -> int:
return version.__int__()

@field_validator("version", mode="before")
def _validate_version(cls, v: t.Any) -> StudyVersion:
return StudyVersion.parse(v)


@staticmethod
def from_build_config(
config: FileStudyTreeConfig,
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/test_local_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_lifecycle():
study_path=Path("somepath"),
path=Path("somepath"),
study_id="",
version=StudyVersion.parse(-1),
version=StudyVersion.parse(0),
areas={
"a1": Area(
name="a1",
Expand Down
2 changes: 1 addition & 1 deletion tests/cache/test_redis_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_lifecycle():
study_path=Path("somepath"),
path=Path("somepath"),
study_id="",
version=StudyVersion.parse(-1),
version=StudyVersion.parse(0),
areas={
"a1": Area(
name="a1",
Expand Down
2 changes: 1 addition & 1 deletion tests/storage/business/test_raw_study_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def test_check_and_update_study_version_in_database(tmp_path: Path) -> None:

assert raw_study.version == "100"

raw_study = RawStudy(id=name, workspace="foo", path=str(study_path), version="100")
raw_study = RawStudy(id=name, workspace="foo", path=str(study_path), version="42")

file_study_tree = Mock()
file_study_tree.get.return_value = {"version": 42}
Expand Down
6 changes: 3 additions & 3 deletions tests/storage/business/test_study_version_upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ def test_fails_because_of_versions_asked(tmp_path: Path):
with zipfile.ZipFile(path_study) as zip_output:
zip_output.extractall(path=study_dir)
# Try to upgrade with an unknown version
with pytest.raises(InvalidUpgrade, match="Cannot downgrade from version '7.2' to '6'"):
with pytest.raises(InvalidUpgrade, match="Cannot downgrade from version '720' to '600'"):
StudyUpgrader(study_dir, "600").upgrade()
# Try to upgrade with the current version
with pytest.raises(InvalidUpgrade, match="Your study is already in version '7.2'"):
with pytest.raises(InvalidUpgrade, match="Your study is already in version '720'"):
StudyUpgrader(study_dir, "720").upgrade()
# Try to upgrade with an old version
with pytest.raises(
InvalidUpgrade,
match="Cannot downgrade from version '7.2' to '7.1'",
match="Cannot downgrade from version '720' to '710'",
):
StudyUpgrader(study_dir, "710").upgrade()
# Try to upgrade with a version that does not exist
Expand Down
10 changes: 5 additions & 5 deletions tests/storage/repository/filesystem/config/test_config_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_parse_output_parameters(study_path: Path) -> None:
config = FileStudyTreeConfig(
study_path=study_path,
path=study_path,
version=-1,
version=0,
store_new_set=True,
study_id="id",
output_path=study_path / "output",
Expand All @@ -105,7 +105,7 @@ def test_parse_bindings(study_path: Path) -> None:
config = FileStudyTreeConfig(
study_path=study_path,
path=study_path,
version=-1,
version=0,
bindings=[
BindingConstraintDTO(
id="bindA",
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_parse_outputs(study_path: Path) -> None:
study_path=study_path,
path=study_path,
study_id="id",
version=-1,
version=0,
output_path=study_path / "output",
outputs={
"20201220-1456eco-hello": Simulation(
Expand Down Expand Up @@ -271,7 +271,7 @@ def test_parse_area(study_path: Path) -> None:
study_path=study_path,
path=study_path,
study_id="id",
version=-1,
version=0,
output_path=study_path / "output",
areas={
"fr": Area(
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_parse_area__extra_area(study_path: Path) -> None:
study_path=study_path,
path=study_path,
study_id="id",
version=-1,
version=0,
output_path=study_path / "output",
areas={
"fr": Area(
Expand Down

0 comments on commit 29c58c7

Please sign in to comment.