Skip to content

Commit 80f5c96

Browse files
committed
[test_ModelicaSystem] include test of ModelicaSystem using docker
1 parent 57c21cf commit 80f5c96

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

tests/test_ModelicaSystem.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
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+
814

915
@pytest.fixture
10-
def model_firstorder(tmp_path):
11-
mod = tmp_path / "M.mo"
12-
mod.write_text("""model M
16+
def model_firstorder_content():
17+
return ("""model M
1318
Real x(start = 1, fixed = true);
1419
parameter Real a = -1;
1520
equation
1621
der(x) = x*a;
1722
end M;
1823
""")
24+
25+
26+
@pytest.fixture
27+
def model_firstorder(tmp_path, model_firstorder_content):
28+
mod = tmp_path / "M.mo"
29+
mod.write_text(model_firstorder_content)
1930
return mod
2031

2132

@@ -113,9 +124,32 @@ def test_customBuildDirectory(tmp_path, model_firstorder):
113124
assert result_file.is_file()
114125

115126

127+
@skip_on_windows
128+
def test_getSolutions_docker(model_firstorder_content):
129+
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
130+
omc = OMPython.OMCSessionZMQ(omc_process=omcp)
131+
132+
modelpath = omc.omcpath_tempdir() / 'M.mo'
133+
modelpath.write_text(model_firstorder_content)
134+
135+
file_path = pathlib.Path(modelpath)
136+
mod = OMPython.ModelicaSystem(
137+
fileName=file_path,
138+
modelName="M",
139+
omc_process=omc.omc_process,
140+
)
141+
142+
_run_getSolutions(mod)
143+
144+
116145
def test_getSolutions(model_firstorder):
117146
filePath = model_firstorder.as_posix()
118147
mod = OMPython.ModelicaSystem(filePath, "M")
148+
149+
_run_getSolutions(mod)
150+
151+
152+
def _run_getSolutions(mod):
119153
x0 = 1
120154
a = -1
121155
tau = -1 / a

0 commit comments

Comments
 (0)