Skip to content

Commit d4fde85

Browse files
committed
[tests] for ModelicaSystemCmd
1 parent f6ba447 commit d4fde85

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/test_ModelicaSystemCmd.py

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

0 commit comments

Comments
 (0)