Skip to content

Commit 72047f3

Browse files
committed
[test_ModelicaSystem] include test of ModelicaSystem using docker
1 parent df2a9ee commit 72047f3

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

@@ -112,9 +128,33 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
112128
assert result_file.is_file()
113129

114130

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

0 commit comments

Comments
 (0)