Skip to content

Commit 1fb3681

Browse files
committed
(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
1 parent e3984e7 commit 1fb3681

16 files changed

+1106
-1
lines changed

.github/workflows/Test_v400.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test-v4.0.0
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 30
10+
strategy:
11+
matrix:
12+
# test for:
13+
# * oldest supported version
14+
# * latest available Python version
15+
python-version: ['3.10', '3.14']
16+
# * Linux using ubuntu-latest
17+
# * Windows using windows-latest
18+
os: ['ubuntu-latest', 'windows-latest']
19+
# * OM stable - latest stable version
20+
# * OM nightly - latest nightly build
21+
omc-version: ['stable', 'nightly']
22+
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v6
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
architecture: 'x64'
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip build setuptools wheel twine
35+
pip install . pytest pytest-md pytest-emoji pre-commit
36+
37+
- name: Set timezone
38+
uses: szenius/set-timezone@v2.0
39+
with:
40+
timezoneLinux: 'Europe/Berlin'
41+
42+
- name: Run pre-commit linters
43+
run: 'pre-commit run --all-files'
44+
45+
- name: "Set up OpenModelica Compiler"
46+
uses: OpenModelica/setup-openmodelica@v1.0.6
47+
with:
48+
version: ${{ matrix.omc-version }}
49+
packages: |
50+
omc
51+
libraries: |
52+
'Modelica 4.0.0'
53+
- run: "omc --version"
54+
55+
- name: Pull OpenModelica docker image
56+
if: runner.os != 'Windows'
57+
run: docker pull openmodelica/openmodelica:v1.25.0-minimal
58+
59+
- name: Build wheel and sdist packages
60+
run: python -m build --wheel --sdist --outdir dist
61+
62+
- name: Check twine
63+
run: python -m twine check dist/*
64+
65+
- name: Run pytest
66+
uses: pavelzw/pytest-action@v2
67+
with:
68+
verbose: true
69+
emoji: true
70+
job-summary: true
71+
custom-arguments: '-v ./tests_v400'
72+
click-to-expand: true
73+
report-title: 'Test Report'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Test-v4.0.0-py310
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 30
10+
strategy:
11+
matrix:
12+
# test for:
13+
# * oldest supported version
14+
python-version: ['3.10']
15+
# * Linux using ubuntu-latest
16+
os: ['ubuntu-latest']
17+
# * OM stable - latest stable version
18+
omc-version: ['stable']
19+
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v6
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
architecture: 'x64'
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip build setuptools wheel twine
32+
pip install . pytest pytest-md pytest-emoji pre-commit
33+
34+
- name: Set timezone
35+
uses: szenius/set-timezone@v2.0
36+
with:
37+
timezoneLinux: 'Europe/Berlin'
38+
39+
- name: Run pre-commit linters
40+
run: 'pre-commit run --all-files'
41+
42+
- name: "Set up OpenModelica Compiler"
43+
uses: OpenModelica/setup-openmodelica@v1.0.6
44+
with:
45+
version: ${{ matrix.omc-version }}
46+
packages: |
47+
omc
48+
libraries: |
49+
'Modelica 4.0.0'
50+
- run: "omc --version"
51+
52+
- name: Pull OpenModelica docker image
53+
if: runner.os != 'Windows'
54+
run: docker pull openmodelica/openmodelica:v1.25.0-minimal
55+
56+
- name: Build wheel and sdist packages
57+
run: python -m build --wheel --sdist --outdir dist
58+
59+
- name: Check twine
60+
run: python -m twine check dist/*
61+
62+
- name: Run pytest
63+
uses: pavelzw/pytest-action@v2
64+
with:
65+
verbose: true
66+
emoji: true
67+
job-summary: true
68+
custom-arguments: '-v ./tests_v400'
69+
click-to-expand: true
70+
report-title: 'Test Report'

.github/workflows/Test_v4xx.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Test-v4.x.x
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test:
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 30
10+
strategy:
11+
matrix:
12+
# test for:
13+
# * oldest supported version
14+
# * latest available Python version
15+
python-version: ['3.10', '3.14']
16+
# * Linux using ubuntu-latest
17+
# * Windows using windows-latest
18+
os: ['ubuntu-latest', 'windows-latest']
19+
# * OM stable - latest stable version
20+
# * OM nightly - latest nightly build
21+
omc-version: ['stable', 'nightly']
22+
23+
steps:
24+
- uses: actions/checkout@v6
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v6
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
architecture: 'x64'
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m pip install --upgrade pip build setuptools wheel twine
35+
pip install . pytest pytest-md pytest-emoji pre-commit
36+
37+
- name: Set timezone
38+
uses: szenius/set-timezone@v2.0
39+
with:
40+
timezoneLinux: 'Europe/Berlin'
41+
42+
- name: Run pre-commit linters
43+
run: 'pre-commit run --all-files'
44+
45+
- name: "Set up OpenModelica Compiler"
46+
uses: OpenModelica/setup-openmodelica@v1.0.6
47+
with:
48+
version: ${{ matrix.omc-version }}
49+
packages: |
50+
omc
51+
libraries: |
52+
'Modelica 4.0.0'
53+
- run: "omc --version"
54+
55+
- name: Pull OpenModelica docker image
56+
if: runner.os != 'Windows'
57+
run: docker pull openmodelica/openmodelica:v1.25.0-minimal
58+
59+
- name: Build wheel and sdist packages
60+
run: python -m build --wheel --sdist --outdir dist
61+
62+
- name: Check twine
63+
run: python -m twine check dist/*
64+
65+
- name: Run pytest
66+
uses: pavelzw/pytest-action@v2
67+
with:
68+
verbose: true
69+
emoji: true
70+
job-summary: true
71+
custom-arguments: '-v ./tests'
72+
click-to-expand: true
73+
report-title: 'Test Report'

.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)