Skip to content

Commit 4b4f9f3

Browse files
committed
Fix flake8 warnings in tests
1 parent a4876b8 commit 4b4f9f3

7 files changed

Lines changed: 48 additions & 39 deletions

tests/test_ArrayDimension.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import OMPython
2-
import tempfile, shutil, os
3-
import pytest
2+
import tempfile
3+
import shutil
4+
import os
45

56

6-
"""
7-
do not change the prefix class name, the class name should have prefix "Test"
8-
according to the documenation of pytest
9-
"""
7+
# do not change the prefix class name, the class name should have prefix "Test"
8+
# according to the documenation of pytest
109
class Test_ArrayDimension:
11-
1210
def test_ArrayDimension(self):
1311
omc = OMPython.OMCSessionZMQ()
1412

15-
## create a temp dir for each session
13+
# create a temp dir for each session
1614
tempdir = tempfile.mkdtemp()
1715
if not os.path.exists(tempdir):
1816
return print(tempdir, " cannot be created")
1917

20-
tempdirExp="".join(["cd(","\"",tempdir,"\"",")"]).replace("\\","/")
18+
tempdirExp = "".join(["cd(", "\"", tempdir, "\"", ")"]).replace("\\", "/")
2119
omc.sendExpression(tempdirExp)
2220

2321
omc.sendExpression("loadString(\"model A Integer x[5+1,1+6]; end A;\")")
2422
omc.sendExpression("getErrorString()")
2523

2624
result = omc.sendExpression("getComponents(A)")
27-
assert result[0][-1] == (6,7), f"array dimension does not match the expected value. Got: {result[0][-1]}, Expected: {(6, 7)}"
25+
assert result[0][-1] == (6, 7), f"array dimension does not match the expected value. Got: {result[0][-1]}, Expected: {(6, 7)}"
2826

2927
omc.sendExpression("loadString(\"model A Integer y = 5; Integer x[y+1,1+9]; end A;\")")
3028
omc.sendExpression("getErrorString()")
@@ -33,5 +31,4 @@ def test_ArrayDimension(self):
3331
assert result[-1][-1] == ('y+1', 10), f"array dimension does not match the expected value. Got: {result[-1][-1]}, Expected: {('y+1', 10)}"
3432

3533
omc.__del__()
36-
shutil.rmtree(tempdir, ignore_errors= True)
37-
34+
shutil.rmtree(tempdir, ignore_errors=True)

tests/test_FMIExport.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import OMPython
22
import unittest
3-
import tempfile, shutil, os
3+
import shutil
4+
import os
5+
46

57
class testFMIExport(unittest.TestCase):
68
def __init__(self, *args, **kwargs):
@@ -26,5 +28,6 @@ def testDrumBoiler(self):
2628
fmu = mod.convertMo2Fmu(fileNamePrefix="DrumBoiler")
2729
self.assertEqual(True, os.path.exists(fmu))
2830

31+
2932
if __name__ == '__main__':
3033
unittest.main()

tests/test_FMIRegression.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
import OMPython
2-
import tempfile, shutil, os
3-
import pytest
2+
import tempfile
3+
import shutil
4+
import os
45

56

6-
"""
7-
do not change the prefix class name, the class name should have prefix "Test"
8-
according to the documenation of pytest
9-
"""
7+
# do not change the prefix class name, the class name should have prefix "Test"
8+
# according to the documenation of pytest
109
class Test_FMIRegression:
1110

1211
def buildModelFMU(self, modelName):
1312
omc = OMPython.OMCSessionZMQ()
1413

15-
## create a temp dir for each session
14+
# create a temp dir for each session
1615
tempdir = tempfile.mkdtemp()
1716
if not os.path.exists(tempdir):
1817
return print(tempdir, " cannot be created")
1918

20-
tempdirExp="".join(["cd(","\"",tempdir,"\"",")"]).replace("\\","/")
19+
tempdirExp = "".join(["cd(", "\"", tempdir, "\"", ")"]).replace("\\", "/")
2120
omc.sendExpression(tempdirExp)
2221

2322
omc.sendExpression("loadModel(Modelica)")
2423
omc.sendExpression("getErrorString()")
2524

2625
fileNamePrefix = modelName.split(".")[-1]
27-
exp = "buildModelFMU(" + modelName + ", fileNamePrefix=\"" + fileNamePrefix + "\"" + ")"
26+
exp = "buildModelFMU(" + modelName + ", fileNamePrefix=\"" + fileNamePrefix + "\"" + ")"
2827

2928
fmu = omc.sendExpression(exp)
30-
assert True == os.path.exists(fmu)
29+
assert os.path.exists(fmu)
3130

3231
omc.__del__()
33-
shutil.rmtree(tempdir, ignore_errors= True)
32+
shutil.rmtree(tempdir, ignore_errors=True)
3433

3534
def test_Modelica_Blocks_Examples_Filter(self):
3635
self.buildModelFMU("Modelica.Blocks.Examples.Filter")

tests/test_ModelicaSystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import OMPython
22
import unittest
3-
import tempfile, shutil, os
3+
import tempfile
4+
import shutil
5+
import os
6+
47

58
class ModelicaSystemTester(unittest.TestCase):
69
def __init__(self, *args, **kwargs):
@@ -20,12 +23,13 @@ def __del__(self):
2023

2124
def testModelicaSystemLoop(self):
2225
def worker():
23-
filePath = os.path.join(self.tmp,"M.mo").replace("\\", "/")
26+
filePath = os.path.join(self.tmp, "M.mo").replace("\\", "/")
2427
m = OMPython.ModelicaSystem(filePath, "M")
2528
m.simulate()
2629
m.convertMo2Fmu(fmuType="me")
2730
for _ in range(10):
2831
worker()
2932

33+
3034
if __name__ == '__main__':
3135
unittest.main()

tests/test_ZMQ.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import OMPython
22
import unittest
3-
import tempfile, shutil, os
3+
import tempfile
4+
import shutil
5+
import os
6+
47

58
class ZMQTester(unittest.TestCase):
69
def __init__(self, *args, **kwargs):
@@ -16,10 +19,10 @@ def __init__(self, *args, **kwargs):
1619

1720
def __del__(self):
1821
shutil.rmtree(self.tmp, ignore_errors=True)
19-
del(self.om)
22+
del self.om
2023

2124
def clean(self):
22-
del(self.om)
25+
del self.om
2326
self.om = None
2427

2528
def testHelloWorld(self):
@@ -37,5 +40,6 @@ def testSimulate(self):
3740
self.assertNotEqual("", self.om.sendExpression('res.resultFile'))
3841
self.clean()
3942

43+
4044
if __name__ == '__main__':
4145
unittest.main()

tests/test_docker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import OMPython
22
import unittest
3-
import tempfile, shutil, os
43
import pytest
54

5+
66
class DockerTester(unittest.TestCase):
77
@pytest.mark.skip(reason="This test would fail")
88
def testDocker(self):
99
om = OMPython.OMCSessionZMQ(docker="openmodelica/openmodelica:v1.16.1-minimal")
10-
assert(om.sendExpression("getVersion()") == "OpenModelica 1.16.1")
10+
assert om.sendExpression("getVersion()") == "OpenModelica 1.16.1"
1111
omInner = OMPython.OMCSessionZMQ(dockerContainer=om._dockerCid)
12-
assert(omInner.sendExpression("getVersion()") == "OpenModelica 1.16.1")
12+
assert omInner.sendExpression("getVersion()") == "OpenModelica 1.16.1"
1313
om2 = OMPython.OMCSessionZMQ(docker="openmodelica/openmodelica:v1.16.1-minimal", port=11111)
14-
assert(om2.sendExpression("getVersion()") == "OpenModelica 1.16.1")
15-
del(om2)
16-
del(omInner)
17-
del(om)
14+
assert om2.sendExpression("getVersion()") == "OpenModelica 1.16.1"
15+
del om2
16+
del omInner
17+
del om
1818

1919

2020
if __name__ == '__main__':

tests/test_linearization.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import OMPython
2-
import tempfile, shutil, os
3-
import pytest
2+
import tempfile
3+
import shutil
4+
import os
5+
46

57
class Test_Linearization:
68
def loadModel(self):
@@ -26,7 +28,7 @@ def __del__(self):
2628

2729
def test_example(self):
2830
self.loadModel()
29-
filePath = os.path.join(self.tmp,"linearTest.mo").replace("\\", "/")
31+
filePath = os.path.join(self.tmp, "linearTest.mo").replace("\\", "/")
3032
print(filePath)
3133
mod = OMPython.ModelicaSystem(filePath, "linearTest")
3234
[A, B, C, D] = mod.linearize()

0 commit comments

Comments
 (0)