Skip to content

Commit adb9686

Browse files
committed
Add tests for potential deadlocks
The tests are based on #61
1 parent 06b956e commit adb9686

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

OMPython/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,7 @@ def simulate(self): # 11
12651265
resultfilename = self.modelName + '_res.mat'
12661266
return
12671267
else:
1268-
print("Error: application file not generated yet")
1269-
return
1268+
raise Exception("Error: application file not generated yet")
12701269
else:
12711270
if (platform.system() == "Windows"):
12721271
getExeFile = os.path.join(os.getcwd(), '{}.{}'.format(self.modelName, "exe")).replace("\\", "/")
@@ -1292,7 +1291,7 @@ def simulate(self): # 11
12921291
resultfilename = self.modelName + '_res.mat'
12931292
return
12941293
else:
1295-
print("Error: application file not generated yet")
1294+
raise Exception("Error: application file not generated yet")
12961295

12971296
# to extract simulation results
12981297
def getSolutions(self, *varList): # 12

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__all__ = ['tests.test_OMParser', 'tests.test_ZMQ']
1+
__all__ = ['tests.test_OMParser', 'tests.test_ZMQ', 'tests.test_ModelicaSystem']

tests/test_ModelicaSystem.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import OMPython
2+
import unittest
3+
import tempfile, shutil, os
4+
5+
class ModelicaSystemTester(unittest.TestCase):
6+
def __init__(self, *args, **kwargs):
7+
super(ModelicaSystemTester, self).__init__(*args, **kwargs)
8+
self.tmp = tempfile.mkdtemp(prefix='tmpOMPython.tests')
9+
with open("%s/M.mo" % self.tmp, "w") as fout:
10+
fout.write("""model M
11+
Real r = time;
12+
end M;
13+
""")
14+
def __del__(self):
15+
shutil.rmtree(self.tmp, ignore_errors=True)
16+
17+
def testModelicaSystemLoop(self):
18+
def worker():
19+
origDir = os.getcwd()
20+
os.chdir(self.tmp)
21+
m = OMPython.ModelicaSystem("M.mo", "M")
22+
m.simulate()
23+
os.chdir(origDir)
24+
for _ in range(10):
25+
worker()
26+
27+
if __name__ == '__main__':
28+
unittest.main()

0 commit comments

Comments
 (0)