Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nose to pytest conversion #221

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
python-version: '3.11.x'
- name: Setup Python
run: |
python3 -m pip install Cython numpy scipy matplotlib nose-py3 setuptools==69.1.0
python3 -m pip install Cython numpy scipy matplotlib pytest setuptools==69.1.0
- name: Install system
run: |
sudo apt-get -y install cmake liblapack-dev libsuitesparse-dev libhypre-dev
Expand Down Expand Up @@ -57,7 +57,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
python3 -m nose --verbose tests/*.py
run: pytest
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--- CHANGELOG ---
--- Future ---
* Changed testing framework from `nose` to `pytest`.
* Removed tests from the PyFMI installation.
* Moved test files from src/pyfmi/tests/... to tests/files/...
* Moved test_util.* from src/pyfmi/tests to src/pyfmi

--- PyFMI-2.15.0 ---
* Changed custom result handling for the Master algorithm to instead use a single ResultHandler for each model.
Expand Down
7 changes: 7 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pytest]
testpaths =
tests
filterwarnings =
ignore:.*does not support directional derivatives.*:UserWarning
PeterMeisrimelModelon marked this conversation as resolved.
Show resolved Hide resolved
markers =
assimulo
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ install_requires =
assimulo >= 3.5.0

tests_require =
nose-py3 >= 1.6.3
pytest >= 7.4.4
16 changes: 5 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,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 @@ -324,32 +324,26 @@ 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},
'util/*'] + extra_package_data
},
script_args=copy_args
)

Expand Down
14 changes: 0 additions & 14 deletions src/pyfmi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
import sys
import time

def testattr(**kwargs):
PeterMeisrimelModelon marked this conversation as resolved.
Show resolved Hide resolved
"""Add attributes to a test function/method/class.

This function is needed to be able to add
@attr(slow = True)
for functions.

"""
def wrap(func):
func.__dict__.update(kwargs)
return func
return wrap


try:
curr_dir = os.path.dirname(os.path.abspath(__file__))
_fpath=os.path.join(curr_dir,'version.txt')
Expand Down
12 changes: 5 additions & 7 deletions src/pyfmi/master.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ cdef class Master:
index_end = index_start + self.models_dict[model]["local_output_len"]
local_output_vref_array = (<FMUModelCS2>model).get_real(self.models_dict[model]["local_output_vref_array"])
for i, index in enumerate(range(index_start, index_end)):
y[index] = local_output_vref_array[i]
y[index] = local_output_vref_array[i].item()
PeterMeisrimelModelon marked this conversation as resolved.
Show resolved Hide resolved
modelonrobinandersson marked this conversation as resolved.
Show resolved Hide resolved
return y.reshape(-1,1)

cpdef np.ndarray get_connection_outputs_discrete(self):
Expand All @@ -794,7 +794,7 @@ cdef class Master:
index_end = index_start + self.models_dict[model]["local_output_discrete_len"]
local_output_discrete = model.get(self.models_dict[model]["local_output_discrete"])
for i, index in enumerate(range(index_start, index_end)):
y[index] = local_output_discrete[i]
y[index] = local_output_discrete[i].item()
return y.reshape(-1,1)

cpdef np.ndarray _get_derivatives(self):
Expand All @@ -810,7 +810,7 @@ cdef class Master:
index_end = index_start + self.models_dict[model]["local_derivative_len"]
local_derivative_vref_array = (<FMUModelCS2>model).get_real(self.models_dict[model]["local_derivative_vref_array"])
for i, index in enumerate(range(index_start, index_end)):
xd[index] = local_derivative_vref_array[i]
xd[index] = local_derivative_vref_array[i].item()

return xd.reshape(-1,1)

Expand All @@ -819,15 +819,15 @@ cdef class Master:
ytmp = model.get(np.array(self.models_dict[model]["local_output_discrete"])[mask])
for i, flag in enumerate(mask):
if flag:
yout[i+self.models_dict[model]["global_index_outputs_discrete"]] = ytmp[j]
yout[i+self.models_dict[model]["global_index_outputs_discrete"]] = ytmp[j].item()
j = j + 1

cpdef np.ndarray get_specific_connection_outputs(self, model, np.ndarray mask, np.ndarray yout):
cdef int j = 0
cdef np.ndarray ytmp = (<FMUModelCS2>model).get_real(self.models_dict[model]["local_output_vref_array"][mask])
for i, flag in enumerate(mask):
if flag:
yout[i+self.models_dict[model]["global_index_outputs"]] = ytmp[j]
yout[i+self.models_dict[model]["global_index_outputs"]] = ytmp[j].item()
j = j + 1

cpdef get_connection_derivatives(self, np.ndarray y_cur):
Expand Down Expand Up @@ -1847,5 +1847,3 @@ cdef class Master:
last_has_outputs = has_outputs
"""
return order, blocks,compressed_blocks


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.

16 changes: 0 additions & 16 deletions tests/__init__.py

This file was deleted.

Loading