|
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 | + |
8 | 14 |
|
9 | 15 | @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 |
13 | 18 | Real x(start = 1, fixed = true); |
14 | 19 | parameter Real a = -1; |
15 | 20 | equation |
16 | 21 | der(x) = x*a; |
17 | 22 | end M; |
18 | 23 | """) |
| 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) |
19 | 30 | return mod |
20 | 31 |
|
21 | 32 |
|
@@ -113,9 +124,32 @@ def test_customBuildDirectory(tmp_path, model_firstorder): |
113 | 124 | assert result_file.is_file() |
114 | 125 |
|
115 | 126 |
|
| 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 | + |
116 | 145 | def test_getSolutions(model_firstorder): |
117 | 146 | filePath = model_firstorder.as_posix() |
118 | 147 | mod = OMPython.ModelicaSystem(filePath, "M") |
| 148 | + |
| 149 | + _run_getSolutions(mod) |
| 150 | + |
| 151 | + |
| 152 | +def _run_getSolutions(mod): |
119 | 153 | x0 = 1 |
120 | 154 | a = -1 |
121 | 155 | tau = -1 / a |
|
0 commit comments