Skip to content

Commit 88b619d

Browse files
committed
[tests] for ModelicaSystemCmd
1 parent 5b1b250 commit 88b619d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_ModelicaSystemCmd.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import OMPython
2+
import pathlib
3+
import shutil
4+
import tempfile
5+
import unittest
6+
7+
8+
import logging
9+
logger = logging.getLogger(__name__)
10+
logging.basicConfig(level=logging.DEBUG)
11+
12+
13+
class ModelicaSystemCmdTester(unittest.TestCase):
14+
def __init__(self, *args, **kwargs):
15+
super(ModelicaSystemCmdTester, self).__init__(*args, **kwargs)
16+
self.tmp = pathlib.Path(tempfile.mkdtemp(prefix='tmpOMPython.tests'))
17+
self.model = self.tmp / "M.mo"
18+
with open(self.model, "w") as fout:
19+
fout.write("""model M
20+
Real x(start = 1, fixed = true);
21+
parameter Real a = -1;
22+
equation
23+
der(x) = x*a;
24+
end M;
25+
""")
26+
self.mod = OMPython.ModelicaSystem(self.model.as_posix(), "M")
27+
28+
def __del__(self):
29+
shutil.rmtree(self.tmp, ignore_errors=True)
30+
31+
def test_simflags(self):
32+
mscmd = OMPython.ModelicaSystemCmd(runpath=self.mod.tempdir, modelname=self.mod.modelName)
33+
mscmd.args_set(args={"noEventEmit": None, "noRestart": None, "override": {'b': 2}})
34+
mscmd.args_set(args=mscmd.parse_simflags(simflags="-noEventEmit -noRestart -override=a=1,x=3"))
35+
36+
logger.info(mscmd.get_cmd())
37+
38+
assert mscmd.get_cmd() == [mscmd.get_exe().as_posix(), '-noEventEmit', '-noRestart', '-override=b=2,a=1,x=3']
39+
40+
41+
if __name__ == '__main__':
42+
unittest.main()

0 commit comments

Comments
 (0)