Skip to content

Commit

Permalink
tests(raw): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jan 8, 2025
1 parent a3ecf59 commit e1003a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def load(

# here we should return the default matrix
default_matrix = self.get_default_empty_matrix()
if not default_matrix:
if default_matrix is None:
return b""
return default_matrix.tobytes()

Expand Down
93 changes: 34 additions & 59 deletions tests/storage/integration/test_STA_mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Union
from unittest.mock import Mock

import numpy as np
import pytest
from fastapi import FastAPI
from starlette.testclient import TestClient
Expand Down Expand Up @@ -172,44 +173,35 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)

@pytest.mark.integration_test
@pytest.mark.parametrize(
"url, expected_output",
"url, expected_output, formatted",
[
(
f"/v1/studies/{UUID}/raw?path=input/bindingconstraints/bindingconstraints",
{},
),
(f"/v1/studies/{UUID}/raw?path=input/bindingconstraints/bindingconstraints", {}, True),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/series/de/mod",
{
"columns": [0, 1, 2],
"index": list(range(365)),
"data": [[0.0]] * 365,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/areas/list",
["DE", "ES", "FR", "IT"],
),
(
f"/v1/studies/{UUID}/raw?path=input/areas/sets/all areas/output",
False,
),
(f"/v1/studies/{UUID}/raw?path=input/areas/list", ["DE", "ES", "FR", "IT"], True),
(f"/v1/studies/{UUID}/raw?path=input/areas/sets/all areas/output", False, True),
(
f"/v1/studies/{UUID}/raw?path=input/areas/de/optimization/nodal optimization/spread-spilled-energy-cost",
0,
True,
),
(f"/v1/studies/{UUID}/raw?path=input/areas/de/ui/layerX/0", 1),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/allocation/de/[allocation]/de",
1,
),
(f"/v1/studies/{UUID}/raw?path=input/areas/de/ui/layerX/0", 1, True),
(f"/v1/studies/{UUID}/raw?path=input/hydro/allocation/de/[allocation]/de", 1, True),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/common/capacity/reservoir_fr",
{
"columns": [0, 1, 2],
"index": list(range(365)),
"data": [[0, 0.5, 1]] * 365,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/thermal/series/fr/05_nuclear/series",
Expand All @@ -218,47 +210,29 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)
"index": list(range(8760)),
"data": [[2000]] * 8760,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/correlation/general/mode",
"annual",
),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/prepro/prepro/intermonthly-correlation",
0.5,
),
(f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/correlation/general/mode", "annual", True),
(f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/prepro/prepro/intermonthly-correlation", 0.5, True),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/prepro/fr/energy",
{"data": [[]], "index": [0], "columns": []},
),
(
f"/v1/studies/{UUID}/raw?path=input/hydro/hydro/inter-monthly-breakdown/fr",
1,
),
(
f"/v1/studies/{UUID}/raw?path=input/thermal/areas/unserverdenergycost/de",
3000.0,
),
(
f"/v1/studies/{UUID}/raw?path=input/thermal/clusters/fr/list/05_nuclear/marginal-cost",
50,
),
(
f"/v1/studies/{UUID}/raw?path=input/links/fr/properties/it/hurdles-cost",
True,
),
(f"/v1/studies/{UUID}/raw?path=input/hydro/hydro/inter-monthly-breakdown/fr", 1, True),
(f"/v1/studies/{UUID}/raw?path=input/thermal/areas/unserverdenergycost/de", 3000.0, True),
(f"/v1/studies/{UUID}/raw?path=input/thermal/clusters/fr/list/05_nuclear/marginal-cost", 50, True),
(f"/v1/studies/{UUID}/raw?path=input/links/fr/properties/it/hurdles-cost", True, True),
(
f"/v1/studies/{UUID}/raw?path=input/links/fr/it",
{
"columns": list(range(8)),
"index": list(range(8760)),
"data": [[100000, 100000, 0.01, 0.01, 0, 0, 0, 0]] * 8760,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/load/prepro/fr/k",
{"data": [[]], "index": [0], "columns": []},
),
(f"/v1/studies/{UUID}/raw?path=input/load/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True),
(
f"/v1/studies/{UUID}/raw?path=input/load/series",
{
Expand All @@ -267,6 +241,7 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)
"load_fr": "matrixfile://load_fr.txt",
"load_it": "matrixfile://load_it.txt",
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/load/series/load_fr",
Expand All @@ -275,6 +250,7 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)
"index": list(range(8760)),
"data": [[i % 168 * 100] for i in range(8760)],
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/misc-gen/miscgen-fr",
Expand All @@ -283,6 +259,12 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)
"index": list(range(8760)),
"data": [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 8760,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/misc-gen/miscgen-fr",
np.array([[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]] * 8760).tobytes(),
False,
),
(
f"/v1/studies/{UUID}/raw?path=input/reserves/fr",
Expand All @@ -291,39 +273,32 @@ def test_sta_mini_study_antares(storage_service, url: str, expected_output: str)
"index": list(range(8760)),
"data": [[0.0]] * 8760,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/solar/prepro/fr/k",
{"data": [[]], "index": [0], "columns": []},
),
(f"/v1/studies/{UUID}/raw?path=input/solar/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True),
(
f"/v1/studies/{UUID}/raw?path=input/solar/series/solar_fr",
{
"columns": [0],
"index": list(range(8760)),
"data": [[0.0]] * 8760,
},
True,
),
(
f"/v1/studies/{UUID}/raw?path=input/wind/prepro/fr/k",
{"data": [[]], "index": [0], "columns": []},
),
(f"/v1/studies/{UUID}/raw?path=input/wind/prepro/fr/k", {"data": [[]], "index": [0], "columns": []}, True),
(
f"/v1/studies/{UUID}/raw?path=input/wind/series/wind_fr",
{
"columns": [0],
"index": list(range(8760)),
"data": [[0.0]] * 8760,
},
True,
),
],
)
def test_sta_mini_input(storage_service, url: str, expected_output: dict):
assert_with_errors(
storage_service=storage_service,
url=url,
expected_output=expected_output,
)
def test_sta_mini_input(storage_service, url: str, expected_output: dict, formatted: bool):
assert_with_errors(storage_service=storage_service, url=url, expected_output=expected_output, formatted=formatted)


@pytest.mark.integration_test
Expand Down

0 comments on commit e1003a8

Please sign in to comment.