Skip to content

Commit

Permalink
fix(study-factory): avoid parsing renewables config if version < 810
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent-laporte-pro committed Jan 4, 2024
1 parent 4b00e79 commit 327f019
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,14 @@ def _parse_renewables(root: Path, area: str) -> t.List[RenewableConfigType]:
"""
Parse the renewables INI file, return an empty list if missing.
"""

# Before version 8.1, we only have "Load", "Wind" and "Solar" objects.
# We can't use renewable clusters.
version = _parse_version(root)
if version < 810:
return []

# Since version 8.1 of the solver, we can use "renewable clusters" objects.
relpath = Path(f"input/renewables/clusters/{area}/list.ini")
config_dict: t.Dict[str, t.Any] = _extract_data_from_file(
root=root,
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/variant_blueprint/test_renewable_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import pytest
from starlette.testclient import TestClient

from antarest.core.tasks.model import TaskStatus
from antarest.study.storage.rawstudy.model.filesystem.config.model import transform_name_to_id
from tests.integration.utils import wait_task_completion


# noinspection SpellCheckingInspection
Expand All @@ -23,6 +25,22 @@ def test_lifecycle(
) -> None:
# sourcery skip: extract-duplicate-method

# =======================
# Study version upgrade
# =======================

# We have an "old" study that we need to upgrade to version 810
min_study_version = 810
res = client.put(
f"/v1/studies/{study_id}/upgrade",
headers={"Authorization": f"Bearer {user_access_token}"},
params={"target_version": min_study_version},
)
res.raise_for_status()
task_id = res.json()
task = wait_task_completion(client, user_access_token, task_id)
assert task.status == TaskStatus.COMPLETED, task

# =====================
# General Data Update
# =====================
Expand Down
3 changes: 3 additions & 0 deletions tests/storage/rawstudies/samples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pathlib import Path

ASSETS_DIR = Path(__file__).parent.resolve()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[antares]
version = 800
version = 810
caption = renewable-2-clusters-ts-prod-factor
created = 1618413128
lastsave = 1625583204
Expand Down
10 changes: 5 additions & 5 deletions tests/storage/rawstudies/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pathlib import Path
from unittest.mock import Mock

from antarest.core.interfaces.cache import CacheConstants
Expand All @@ -7,10 +6,11 @@
from antarest.study.storage.rawstudy.model.filesystem.context import ContextServer
from antarest.study.storage.rawstudy.model.filesystem.factory import StudyFactory
from antarest.study.storage.rawstudy.model.filesystem.root.filestudytree import FileStudyTree
from tests.storage.rawstudies.samples import ASSETS_DIR


def test_renewable_subtree():
path = Path(__file__).parent / "samples/v810/sample1"
def test_renewable_subtree() -> None:
path = ASSETS_DIR / "v810/sample1"
context: ContextServer = Mock(specs=ContextServer)
config = build(path, "")
assert config.get_renewable_ids("area") == ["la_rochelle", "oleron"]
Expand Down Expand Up @@ -41,8 +41,8 @@ def test_renewable_subtree():
}


def test_factory_cache():
path = Path(__file__).parent / "samples/v810/sample1"
def test_factory_cache() -> None:
path = ASSETS_DIR / "v810/sample1"

cache = Mock()
factory = StudyFactory(matrix=Mock(), resolver=Mock(), cache=cache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def test_parse_thermal_860(tmp_path: Path, version, caplog) -> None:

def test_parse_renewables(tmp_path: Path) -> None:
study_path = build_empty_files(tmp_path)
study_path.joinpath("study.antares").write_text("[antares] \n version = 700")
study_path.joinpath("study.antares").write_text("[antares] \n version = 810")
ini_path = study_path.joinpath("input/renewables/clusters/fr/list.ini")

# Error case: `input/renewables/clusters/fr` directory is missing.
Expand Down

0 comments on commit 327f019

Please sign in to comment.