Skip to content

Commit f469523

Browse files
committed
[test_ModelicaSystem] include test of ModelicaSystem using docker
1 parent 7885e25 commit f469523

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

tests/test_ModelicaSystem.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,36 @@
22
import os
33
import pathlib
44
import pytest
5+
import sys
56
import tempfile
67
import numpy as np
78

9+
skip_on_windows = pytest.mark.skipif(
10+
sys.platform.startswith("win"),
11+
reason="OpenModelica Docker image is Linux-only; skipping on Windows.",
12+
)
13+
14+
skip_python_older_312 = pytest.mark.skipif(
15+
sys.version_info < (3, 12),
16+
reason="OMCPath(non-local) only working for Python >= 3.12.",
17+
)
18+
819

920
@pytest.fixture
10-
def model_firstorder(tmp_path):
11-
mod = tmp_path / "M.mo"
12-
mod.write_text("""model M
21+
def model_firstorder_content():
22+
return ("""model M
1323
Real x(start = 1, fixed = true);
1424
parameter Real a = -1;
1525
equation
1626
der(x) = x*a;
1727
end M;
1828
""")
29+
30+
31+
@pytest.fixture
32+
def model_firstorder(tmp_path, model_firstorder_content):
33+
mod = tmp_path / "M.mo"
34+
mod.write_text(model_firstorder_content)
1935
return mod
2036

2137

@@ -113,9 +129,33 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
113129
assert result_file.is_file()
114130

115131

132+
@skip_on_windows
133+
@skip_python_older_312
134+
def test_getSolutions_docker(model_firstorder_content):
135+
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
136+
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
137+
138+
modelpath = omc.omcpath_tempdir() / 'M.mo'
139+
modelpath.write_text(model_firstorder_content)
140+
141+
file_path = pathlib.Path(modelpath)
142+
mod = OMPython.ModelicaSystem(
143+
fileName=file_path,
144+
modelName="M",
145+
omc_process=omc.omc_process,
146+
)
147+
148+
_run_getSolutions(mod)
149+
150+
116151
def test_getSolutions(model_firstorder):
117152
filePath = model_firstorder.as_posix()
118153
mod = OMPython.ModelicaSystem(filePath, "M")
154+
155+
_run_getSolutions(mod)
156+
157+
158+
def _run_getSolutions(mod):
119159
x0 = 1
120160
a = -1
121161
tau = -1 / a

0 commit comments

Comments
 (0)