Skip to content

Commit

Permalink
first draft: 42 test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Oct 9, 2024
1 parent dc0130d commit a781c09
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import functools
import typing as t

from pydantic import Field
from pydantic import Field, field_validator

from antarest.core.serialization import AntaresBaseModel

Expand Down Expand Up @@ -51,6 +51,10 @@ class ItemProperties(

name: str = Field(description="Cluster name", pattern=r"[a-zA-Z0-9_(),& -]+")

@field_validator("name", mode="before")
def _validate_name(cls, name: str) -> str:
return str(name).lower()

def __lt__(self, other: t.Any) -> bool:
"""
Compare two clusters by group and name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class STStorageGroup(EnumIgnoreCase):
- OTHER1...OTHER5: Represents other energy storage systems.
"""

PSP_OPEN = "PSP_open"
PSP_CLOSED = "PSP_closed"
PONDAGE = "Pondage"
BATTERY = "Battery"
OTHER1 = "Other1"
OTHER2 = "Other2"
OTHER3 = "Other3"
OTHER4 = "Other4"
OTHER5 = "Other5"
PSP_OPEN = "psp_open"
PSP_CLOSED = "psp_closed"
PONDAGE = "pondage"
BATTERY = "battery"
OTHER1 = "other1"
OTHER2 = "other2"
OTHER3 = "other3"
OTHER4 = "other4"
OTHER5 = "other5"


# noinspection SpellCheckingInspection
Expand Down
20 changes: 10 additions & 10 deletions antarest/study/storage/rawstudy/model/filesystem/config/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ class ThermalClusterGroup(EnumIgnoreCase):
The group `OTHER1` is used by default.
"""

NUCLEAR = "Nuclear"
LIGNITE = "Lignite"
HARD_COAL = "Hard Coal"
GAS = "Gas"
OIL = "Oil"
MIXED_FUEL = "Mixed Fuel"
OTHER1 = "Other 1"
OTHER2 = "Other 2"
OTHER3 = "Other 3"
OTHER4 = "Other 4"
NUCLEAR = "nuclear"
LIGNITE = "lignite"
HARD_COAL = "hard coal"
GAS = "gas"
OIL = "oil"
MIXED_FUEL = "mixed fuel"
OTHER1 = "other 1"
OTHER2 = "other 2"
OTHER3 = "other 3"
OTHER4 = "other 4"

def __repr__(self) -> str: # pragma: no cover
return f"{self.__class__.__name__}.{self.name}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ class CreateCluster(ICommand):

@field_validator("cluster_name", mode="before")
def validate_cluster_name(cls, val: str) -> str:
valid_name = transform_name_to_id(val, lower=False)
if valid_name != val:
to_return = transform_name_to_id(val)
if not to_return:
raise ValueError("Cluster name must only contains [a-zA-Z0-9],&,-,_,(,) characters")
return val
return to_return

@field_validator("prepro", mode="before")
def validate_prepro(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st
clusters_list = preparer.get_thermals(study_id, area1_id)
assert len(clusters_list) == 1
assert clusters_list[0]["id"] == cluster_id
assert clusters_list[0]["name"] == "Cluster 1"
assert clusters_list[0]["name"] == "cluster 1"
assert clusters_list[0]["group"] == "Nuclear"

if study_type == "variant":
Expand Down
16 changes: 10 additions & 6 deletions tests/integration/study_data_blueprint/test_st_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,25 @@ def test_lifecycle__nominal(
# We can create a short-term storage with the following properties.
# Unfilled properties will be set to their default values.
siemens_properties = {
"name": siemens_battery,
"group": "Battery",
"group": "battery",
"injectionNominalCapacity": 1450,
"withdrawalNominalCapacity": 1350,
"reservoirCapacity": 1500,
}
res = client.post(
f"/v1/studies/{internal_study_id}/areas/{area_id}/storages",
headers=user_headers,
json=siemens_properties,
json={"name": siemens_battery, **siemens_properties},
)
assert res.status_code == 200, res.json()
siemens_battery_id = res.json()["id"]
assert siemens_battery_id == transform_name_to_id(siemens_battery)
siemens_output = {**default_output, **siemens_properties, "id": siemens_battery_id}
siemens_output = {
**default_output,
**siemens_properties,
"id": siemens_battery_id,
"name": siemens_battery.lower(),
}
assert res.json() == siemens_output

# reading the properties of a short-term storage
Expand Down Expand Up @@ -612,7 +616,7 @@ def test__default_values(
)
assert res.status_code == 200, res.json()
tesla_battery_id = res.json()["id"]
tesla_output = {**default_output, "id": tesla_battery_id, "name": tesla_battery, "group": "Battery"}
tesla_output = {**default_output, "id": tesla_battery_id, "name": tesla_battery.lower(), "group": "Battery"}
assert res.json() == tesla_output

# Use the Debug mode to make sure that the initialLevel and initialLevelOptim properties
Expand Down Expand Up @@ -814,7 +818,7 @@ def test_variant_lifecycle(self, client: TestClient, user_access_token: str, var
)
assert res.status_code in {200, 201}, res.json()
cluster_cfg = res.json()
assert cluster_cfg["name"] == new_name
assert cluster_cfg["name"] == new_name.lower()
new_id = cluster_cfg["id"]

# Check that the duplicate has the right properties
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/study_data_blueprint/test_table_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def test_lifecycle__nominal(
"enabled": True,
"fixedCost": 0,
"genTs": "use global",
"group": "Other 2",
"group": "other 2",
"lawForced": "uniform",
"lawPlanned": "uniform",
"marginalCost": 10,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/study_data_blueprint/test_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,14 +918,14 @@ def test_variant_lifecycle(self, client: TestClient, user_access_token: str, var
)
assert res.status_code in {200, 201}, res.json()
cluster_cfg = res.json()
assert cluster_cfg["name"] == new_name
assert cluster_cfg["name"] == new_name.lower()
new_id = cluster_cfg["id"]

# Check that the duplicate has the right properties
res = client.get(f"/v1/studies/{variant_id}/areas/{area_id}/clusters/thermal/{new_id}")
assert res.status_code == 200, res.json()
cluster_cfg = res.json()
assert cluster_cfg["group"] == "Nuclear"
assert cluster_cfg["group"] == "nuclear"
assert cluster_cfg["unitCount"] == 13
assert cluster_cfg["nominalCapacity"] == 42500
assert cluster_cfg["marginalCost"] == 0.2
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ def test_area_management(client: TestClient, admin_access_token: str) -> None:
f"/v1/studies/{study_id}/areas/area 1/clusters/thermal/cluster 1/form",
)
assert res.status_code == 200, res.json()
obj["group"] = obj["group"].lower()
assert res.json() == {"id": "cluster 1", **obj}

# Links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_lifecycle(
expected = {
"enabled": True,
"group": "Wind Offshore",
"id": "Oleron",
"id": "oleron",
"name": cluster_fr1,
"nominalCapacity": 2500.0,
"tsInterpretation": "power-generation",
Expand Down
4 changes: 2 additions & 2 deletions tests/study/business/areas/test_thermal_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def test_create_cluster__study_legacy(
"minStablePower": 0.0,
"minUpTime": 15,
"mustRun": False,
"name": "New Cluster",
"name": "new cluster",
"nh3": None,
"nmvoc": None,
"nominalCapacity": 1000.0,
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_update_cluster(
expected = {
"id": "2 avail and must 1",
"group": ThermalClusterGroup.GAS,
"name": "New name",
"name": "new name",
"enabled": False,
"unitCount": 100,
"nominalCapacity": 2000.0,
Expand Down
8 changes: 4 additions & 4 deletions tests/variantstudy/model/command/test_create_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_init(self, command_context: CommandContext):
prepro_id = command_context.matrix_service.create(prepro)
modulation_id = command_context.matrix_service.create(modulation)
assert cl.area_id == "foo"
assert cl.cluster_name == "Cluster1"
assert cl.cluster_name == "cluster1"
assert cl.parameters == {"group": "Nuclear", "nominalcapacity": 2400, "unitcount": 2}
assert cl.prepro == f"matrix://{prepro_id}"
assert cl.modulation == f"matrix://{modulation_id}"
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext):

clusters = configparser.ConfigParser()
clusters.read(study_path / "input" / "thermal" / "clusters" / area_id / "list.ini")
assert str(clusters[cluster_name]["name"]) == cluster_name
assert str(clusters[cluster_name]["name"]) == cluster_name.lower()
assert str(clusters[cluster_name]["group"]) == parameters["group"]
assert int(clusters[cluster_name]["unitcount"]) == int(parameters["unitcount"])
assert float(clusters[cluster_name]["nominalcapacity"]) == float(parameters["nominalcapacity"])
Expand Down Expand Up @@ -166,8 +166,8 @@ def test_to_dto(self, command_context: CommandContext):
"action": "create_cluster",
"args": {
"area_id": "foo",
"cluster_name": "Cluster1",
"parameters": {"group": "Nuclear", "nominalcapacity": 2400, "unitcount": 2},
"cluster_name": "cluster1",
"parameters": {"group": "nuclear", "nominalcapacity": 2400, "unitcount": 2},
"prepro": prepro_id,
"modulation": modulation_id,
},
Expand Down

0 comments on commit a781c09

Please sign in to comment.