forked from OpenModelica/OMPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_OMCPath.py
More file actions
92 lines (66 loc) · 2.02 KB
/
test_OMCPath.py
File metadata and controls
92 lines (66 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sys
import OMPython
import pytest
skip_on_windows = pytest.mark.skipif(
sys.platform.startswith("win"),
reason="OpenModelica Docker image is Linux-only; skipping on Windows.",
)
skip_python_older_312 = pytest.mark.skipif(
sys.version_info < (3, 12),
reason="OMCPath(non-local) only working for Python >= 3.12.",
)
def test_OMCPath_OMCSessionZMQ():
om = OMPython.OMCSessionZMQ()
_run_OMCPath_checks(om)
del om
def test_OMCPath_OMCProcessLocal():
omp = OMPython.OMCProcessLocal()
om = OMPython.OMCSessionZMQ(omc_process=omp)
_run_OMCPath_checks(om)
del om
@skip_on_windows
@skip_python_older_312
def test_OMCPath_OMCProcessDocker():
omcp = OMPython.OMCProcessDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
om = OMPython.OMCSessionZMQ(omc_process=omcp)
assert om.sendExpression("getVersion()") == "OpenModelica 1.25.0"
_run_OMCPath_checks(om)
del omcp
del om
@pytest.mark.skip(reason="Not able to run WSL on github")
@skip_python_older_312
def test_OMCPath_OMCProcessWSL():
omcp = OMPython.OMCProcessWSL(
wsl_omc='omc',
wsl_user='omc',
timeout=30.0,
)
om = OMPython.OMCSessionZMQ(omc_process=omcp)
_run_OMCPath_checks(om)
del omcp
del om
def _run_OMCPath_checks(om: OMPython.OMCSessionZMQ):
p1 = om.omcpath_tempdir()
p2 = p1 / 'test'
p2.mkdir()
assert p2.is_dir()
p3 = p2 / '..' / p2.name / 'test.txt'
assert p3.is_file() is False
assert p3.write_text('test')
assert p3.is_file()
assert p3.size() > 0
p3 = p3.resolve().absolute()
assert str(p3) == str((p2 / 'test.txt').resolve().absolute())
assert p3.read_text() == "test"
assert p3.is_file()
assert p3.parent.is_dir()
p3.unlink()
assert p3.is_file() is False
def test_OMCPath_write_file(tmpdir):
om = OMPython.OMCSessionZMQ()
data = "abc # \\t # \" # \\n # xyz"
p1 = om.omcpath_tempdir()
p2 = p1 / 'test.txt'
p2.write_text(data=data)
assert data == p2.read_text()
del om