Skip to content

Commit ca7ffaf

Browse files
committed
Remove unittest
1 parent 87b0a38 commit ca7ffaf

13 files changed

+683
-759
lines changed

tests/__init__.py

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

tests/test_ArrayDimension.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
import OMPython
2-
import tempfile
3-
import shutil
4-
import os
52

63

7-
# do not change the prefix class name, the class name should have prefix "Test"
8-
# according to the documenation of pytest
9-
class Test_ArrayDimension:
10-
def test_ArrayDimension(self):
11-
omc = OMPython.OMCSessionZMQ()
4+
def test_ArrayDimension(tmp_path):
5+
omc = OMPython.OMCSessionZMQ()
126

13-
# create a temp dir for each session
14-
tempdir = tempfile.mkdtemp()
15-
if not os.path.exists(tempdir):
16-
return print(tempdir, " cannot be created")
7+
omc.sendExpression(f'cd("{tmp_path.as_posix()}")')
178

18-
tempdirExp = "".join(["cd(", "\"", tempdir, "\"", ")"]).replace("\\", "/")
19-
omc.sendExpression(tempdirExp)
9+
omc.sendExpression('loadString("model A Integer x[5+1,1+6]; end A;")')
10+
omc.sendExpression("getErrorString()")
2011

21-
omc.sendExpression("loadString(\"model A Integer x[5+1,1+6]; end A;\")")
22-
omc.sendExpression("getErrorString()")
12+
result = omc.sendExpression("getComponents(A)")
13+
assert result[0][-1] == (6, 7), "array dimension does not match"
2314

24-
result = omc.sendExpression("getComponents(A)")
25-
assert result[0][-1] == (6, 7), f"array dimension does not match the expected value. Got: {result[0][-1]}, Expected: {(6, 7)}"
15+
omc.sendExpression('loadString("model A Integer y = 5; Integer x[y+1,1+9]; end A;")')
16+
omc.sendExpression("getErrorString()")
2617

27-
omc.sendExpression("loadString(\"model A Integer y = 5; Integer x[y+1,1+9]; end A;\")")
28-
omc.sendExpression("getErrorString()")
29-
30-
result = omc.sendExpression("getComponents(A)")
31-
assert result[-1][-1] == ('y+1', 10), f"array dimension does not match the expected value. Got: {result[-1][-1]}, Expected: {('y+1', 10)}"
32-
33-
omc.__del__()
34-
shutil.rmtree(tempdir, ignore_errors=True)
18+
result = omc.sendExpression("getComponents(A)")
19+
assert result[-1][-1] == ('y+1', 10), "array dimension does not match"

tests/test_FMIExport.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
import OMPython
2-
import unittest
32
import shutil
43
import os
54

65

7-
class testFMIExport(unittest.TestCase):
8-
def __init__(self, *args, **kwargs):
9-
super(testFMIExport, self).__init__(*args, **kwargs)
10-
self.tmp = ""
11-
12-
def __del__(self):
13-
shutil.rmtree(self.tmp, ignore_errors=True)
14-
15-
def testCauerLowPassAnalog(self):
16-
print("testing Cauer")
17-
mod = OMPython.ModelicaSystem(modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
18-
lmodel=["Modelica"])
19-
self.tmp = mod.getWorkDirectory()
20-
6+
def test_CauerLowPassAnalog():
7+
mod = OMPython.ModelicaSystem(modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
8+
lmodel=["Modelica"])
9+
tmp = mod.getWorkDirectory()
10+
try:
2111
fmu = mod.convertMo2Fmu(fileNamePrefix="CauerLowPassAnalog")
22-
self.assertEqual(True, os.path.exists(fmu))
12+
assert os.path.exists(fmu)
13+
finally:
14+
shutil.rmtree(tmp, ignore_errors=True)
2315

24-
def testDrumBoiler(self):
25-
print("testing DrumBoiler")
26-
mod = OMPython.ModelicaSystem(modelName="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler", lmodel=["Modelica"])
27-
self.tmp = mod.getWorkDirectory()
2816

17+
def test_DrumBoiler():
18+
mod = OMPython.ModelicaSystem(modelName="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler", lmodel=["Modelica"])
19+
tmp = mod.getWorkDirectory()
20+
try:
2921
fmu = mod.convertMo2Fmu(fileNamePrefix="DrumBoiler")
30-
self.assertEqual(True, os.path.exists(fmu))
31-
32-
33-
if __name__ == '__main__':
34-
unittest.main()
22+
assert os.path.exists(fmu)
23+
finally:
24+
shutil.rmtree(tmp, ignore_errors=True)

tests/test_FMIRegression.py

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
11
import OMPython
22
import tempfile
3+
import pathlib
34
import shutil
45
import os
56

67

7-
# do not change the prefix class name, the class name should have prefix "Test"
8-
# according to the documenation of pytest
9-
class Test_FMIRegression:
8+
def buildModelFMU(modelName):
9+
omc = OMPython.OMCSessionZMQ()
1010

11-
def buildModelFMU(self, modelName):
12-
omc = OMPython.OMCSessionZMQ()
13-
14-
# create a temp dir for each session
15-
tempdir = tempfile.mkdtemp()
16-
if not os.path.exists(tempdir):
17-
return print(tempdir, " cannot be created")
18-
19-
tempdirExp = "".join(["cd(", "\"", tempdir, "\"", ")"]).replace("\\", "/")
20-
omc.sendExpression(tempdirExp)
11+
tempdir = pathlib.Path(tempfile.mkdtemp())
12+
try:
13+
omc.sendExpression(f'cd("{tempdir.as_posix()}")')
2114

2215
omc.sendExpression("loadModel(Modelica)")
2316
omc.sendExpression("getErrorString()")
2417

2518
fileNamePrefix = modelName.split(".")[-1]
26-
exp = "buildModelFMU(" + modelName + ", fileNamePrefix=\"" + fileNamePrefix + "\"" + ")"
27-
19+
exp = f'buildModelFMU({modelName}, fileNamePrefix="{fileNamePrefix}")'
2820
fmu = omc.sendExpression(exp)
2921
assert os.path.exists(fmu)
30-
31-
omc.__del__()
22+
finally:
23+
del omc
3224
shutil.rmtree(tempdir, ignore_errors=True)
3325

34-
def test_Modelica_Blocks_Examples_Filter(self):
35-
self.buildModelFMU("Modelica.Blocks.Examples.Filter")
3626

37-
def test_Modelica_Blocks_Examples_RealNetwork1(self):
38-
self.buildModelFMU("Modelica.Blocks.Examples.RealNetwork1")
27+
def test_Modelica_Blocks_Examples_Filter():
28+
buildModelFMU("Modelica.Blocks.Examples.Filter")
29+
30+
31+
def test_Modelica_Blocks_Examples_RealNetwork1():
32+
buildModelFMU("Modelica.Blocks.Examples.RealNetwork1")
33+
34+
35+
def test_Modelica_Electrical_Analog_Examples_CauerLowPassAnalog():
36+
buildModelFMU("Modelica.Electrical.Analog.Examples.CauerLowPassAnalog")
37+
38+
39+
def test_Modelica_Electrical_Digital_Examples_FlipFlop():
40+
buildModelFMU("Modelica.Electrical.Digital.Examples.FlipFlop")
41+
42+
43+
def test_Modelica_Mechanics_Rotational_Examples_FirstGrounded():
44+
buildModelFMU("Modelica.Mechanics.Rotational.Examples.FirstGrounded")
45+
46+
47+
def test_Modelica_Mechanics_Rotational_Examples_CoupledClutches():
48+
buildModelFMU("Modelica.Mechanics.Rotational.Examples.CoupledClutches")
49+
3950

40-
def test_Modelica_Electrical_Analog_Examples_CauerLowPassAnalog(self):
41-
self.buildModelFMU("Modelica.Electrical.Analog.Examples.CauerLowPassAnalog")
51+
def test_Modelica_Mechanics_MultiBody_Examples_Elementary_DoublePendulum():
52+
buildModelFMU("Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum")
4253

43-
def test_Modelica_Electrical_Digital_Examples_FlipFlop(self):
44-
self.buildModelFMU("Modelica.Electrical.Digital.Examples.FlipFlop")
4554

46-
def test_Modelica_Mechanics_Rotational_Examples_FirstGrounded(self):
47-
self.buildModelFMU("Modelica.Mechanics.Rotational.Examples.FirstGrounded")
55+
def test_Modelica_Mechanics_MultiBody_Examples_Elementary_FreeBody():
56+
buildModelFMU("Modelica.Mechanics.MultiBody.Examples.Elementary.FreeBody")
4857

49-
def test_Modelica_Mechanics_Rotational_Examples_CoupledClutches(self):
50-
self.buildModelFMU("Modelica.Mechanics.Rotational.Examples.CoupledClutches")
5158

52-
def test_Modelica_Mechanics_MultiBody_Examples_Elementary_DoublePendulum(self):
53-
self.buildModelFMU("Modelica.Mechanics.MultiBody.Examples.Elementary.DoublePendulum")
59+
def test_Modelica_Fluid_Examples_PumpingSystem():
60+
buildModelFMU("Modelica.Fluid.Examples.PumpingSystem")
5461

55-
def test_Modelica_Mechanics_MultiBody_Examples_Elementary_FreeBody(self):
56-
self.buildModelFMU("Modelica.Mechanics.MultiBody.Examples.Elementary.FreeBody")
5762

58-
def test_Modelica_Fluid_Examples_PumpingSystem(self):
59-
self.buildModelFMU("Modelica.Fluid.Examples.PumpingSystem")
63+
def test_Modelica_Fluid_Examples_TraceSubstances_RoomCO2WithControls():
64+
buildModelFMU("Modelica.Fluid.Examples.TraceSubstances.RoomCO2WithControls")
6065

61-
def test_Modelica_Fluid_Examples_TraceSubstances_RoomCO2WithControls(self):
62-
self.buildModelFMU("Modelica.Fluid.Examples.TraceSubstances.RoomCO2WithControls")
6366

64-
def test_Modelica_Clocked_Examples_SimpleControlledDrive_ClockedWithDiscreteTextbookController(self):
65-
self.buildModelFMU("Modelica.Clocked.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController")
67+
def test_Modelica_Clocked_Examples_SimpleControlledDrive_ClockedWithDiscreteTextbookController():
68+
buildModelFMU("Modelica.Clocked.Examples.SimpleControlledDrive.ClockedWithDiscreteTextbookController")

0 commit comments

Comments
 (0)