|
2 | 2 | import os |
3 | 3 | import pathlib |
4 | 4 | import pytest |
| 5 | +import sys |
5 | 6 | import tempfile |
6 | 7 | import numpy as np |
7 | 8 |
|
| 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 | + |
8 | 19 |
|
9 | 20 | @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 |
13 | 23 | Real x(start = 1, fixed = true); |
14 | 24 | parameter Real a = -1; |
15 | 25 | equation |
16 | 26 | der(x) = x*a; |
17 | 27 | end M; |
18 | 28 | """) |
| 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) |
19 | 35 | return mod |
20 | 36 |
|
21 | 37 |
|
@@ -113,9 +129,33 @@ def test_customBuildDirectory(tmp_path, model_firstorder): |
113 | 129 | assert result_file.is_file() |
114 | 130 |
|
115 | 131 |
|
| 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 | + |
116 | 151 | def test_getSolutions(model_firstorder): |
117 | 152 | filePath = model_firstorder.as_posix() |
118 | 153 | mod = OMPython.ModelicaSystem(filePath, "M") |
| 154 | + |
| 155 | + _run_getSolutions(mod) |
| 156 | + |
| 157 | + |
| 158 | +def _run_getSolutions(mod): |
119 | 159 | x0 = 1 |
120 | 160 | a = -1 |
121 | 161 | tau = -1 / a |
|
0 commit comments