-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathtest_OMCPath.py
More file actions
82 lines (58 loc) · 1.83 KB
/
test_OMCPath.py
File metadata and controls
82 lines (58 loc) · 1.83 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
import sys
import pytest
import OMPython
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_OMCProcessLocal():
omcs = OMPython.OMCSessionLocal()
_run_OMCPath_checks(omcs)
del omcs
@skip_on_windows
@skip_python_older_312
def test_OMCPath_OMCProcessDocker():
omcs = OMPython.OMCSessionDocker(docker="openmodelica/openmodelica:v1.25.0-minimal")
omversion = omcs.sendExpression("getVersion()")
assert isinstance(omversion, str) and omversion.startswith("OpenModelica")
_run_OMCPath_checks(omcs)
del omcs
@pytest.mark.skip(reason="Not able to run WSL on github")
@skip_python_older_312
def test_OMCPath_OMCProcessWSL():
omcs = OMPython.OMCSessionWSL(
wsl_omc='omc',
wsl_user='omc',
timeout=30.0,
)
_run_OMCPath_checks(omcs)
del omcs
def _run_OMCPath_checks(omcs: OMPython.OMCSessionABC):
p1 = omcs.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):
omcs = OMPython.OMCSessionLocal()
data = "abc # \\t # \" # \\n # xyz"
p1 = omcs.omcpath_tempdir()
p2 = p1 / 'test.txt'
p2.write_text(data=data)
assert data == p2.read_text()
del omcs