Skip to content

Commit

Permalink
Removing tests from packages; moving test files to tests folder; addi…
Browse files Browse the repository at this point in the history
…ng examples to testing
  • Loading branch information
PeterMeisrimelModelon committed Feb 16, 2024
1 parent 6de1596 commit d4c3a40
Show file tree
Hide file tree
Showing 73 changed files with 86 additions and 50 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,4 @@ jobs:
- name: Build
run: python3 setup.py install --user --fmil-home=/usr
- name: Test
run: |
rm src/pyfmi/__init__.py
cp -rv src/pyfmi/tests/files tests
pytest --verbose tests/
run: pytest
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Removed utilities related to the obsolete FMUX model interface.
* Removed no longer required dependency on lxml.
* Upgraded to Cython3.
* Switched testing framework from nose to pytest
* Removed submodule pyfmi.tests, tests are no longer part of the PyFMI package.

--- PyFMI-2.11.0 ---
* Refactored result handling for dynamic_diagnostics. It is now possible use dynamic_diagnostics with a custom result handler.
Expand Down
7 changes: 7 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ install_requires =
pytest >= 7.4.4
matplotlib > 3
assimulo >= 3.5.0

# pytest configuration
[tool:pytest]
addopts = -v
testpaths = "tests"
filterwarnings =
ignore:.*does not support directional derivatives.*:UserWarning
15 changes: 3 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def check_extensions():
compiler_directives={'language_level' : "3str"})

# Test utilities
ext_list += cythonize([os.path.join("src", "pyfmi", "tests", "test_util.pyx")],
ext_list += cythonize([os.path.join("src", "pyfmi", "test_util.pyx")],
include_path = incl_path,
compiler_directives={'language_level' : "3str"})

Expand Down Expand Up @@ -322,33 +322,24 @@ def check_extensions():
classifiers=CLASSIFIERS,
ext_modules = ext_list,
package_dir = {'pyfmi': os.path.join('src', 'pyfmi'),
'pyfmi.common': os.path.join('src', 'common'),
'pyfmi.tests': 'tests'},
'pyfmi.common': os.path.join('src', 'common')},
packages=[
'pyfmi',
'pyfmi.simulation',
'pyfmi.examples',
'pyfmi.common',
'pyfmi.common.plotting',
'pyfmi.tests',
'pyfmi.common.log'
],
package_data = {'pyfmi': [
'examples/files/FMUs/ME1.0/*',
'examples/files/FMUs/CS1.0/*',
'examples/files/FMUs/ME2.0/*',
'examples/files/FMUs/CS2.0/*',
'tests/files/FMUs/XML/ME1.0/*',
'tests/files/FMUs/XML/CS1.0/*',
'tests/files/FMUs/XML/ME2.0/*',
'tests/files/FMUs/XML/CS2.0/*',
'tests/files/Results/*',
'tests/files/Logs/*',
'version.txt',
'LICENSE',
'CHANGELOG',
'util/*'] + extra_package_data,
'pyfmi.tests': ['pytest.ini']},
'util/*'] + extra_package_data},
script_args=copy_args
)

Expand Down
6 changes: 3 additions & 3 deletions src/pyfmi/examples/fmi_bouncing_ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pyfmi import load_fmu

curr_dir = os.path.dirname(os.path.abspath(__file__));
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs','ME1.0')
path_to_fmus2 = os.path.join(curr_dir, 'files', 'FMUs','ME2.0')

Expand All @@ -31,9 +31,9 @@ def run_demo(with_plots=True, version="2.0"):
ME FMUs version 1.0 and 2.0.
"""
if version == '1.0':
fmu_name = os.path.join(path_to_fmus,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus, 'bouncingBall.fmu')
else:
fmu_name = os.path.join(path_to_fmus2,'bouncingBall.fmu')
fmu_name = os.path.join(path_to_fmus2, 'bouncingBall.fmu')

model = load_fmu(fmu_name)

Expand Down
2 changes: 1 addition & 1 deletion src/pyfmi/examples/fmi_bouncing_ball_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pyfmi import load_fmu

curr_dir = os.path.dirname(os.path.abspath(__file__));
curr_dir = os.path.dirname(os.path.abspath(__file__))
path_to_fmus = os.path.join(curr_dir, 'files', 'FMUs', 'CS1.0')
path_to_fmus2 = os.path.join(curr_dir, 'files', 'FMUs', 'CS2.0')

Expand Down
3 changes: 1 addition & 2 deletions src/pyfmi/examples/fmu_with_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_demo(with_plots=True):
See also simulation_with_input.py
"""
fmu_name = os.path.join(path_to_fmus_me1,'SecondOrder.fmu')
fmu_name = os.path.join(path_to_fmus_me1, 'SecondOrder.fmu')

# Generate input
t = np.linspace(0.,10.,100)
Expand Down Expand Up @@ -70,4 +70,3 @@ def run_demo(with_plots=True):

if __name__=="__main__":
run_demo()

File renamed without changes.
2 changes: 1 addition & 1 deletion src/pyfmi/tests/test_util.pyx → src/pyfmi/test_util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cimport pyfmi.fmil_import as FMIL
from pyfmi.fmi import FMUException, FMUModelME1, FMUModelCS1, FMUModelCS2, FMUModelME2

def get_examples_folder():
return os.path.join(os.path.dirname(__file__), '..', 'examples')
return os.path.join(os.path.dirname(__file__), 'examples')

cdef class _ForTestingFMUModelME1(FMUModelME1):
cdef int _get_nominal_continuous_states_fmil(self, FMIL.fmi1_real_t* xnominal, size_t nx):
Expand Down
16 changes: 0 additions & 16 deletions src/pyfmi/tests/__init__.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions tests/pytest.ini

This file was deleted.

59 changes: 59 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2024 Modelon AB
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import pytest
import os
import pylab as pl

from pyfmi.examples import (
fmi_bouncing_ball_native,
fmi20_bouncing_ball_native,
fmi_bouncing_ball,
fmi_bouncing_ball_cs,
fmu_with_input,
fmu_with_input_function
)

@pytest.mark.parametrize("example", [
fmi_bouncing_ball_native,
fmi20_bouncing_ball_native
])
def test_run_example_bouncing_ball_native(example):
"""Test pyfmi bouncing ball native examples."""
example.run_demo()
pl.close("all") # close all generated figures

@pytest.mark.parametrize("fmi_version", ["1.0", "2.0"])
@pytest.mark.parametrize("example", [
fmi_bouncing_ball,
fmi_bouncing_ball_cs
])
def test_run_example_bouncing_ball(example, fmi_version):
"""Test pyfmi bouncing ball example in various versions."""
example.run_demo(version = fmi_version)
pl.close("all") # close all generated figures

@pytest.mark.skipif("nt" not in os.name,
reason = "FMU is example only contains windows binaries")
@pytest.mark.parametrize("example", [
fmu_with_input,
fmu_with_input_function
])
def test_run_example_with_input(example):
"""Test pyfmi examples with input."""
example.run_demo()
pl.close("all") # close all generated figures
2 changes: 1 addition & 1 deletion tests/test_fmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pyfmi.fmi as fmi
from pyfmi.fmi_algorithm_drivers import AssimuloFMIAlg, AssimuloFMIAlgOptions, \
PYFMI_JACOBIAN_LIMIT, PYFMI_JACOBIAN_SPARSE_SIZE_LIMIT
from pyfmi.tests.test_util import Dummy_FMUModelCS1, Dummy_FMUModelME1, Dummy_FMUModelME2, Dummy_FMUModelCS2, get_examples_folder
from pyfmi.test_util import Dummy_FMUModelCS1, Dummy_FMUModelME1, Dummy_FMUModelME2, Dummy_FMUModelCS2, get_examples_folder
from pyfmi.common.io import ResultHandler
from pyfmi.common.algorithm_drivers import UnrecognizedOptionError
from pyfmi.common.core import create_temp_dir
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fmi_coupled.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import pytest
import os

import pyfmi.fmi as fmi
from pyfmi.fmi import FMUModelME2
from pyfmi.fmi_coupled import CoupledFMUModelME2
import pyfmi.fmi as fmi
from pyfmi.tests.test_util import Dummy_FMUModelME2
from pyfmi.test_util import Dummy_FMUModelME2

assimulo_installed = True
try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fmi_estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import numpy as np

from pyfmi.tests.test_util import Dummy_FMUModelME2
from pyfmi.test_util import Dummy_FMUModelME2
from scipy.io.matlab import loadmat

assimulo_installed = True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fmi_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from pyfmi import Master
from pyfmi.fmi import FMUException, FMUModelCS2, FMUModelME2
from pyfmi.tests.test_util import Dummy_FMUModelCS2
from pyfmi.test_util import Dummy_FMUModelCS2
from pyfmi.common.algorithm_drivers import UnrecognizedOptionError

file_path = os.path.dirname(os.path.abspath(__file__))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pyfmi.common.diagnostics import DIAGNOSTICS_PREFIX

import pyfmi.fmi as fmi
from pyfmi.tests.test_util import Dummy_FMUModelME1, Dummy_FMUModelCS1, Dummy_FMUModelME2, Dummy_FMUModelCS2
from pyfmi.test_util import Dummy_FMUModelME1, Dummy_FMUModelCS1, Dummy_FMUModelME2, Dummy_FMUModelCS2

file_path = os.path.dirname(os.path.abspath(__file__))

Expand Down
2 changes: 1 addition & 1 deletion tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from pyfmi.common.log import extract_xml_log, parse_xml_log
from pyfmi.common.diagnostics import DIAGNOSTICS_PREFIX
from pyfmi.tests.test_util import Dummy_FMUModelME2
from pyfmi.test_util import Dummy_FMUModelME2
from pyfmi.fmi_util import decode

import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from filecmp import cmp as compare_files

from pyfmi.fmi import FMUException, load_fmu, FMUModelCS2, FMUModelME2
from pyfmi.tests.test_util import get_examples_folder
from pyfmi.test_util import get_examples_folder

file_path = os.path.dirname(os.path.abspath(__file__))

Expand Down

0 comments on commit d4c3a40

Please sign in to comment.