Skip to content

Commit 198ab3d

Browse files
syntronadeas31
andauthored
D007 define unit test for v4.0.0 compatibility layer (#438)
* (D006) small fixes in ModelicaSystem [ModelicaSystemABC] reorder code in __init__() [ModelicaSystem*] linter fixes * (D008) add v4.0.0 compatibility layer [OMTypedParser] compatibility layer [__init__/OMCSession] prepare compatibility layer [ModelicaSystem] define as compatibility layer [ModelicaSystemCmd] define as compatibility layer * (D007) define unittest / workflow for v4.0.0 add workflow to run unittests in ./tests tests from v4.0.0 fix test_linearization from v4.0.0 flake8 error: test_linearization.py:71:5: E741 ambiguous variable name 'l' this was fixed in: 'update usage of flake8 (#357)' (SHA1: 70cb446) fix test_ModelicaSystem - needed adaptions: * convert OMCPath to pathlib.Path * use correct exceptions define test workflows for v400 * cleanup github workflow - use the default one to run all tests * fix name for v4.0.0 test - test*s*_v400 * update name / title for unittest tests_v400 * Increase timeout to 45 minutes --------- Co-authored-by: Adeel Asghar <adeel.asghar@liu.se>
1 parent e18ad45 commit 198ab3d

14 files changed

Lines changed: 902 additions & 3 deletions

.github/workflows/Test.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
jobs:
1212
test:
1313
runs-on: ${{ matrix.os }}
14-
timeout-minutes: 30
14+
timeout-minutes: 45
1515
strategy:
1616
matrix:
1717
# test for:
@@ -73,10 +73,20 @@ jobs:
7373
verbose: true
7474
emoji: true
7575
job-summary: true
76-
custom-arguments: '-v'
76+
custom-arguments: '-v ./tests'
7777
click-to-expand: true
7878
report-title: 'Test Report'
7979

80+
- name: Run pytest based on v4.0.0 compatibility layer
81+
uses: pavelzw/pytest-action@v2
82+
with:
83+
verbose: true
84+
emoji: true
85+
job-summary: true
86+
custom-arguments: '-v ./tests_v400'
87+
click-to-expand: true
88+
report-title: 'Test Report (v4.0.0 compatibility layer)'
89+
8090
Publish:
8191
name: Publish to PyPI
8292
runs-on: ${{ matrix.os }}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ repos:
3333
hooks:
3434
- id: mypy
3535
args: []
36-
exclude: tests/
36+
exclude: 'test|test_v400'
3737
additional_dependencies:
3838
- pyparsing
3939
- types-psutil

tests_v400/__init__.py

Whitespace-only changes.

tests_v400/test_ArrayDimension.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import OMPython
2+
3+
4+
def test_ArrayDimension(tmp_path):
5+
omc = OMPython.OMCSessionZMQ()
6+
7+
omc.sendExpression(f'cd("{tmp_path.as_posix()}")')
8+
9+
omc.sendExpression('loadString("model A Integer x[5+1,1+6]; end A;")')
10+
omc.sendExpression("getErrorString()")
11+
12+
result = omc.sendExpression("getComponents(A)")
13+
assert result[0][-1] == (6, 7), "array dimension does not match"
14+
15+
omc.sendExpression('loadString("model A Integer y = 5; Integer x[y+1,1+9]; end A;")')
16+
omc.sendExpression("getErrorString()")
17+
18+
result = omc.sendExpression("getComponents(A)")
19+
assert result[-1][-1] == ('y+1', 10), "array dimension does not match"

tests_v400/test_FMIExport.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import OMPython
2+
import shutil
3+
import os
4+
5+
6+
def test_CauerLowPassAnalog():
7+
mod = OMPython.ModelicaSystem(modelName="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog",
8+
lmodel=["Modelica"])
9+
tmp = mod.getWorkDirectory()
10+
try:
11+
fmu = mod.convertMo2Fmu(fileNamePrefix="CauerLowPassAnalog")
12+
assert os.path.exists(fmu)
13+
finally:
14+
shutil.rmtree(tmp, ignore_errors=True)
15+
16+
17+
def test_DrumBoiler():
18+
mod = OMPython.ModelicaSystem(modelName="Modelica.Fluid.Examples.DrumBoiler.DrumBoiler", lmodel=["Modelica"])
19+
tmp = mod.getWorkDirectory()
20+
try:
21+
fmu = mod.convertMo2Fmu(fileNamePrefix="DrumBoiler")
22+
assert os.path.exists(fmu)
23+
finally:
24+
shutil.rmtree(tmp, ignore_errors=True)

0 commit comments

Comments
 (0)