-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathtest_ZMQ.py
More file actions
66 lines (44 loc) · 1.62 KB
/
test_ZMQ.py
File metadata and controls
66 lines (44 loc) · 1.62 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
import pathlib
import os
import pytest
import OMPython
@pytest.fixture
def model_time_str():
return """model M
Real r = time;
end M;
"""
@pytest.fixture
def omcs(tmp_path):
origDir = pathlib.Path.cwd()
os.chdir(tmp_path)
omcs = OMPython.OMCSessionLocal()
os.chdir(origDir)
return omcs
def testHelloWorld(omcs):
assert omcs.sendExpression('"HelloWorld!"') == "HelloWorld!"
def test_Translate(omcs, model_time_str):
assert omcs.sendExpression(model_time_str) == ("M",)
assert omcs.sendExpression('translateModel(M)') is True
def test_Simulate(omcs, model_time_str):
assert omcs.sendExpression(f'loadString("{model_time_str}")') is True
omcs.sendExpression('res:=simulate(M, stopTime=2.0)')
assert omcs.sendExpression('res.resultFile')
def test_sendExpression(omcs):
assert omcs.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
assert omcs.sendExpression('"HelloWorld!"', parsed=True) == 'HelloWorld!'
def test_omcprocessport_execute(omcs):
port = omcs.get_port()
omcs2 = OMPython.OMCSessionPort(omc_port=port)
# run 1
assert omcs.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
# run 2
assert omcs2.sendExpression('"HelloWorld!"', parsed=False) == '"HelloWorld!"\n'
del omcs2
def test_omcprocessport_simulate(omcs, model_time_str):
port = omcs.get_port()
omcs2 = OMPython.OMCSessionPort(omc_port=port)
assert omcs2.sendExpression(f'loadString("{model_time_str}")') is True
omcs2.sendExpression('res:=simulate(M, stopTime=2.0)')
assert omcs2.sendExpression('res.resultFile') != ""
del omcs2