Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SimStadt
simstadtpy
Commits
f4f99c49
Commit
f4f99c49
authored
May 10, 2026
by
Eric Duminil
Browse files
Starting to tests EnergyGridResults
parent
c48aa296
Changes
1
Show whitespace changes
Inline
Side-by-side
tests/test_results.py
View file @
f4f99c49
...
@@ -8,6 +8,7 @@ import pytest
...
@@ -8,6 +8,7 @@ import pytest
from
simstadt
import
(
from
simstadt
import
(
KPI
,
KPI
,
EnergyGridResults
,
GreenWaterResults
,
GreenWaterResults
,
HeatDemandResults
,
HeatDemandResults
,
LoadProfileResults
,
LoadProfileResults
,
...
@@ -19,19 +20,21 @@ from simstadt import (
...
@@ -19,19 +20,21 @@ from simstadt import (
)
)
TEST_REPOSITORY
=
Path
(
__file__
).
parent
/
"data"
/
"TestRepo"
TEST_REPOSITORY
=
Path
(
__file__
).
parent
/
"data"
/
"TestRepo"
TEST_PROJECT_PATH
=
TEST_REPOSITORY
/
"CGSC.proj"
PROJECT1_PATH
=
TEST_REPOSITORY
/
"CGSC.proj"
LOAD_PROFILE_FLOW
=
TEST_REPOSITORY
/
"SektorSim.proj"
/
"LoadProfile.flow"
PROJECT2_PATH
=
TEST_REPOSITORY
/
"SektorSim.proj"
SOLAR_FLOW
=
TEST_REPOSITORY
/
"SektorSim.proj"
/
"Solar.flow"
LOAD_PROFILE_FLOW
=
PROJECT2_PATH
/
"LoadProfile.flow"
SOLAR_FLOW
=
PROJECT2_PATH
/
"Solar.flow"
ENERGY_GRID_FLOW
=
PROJECT2_PATH
/
"EnergyGridSimulation.flow"
def
kpis_by_name
(
results
:
SimStadtResults
)
->
dict
[
str
,
KPI
]:
def
kpis_by_name
(
results
:
SimStadtResults
)
->
dict
[
str
,
KPI
]:
return
{
kpi
.
name
:
kpi
for
kpi
in
results
.
kpis
}
return
{
kpi
.
name
:
kpi
for
kpi
in
results
.
kpis
}
def
find_output_files
(
workflow_
name
:
str
)
->
list
[
Path
]:
def
find_output_files
(
workflow_
path
:
Path
)
->
list
[
Path
]:
return
[
return
[
f
f
for
f
in
(
TEST_PROJECT_PATH
/
workflow_
name
)
.
glob
(
"*.step/**/*"
)
for
f
in
workflow_
path
.
glob
(
"*.step/**/*"
)
if
f
.
is_file
()
and
f
.
name
!=
"params.xml"
if
f
.
is_file
()
and
f
.
name
!=
"params.xml"
]
]
...
@@ -156,7 +159,7 @@ def test_heating_repr(heating_results):
...
@@ -156,7 +159,7 @@ def test_heating_repr(heating_results):
def
heating_and_cooling_results
()
->
SimStadtResults
:
def
heating_and_cooling_results
()
->
SimStadtResults
:
return
create_simstadt_results
(
return
create_simstadt_results
(
"Heating and cooling demand simulation for Grombühl"
,
"Heating and cooling demand simulation for Grombühl"
,
find_output_files
(
"104_HeatAndCoolDemand.flow"
),
find_output_files
(
PROJECT1_PATH
/
"104_HeatAndCoolDemand.flow"
),
)
)
...
@@ -170,9 +173,9 @@ def test_heating_and_cooling_kpis(heating_and_cooling_results):
...
@@ -170,9 +173,9 @@ def test_heating_and_cooling_kpis(heating_and_cooling_results):
assert
"Specific Heating Demand"
in
kpis
assert
"Specific Heating Demand"
in
kpis
assert
"Yearly Cooling demand"
in
kpis
assert
"Yearly Cooling demand"
in
kpis
assert
"Specific Cooling Demand"
in
kpis
assert
"Specific Cooling Demand"
in
kpis
assert
heating_and_cooling_results
.
kpi
(
"Specific Cooling Demand"
).
value
==
pytest
.
approx
(
assert
heating_and_cooling_results
.
kpi
(
20
,
abs
=
1
"Specific Cooling Demand"
)
)
.
value
==
pytest
.
approx
(
20
,
abs
=
1
)
assert
len
(
kpis
)
==
12
assert
len
(
kpis
)
==
12
...
@@ -193,7 +196,7 @@ def test_heating_and_cooling_diagrams(heating_and_cooling_results):
...
@@ -193,7 +196,7 @@ def test_heating_and_cooling_diagrams(heating_and_cooling_results):
def
cooling_results
()
->
SimStadtResults
:
def
cooling_results
()
->
SimStadtResults
:
return
create_simstadt_results
(
return
create_simstadt_results
(
"Cooling demand simulation for Grombühl"
,
"Cooling demand simulation for Grombühl"
,
find_output_files
(
"105_CoolingDemand.flow"
),
find_output_files
(
PROJECT1_PATH
/
"105_CoolingDemand.flow"
),
)
)
...
@@ -616,6 +619,35 @@ def test_broken_simulation():
...
@@ -616,6 +619,35 @@ def test_broken_simulation():
results
.
kpis
results
.
kpis
# ---------------------------------------------------------------------------
# Energy Grid Simulation
# ---------------------------------------------------------------------------
@
pytest
.
fixture
(
scope
=
"module"
)
def
energy_grid_results
()
->
SimStadtResults
:
return
create_simstadt_results
(
"Energy Grid Simulation for MiniBuchwald"
,
find_output_files
(
PROJECT2_PATH
/
"EnergyGridSimulation.flow"
),
)
def
test_energy_grid_result_type
(
energy_grid_results
):
assert
isinstance
(
energy_grid_results
,
EnergyGridResults
)
def
test_energy_grid_output_files_exist
(
energy_grid_results
):
assert
all
(
f
.
exists
()
for
f
in
energy_grid_results
.
output_files
)
assert
len
(
energy_grid_results
.
get_all_by_extension
(
".json"
))
==
1
def
test_energy_grid_dataframe
(
energy_grid_results
):
df
=
energy_grid_results
.
dataframe
assert
isinstance
(
df
,
pd
.
DataFrame
)
assert
df
.
shape
==
(
8760
,
3
)
assert
list
(
df
.
columns
)
==
[
"GHI"
,
"DHI"
,
"Ta"
]
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
# Unknown workflow
# Unknown workflow
# ---------------------------------------------------------------------------
# ---------------------------------------------------------------------------
...
@@ -623,7 +655,7 @@ def test_broken_simulation():
...
@@ -623,7 +655,7 @@ def test_broken_simulation():
def
test_unknown_workflow_results
(
caplog
):
def
test_unknown_workflow_results
(
caplog
):
output_files
=
[
output_files
=
[
TEST_
PROJECT_PATH
/
"UnknownWorkflow.flow/output.step/result.log"
,
PROJECT
1
_PATH
/
"UnknownWorkflow.flow/output.step/result.log"
,
]
]
with
caplog
.
at_level
(
logging
.
WARNING
):
with
caplog
.
at_level
(
logging
.
WARNING
):
results
=
create_simstadt_results
(
"Unknown workflow test"
,
output_files
)
results
=
create_simstadt_results
(
"Unknown workflow test"
,
output_files
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment