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
e8327ddc
Commit
e8327ddc
authored
Mar 13, 2026
by
Eric Duminil
Browse files
Mocking SimStadt for faster tests
parent
e2afa436
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/conftest.py
View file @
e8327ddc
...
...
@@ -19,7 +19,7 @@ def test_project_path() -> Path:
# ---------------------------------------------------------------------------
# SimStadt
spoof
(replaces subprocess call with fixture file copying)
# SimStadt
mock
(replaces subprocess call with fixture file copying)
# ---------------------------------------------------------------------------
def
_find_fixture_flow
(
provider
:
str
)
->
Path
|
None
:
...
...
@@ -38,10 +38,10 @@ def _find_fixture_flow(provider: str) -> Path | None:
@
pytest
.
fixture
def
spoof
_simstadt
(
monkeypatch
):
"""
Patch
run_simstadt
to
copy fixture output files instead of running SimStadt."""
def
mock
_simstadt
(
monkeypatch
):
"""
Mock
run_simstadt
by
copy
ing
fixture output files instead of running SimStadt."""
def
_
spoof
(
workflow_path
:
Path
,
name
:
str
)
->
str
:
def
_
mock
(
workflow_path
:
Path
,
name
:
str
)
->
str
:
root
=
et
.
parse
(
workflow_path
/
"params.xml"
).
getroot
()
elem
=
root
.
find
(
".//void[@property='workflowProvider']/object"
)
provider
=
elem
.
get
(
"class"
)
if
elem
is
not
None
else
None
...
...
@@ -53,9 +53,9 @@ def spoof_simstadt(monkeypatch):
dst
=
workflow_path
/
src
.
relative_to
(
fixture_flow
)
dst
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
shutil
.
copy2
(
src
,
dst
)
return
f
"
Spoof
ed SimStadt for
{
name
}
"
return
f
"
Mock
ed SimStadt for
{
name
}
"
monkeypatch
.
setattr
(
"simstadt.runner.run_simstadt"
,
_
spoof
)
monkeypatch
.
setattr
(
"simstadt.runner.run_simstadt"
,
_
mock
)
# ---------------------------------------------------------------------------
...
...
tests/test_runner.py
View file @
e8327ddc
...
...
@@ -3,42 +3,42 @@
import
shutil
from
pathlib
import
Path
import
pytest
from
simstadt.runner
import
run_workflow_with_citygml
TEST_DATA
=
Path
(
__file__
).
parent
/
"data"
CITYGML
=
TEST_DATA
/
"TestRepo"
/
"MiniBuchwald.gml"
TEMPLATE
=
TEST_DATA
/
"Templates"
/
"01_HeatDemand"
TEMPLATE1
=
TEST_DATA
/
"Templates"
/
"01_HeatDemand"
TEMPLATE2
=
TEST_DATA
/
"Templates"
/
"02_LoadProfile"
TEMPLATE3
=
TEST_DATA
/
"Templates"
/
"03_PV"
def
test_citygml_in_proj_folder
(
spoof
_simstadt
,
tmp_path
):
def
test_citygml_in_proj_folder
(
mock
_simstadt
,
tmp_path
):
"""CityGML already inside a .proj folder — used as-is, nothing copied."""
proj
=
tmp_path
/
"Test.proj"
proj
.
mkdir
()
gml
=
proj
/
CITYGML
.
name
shutil
.
copy
(
CITYGML
,
gml
)
results
=
run_workflow_with_citygml
(
TEMPLATE
,
gml
)
results
=
run_workflow_with_citygml
(
TEMPLATE
1
,
gml
)
assert
results
is
not
None
assert
CITYGML
.
name
in
results
.
citygml
assert
results
.
workflow_path
.
parent
==
proj
def
test_citygml_with_explicit_project_path
(
spoof
_simstadt
,
tmp_path
):
def
test_citygml_with_explicit_project_path
(
mock
_simstadt
,
tmp_path
):
"""CityGML outside .proj with project_path — CityGML is copied to project_path."""
proj
=
tmp_path
/
"Test.proj"
proj
.
mkdir
()
results
=
run_workflow_with_citygml
(
TEMPLATE
,
CITYGML
,
project_path
=
proj
)
results
=
run_workflow_with_citygml
(
TEMPLATE
2
,
CITYGML
,
project_path
=
proj
)
assert
(
proj
/
CITYGML
.
name
).
exists
()
assert
results
is
not
None
assert
results
.
workflow_path
.
parent
==
proj
def
test_citygml_with_explicit_project_path_no_double_copy
(
spoof
_simstadt
,
tmp_path
):
def
test_citygml_with_explicit_project_path_no_double_copy
(
mock
_simstadt
,
tmp_path
):
"""CityGML already present in project_path — not copied again."""
proj
=
tmp_path
/
"Test.proj"
proj
.
mkdir
()
...
...
@@ -46,14 +46,14 @@ def test_citygml_with_explicit_project_path_no_double_copy(spoof_simstadt, tmp_p
shutil
.
copy
(
CITYGML
,
dest
)
mtime_before
=
dest
.
stat
().
st_mtime
run_workflow_with_citygml
(
TEMPLATE
,
CITYGML
,
project_path
=
proj
)
run_workflow_with_citygml
(
TEMPLATE
3
,
CITYGML
,
project_path
=
proj
)
assert
dest
.
stat
().
st_mtime
==
mtime_before
def
test_citygml_creates_temp_repo
(
spoof
_simstadt
):
def
test_citygml_creates_temp_repo
(
mock
_simstadt
):
"""CityGML outside .proj with no project_path — temporary repository created."""
results
=
run_workflow_with_citygml
(
TEMPLATE
,
CITYGML
)
results
=
run_workflow_with_citygml
(
TEMPLATE
1
,
CITYGML
)
assert
results
is
not
None
assert
"simstadt_repo"
in
str
(
results
.
workflow_path
)
...
...
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