Skip to content

Commit 091c7ad

Browse files
authored
Merge branch 'master' into fmiregression
2 parents 13f3487 + 62771af commit 091c7ad

File tree

9 files changed

+81
-90
lines changed

9 files changed

+81
-90
lines changed

.github/workflows/FMITest.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
verbose: true
5252
emoji: true
5353
job-summary: true
54-
custom-arguments: 'test_FMIRegression.py -v'
54+
custom-arguments: 'tests/test_FMIRegression.py -v'
5555
click-to-expand: true
5656
report-title: 'FMI Test Report'
57-

.github/workflows/Test.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
version: ${{ matrix.omc-version }}
2525
packages: |
2626
omc
27+
libraries: |
28+
'Modelica 4.0.0'
2729
2830
- run: "omc --version"
2931

@@ -37,10 +39,19 @@ jobs:
3739
- name: Install dependencies
3840
run: |
3941
python -m pip install --upgrade pip
40-
pip install future pyparsing numpy psutil pyzmq
42+
pip install future pyparsing numpy psutil pyzmq pytest pytest-md pytest-emoji
4143
42-
- name: Test OMPython
43-
run: |
44-
python -m unittest tests/test_ModelicaSystem.py
45-
python -m unittest tests/test_OMParser.py
46-
python -m unittest tests/test_ZMQ.py
44+
- name: Set timezone
45+
uses: szenius/set-timezone@v1.2
46+
with:
47+
timezoneLinux: 'Europe/Berlin'
48+
49+
- name: Run pytest
50+
uses: pavelzw/pytest-action@v2
51+
with:
52+
verbose: true
53+
emoji: true
54+
job-summary: true
55+
custom-arguments: '-v'
56+
click-to-expand: true
57+
report-title: 'Test Report'

.jenkins/python2/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

.jenkins/python3/Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

Jenkinsfile

Lines changed: 0 additions & 49 deletions
This file was deleted.

OMPython/__init__.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -798,18 +798,14 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
798798
Note: If the model file is not in the current working directory, then the path where file is located must be included together with file name. Besides, if the Modelica model contains several different models within the same package, then in order to build the specific model, in second argument, user must put the package name with dot(.) followed by specific model name.
799799
ex: myModel = ModelicaSystem("ModelicaModel.mo", "modelName")
800800
"""
801-
802801
if fileName is None and modelName is None and not lmodel: # all None
803802
if useCorba:
804803
self.getconn = OMCSession()
805804
else:
806805
self.getconn = OMCSessionZMQ()
807806
return
808807

809-
if fileName is None:
810-
return "File does not exist"
811808
self.tree = None
812-
813809
self.quantitiesList=[]
814810
self.paramlist={}
815811
self.inputlist={}
@@ -830,6 +826,10 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
830826
else:
831827
self.getconn = OMCSessionZMQ()
832828

829+
## needed for properly deleting the OMCSessionZMQ
830+
self._omc_log_file = self.getconn._omc_log_file
831+
self._omc_process = self.getconn._omc_process
832+
833833
## set commandLineOptions if provided by users
834834
if commandLineOptions is not None:
835835
exp="".join(["setCommandLineOptions(","\"",commandLineOptions,"\"",")"])
@@ -846,7 +846,7 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
846846
self.resultfile="" # for storing result file
847847
self.variableFilter = variableFilter
848848

849-
if not os.path.exists(self.fileName): # if file does not eixt
849+
if fileName is not None and not os.path.exists(self.fileName): # if file does not eixt
850850
print("File Error:" + os.path.abspath(self.fileName) + " does not exist!!!")
851851
return
852852

@@ -856,19 +856,37 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
856856
self.getconn.sendExpression("setCommandLineOptions(\"--linearizationDumpLanguage=python\")")
857857
self.getconn.sendExpression("setCommandLineOptions(\"--generateSymbolicLinearization\")")
858858

859-
self.loadingModel()
859+
self.setTempDirectory()
860+
861+
if fileName is not None:
862+
self.loadFile()
863+
864+
## allow directly loading models from MSL without fileName
865+
if fileName is None and modelName is not None:
866+
self.loadLibrary()
867+
868+
self.buildModel()
860869

861870
def __del__(self):
862871
OMCSessionBase.__del__(self)
863872

864-
# for loading file/package, loading model and building model
865-
def loadingModel(self):
873+
def setCommandLineOptions(self):
874+
## set commandLineOptions if provided by users
875+
if commandLineOptions is not None:
876+
exp="".join(["setCommandLineOptions(","\"",commandLineOptions,"\"",")"])
877+
cmdexp = self.getconn.sendExpression(exp)
878+
if not cmdexp:
879+
return print(self.getconn.sendExpression("getErrorString()"))
880+
881+
def loadFile(self):
866882
# load file
867883
loadFileExp="".join(["loadFile(","\"",self.fileName,"\"",")"]).replace("\\","/")
868884
loadMsg = self.getconn.sendExpression(loadFileExp)
869885
if not loadMsg:
870886
return print(self.getconn.sendExpression("getErrorString()"))
871887

888+
# for loading file/package, loading model and building model
889+
def loadLibrary(self):
872890
# load Modelica standard libraries or Modelica files if needed
873891
for element in self.lmodel:
874892
if element is not None:
@@ -892,6 +910,7 @@ def loadingModel(self):
892910
if loadmodelError:
893911
print(loadmodelError)
894912

913+
def setTempDirectory(self):
895914
# create a unique temp directory for each session and build the model in that directory
896915
self.tempdir = tempfile.mkdtemp()
897916
if not os.path.exists(self.tempdir):
@@ -900,7 +919,8 @@ def loadingModel(self):
900919
exp="".join(["cd(","\"",self.tempdir,"\"",")"]).replace("\\","/")
901920
self.getconn.sendExpression(exp)
902921

903-
self.buildModel()
922+
def getWorkDirectory(self):
923+
return self.tempdir
904924

905925
def buildModel(self, variableFilter=None):
906926
if variableFilter is not None:

tests/test_FMIExport.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import OMPython
2+
import unittest
3+
import tempfile, shutil, os
4+
5+
class testFMIExport(unittest.TestCase):
6+
def __init__(self, *args, **kwargs):
7+
super(testFMIExport, self).__init__(*args, **kwargs)
8+
self.tmp = ""
9+
10+
def __del__(self):
11+
shutil.rmtree(self.tmp, ignore_errors=True)
12+
13+
def testCauerLowPassAnalog(self):
14+
print("testing Cauer")
15+
mod = OMPython.ModelicaSystem(modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog", lmodel="Modelica")
16+
self.tmp = mod.getWorkDirectory()
17+
18+
fmu = mod.convertMo2Fmu(fileNamePrefix="CauerLowPassAnalog")
19+
self.assertEqual(True, os.path.exists(fmu))
20+
21+
def testDrumBoiler(self):
22+
print("testing DrumBoiler")
23+
mod = OMPython.ModelicaSystem(modelName="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler", lmodel="Modelica")
24+
self.tmp = mod.getWorkDirectory()
25+
26+
fmu = mod.convertMo2Fmu(fileNamePrefix="DrumBoiler")
27+
self.assertEqual(True, os.path.exists(fmu))
28+
29+
if __name__ == '__main__':
30+
unittest.main()

tests/test_ModelicaSystem.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ def __del__(self):
1919

2020
def testModelicaSystemLoop(self):
2121
def worker():
22-
origDir = os.getcwd()
23-
os.chdir(self.tmp)
24-
m = OMPython.ModelicaSystem("M.mo", "M")
22+
filePath = os.path.join(self.tmp,"M.mo").replace("\\", "/")
23+
m = OMPython.ModelicaSystem(filePath, "M")
2524
m.simulate()
2625
m.convertMo2Fmu(fmuType="me")
27-
os.chdir(origDir)
2826
for _ in range(10):
2927
worker()
3028

tests/test_docker.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import OMPython
22
import unittest
33
import tempfile, shutil, os
4+
import pytest
45

56
class DockerTester(unittest.TestCase):
7+
@pytest.mark.skip(reason="This test would fail")
68
def testDocker(self):
79
om = OMPython.OMCSessionZMQ(docker="openmodelica/openmodelica:v1.16.1-minimal")
810
assert(om.sendExpression("getVersion()") == "OpenModelica 1.16.1")

0 commit comments

Comments
 (0)