Skip to content

Commit

Permalink
Conversion to pytest; work in progress
Browse files Browse the repository at this point in the history
work in progress; more conversion

Cleanup

removing redundant testattr

removing warnings

Resolving DeprecationWarnings in tests

Fixing issue in 1 test; more deprecation issues

Replaced commented-out tests with appropriate pytest.mark.skip

Cleanup; some more minor Deprecations

Review fixes
  • Loading branch information
PeterMeisrimelModelon authored and Peter Meisrimel committed Oct 2, 2024
1 parent 35b1318 commit f1296ff
Show file tree
Hide file tree
Showing 71 changed files with 1,115 additions and 1,326 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
python-version: '3.11.x'
- name: Setup Python
run: |
python3 -m pip install Cython numpy scipy matplotlib nose-py3
python3 -m pip install Cython numpy scipy matplotlib pytest
- name: Install system
run: |
sudo apt-get -y install cmake liblapack-dev libsuitesparse-dev libhypre-dev
Expand All @@ -43,4 +43,4 @@ jobs:
- name: Build
run: python3 setup.py install --user --sundials-home=/usr --blas-home=/usr/lib/x86_64-linux-gnu/ --lapack-home=/usr/lib/x86_64-linux-gnu/ --superlu-home=/usr --extra-fortran-compile-flags="-fallow-argument-mismatch"
- name: Test
run: python3 -m nose --verbose tests/* tests/solvers/*
run: pytest --verbose tests/
3 changes: 1 addition & 2 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Installation is performed using the command:
'python setup.py install --sundials-home=/path/to/sundials --blas-home=/path/to/blas --lapack-home=/path/to/lapack'

Assimulo is then installed under Python dist-packages.
To test the installation, browse to the tests folder and do a 'nosetests'.
(The testing needs additionally the python-nose package)
To test the installation, run "pytest tests/".

For more information regarding Assimulo and the installation procedure,
please visit: http://www.jmodelica.org/assimulo
8 changes: 4 additions & 4 deletions doc/sphinx/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ the section troubleshooting see :ref:`instTrouble` should be consulted before in

To test Assimulo, go into the tests folder and type::
nosetests
pytest .
Which requires python-nose.
Which requires pytest.

Windows
==========
Expand All @@ -90,9 +90,9 @@ After a successful installation, the package will be located in pythons dist-pac

To test Assimulo, go into the tests folder and type::
nosetests
pytest .
Which requires python-nose.
Which requires pytest.


.. _instTrouble:
Expand Down
6 changes: 3 additions & 3 deletions examples/cvode_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -66,8 +66,8 @@ def f(t,y):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y2[-1][0], 0.00347746, 5)
nose.tools.assert_almost_equal(exp_sim.get_last_step(), 0.0222169642893, 3)
assert y2[-1][0] == pytest.approx(0.00347746, abs = 1e-5)
assert exp_sim.get_last_step() == pytest.approx(0.0222169642893, abs = 1e-3)

return exp_mod, exp_sim

Expand Down
4 changes: 2 additions & 2 deletions examples/cvode_basic_backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -62,7 +62,7 @@ def f(t,y):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)
assert y[-1][0] == pytest.approx(4.00000000, abs = 1e-3)

return exp_mod, exp_sim

Expand Down
6 changes: 3 additions & 3 deletions examples/cvode_gyro.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.problem import Explicit_Problem
from assimulo.solvers import CVode

Expand Down Expand Up @@ -83,8 +83,8 @@ def f(t, u):
pl.show()

#Basic tests
nose.tools.assert_almost_equal(y[-1][0], 692.800241862)
nose.tools.assert_almost_equal(y[-1][8], 7.08468221e-1)
assert y[-1][0] == pytest.approx(692.800241862)
assert y[-1][8] == pytest.approx(7.08468221e-1)

return exp_mod, exp_sim

Expand Down
4 changes: 2 additions & 2 deletions examples/cvode_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -89,7 +89,7 @@ def f(t,y):

#Basic test
x1 = y[:,0]
nose.tools.assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
assert np.abs(float(x1[-1]) - 1.8601438) < 1e-1

return exp_mod, exp_sim

Expand Down
11 changes: 4 additions & 7 deletions examples/cvode_with_disc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -156,14 +156,11 @@ def run_example(with_plots=True):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0],8.0)
nose.tools.assert_almost_equal(y[-1][1],3.0)
nose.tools.assert_almost_equal(y[-1][2],2.0)
assert y[-1][0] == pytest.approx(8.0)
assert y[-1][1] == pytest.approx(3.0)
assert y[-1][2] == pytest.approx(2.0)

return exp_mod, exp_sim

if __name__=="__main__":
mod,sim = run_example()



10 changes: 5 additions & 5 deletions examples/cvode_with_initial_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -123,10 +123,10 @@ def f(t, y, p):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0], 1577.6552477, 5)
nose.tools.assert_almost_equal(y[-1][1], 611.9574565, 5)
nose.tools.assert_almost_equal(y[-1][2], 2215.88563217, 5)
nose.tools.assert_almost_equal(exp_sim.p_sol[0][1][0], 1.0)
assert y[-1][0] == pytest.approx(1577.6552477, abs = 1e-5)
assert y[-1][1] == pytest.approx(611.9574565, abs = 1e-5)
assert y[-1][2] == pytest.approx(2215.88563217, abs = 1e-5)
assert exp_sim.p_sol[0][1][0] == pytest.approx(1.0)

return exp_mod, exp_sim

Expand Down
6 changes: 3 additions & 3 deletions examples/cvode_with_jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -78,8 +78,8 @@ def jac(t,y):
pl.show()

#Basic tests
nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
nose.tools.assert_almost_equal(y[-1][1],-49.100000000)
assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4)
assert y[-1][1] == pytest.approx(-49.100000000)

return exp_mod, exp_sim

Expand Down
4 changes: 2 additions & 2 deletions examples/cvode_with_jac_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import numpy as np
import scipy.sparse as sps
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -93,7 +93,7 @@ def jac(t,y):
pl.show()

#Basic tests
nose.tools.assert_almost_equal(y[-1][0],0.9851,3)
assert y[-1][0] == pytest.approx(0.9851, abs = 1e-3)

return exp_mod, exp_sim

Expand Down
6 changes: 3 additions & 3 deletions examples/cvode_with_jac_spgmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -85,8 +85,8 @@ def jacv(t,y,fy,v):
pl.show()

#Basic tests
nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
nose.tools.assert_almost_equal(y[-1][1],-49.100000000)
assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4)
assert y[-1][1] == pytest.approx(-49.100000000)

return exp_mod, exp_sim

Expand Down
14 changes: 7 additions & 7 deletions examples/cvode_with_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -87,12 +87,12 @@ def f(t, y, p):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
nose.tools.assert_almost_equal(y[-1][1], 2.24046805e-05, 4)
nose.tools.assert_almost_equal(y[-1][2], 9.44595637e-02, 4)
nose.tools.assert_almost_equal(exp_sim.p_sol[0][-1][0], -1.8761, 2) #Values taken from the example in Sundials
nose.tools.assert_almost_equal(exp_sim.p_sol[1][-1][0], 2.9614e-06, 8)
nose.tools.assert_almost_equal(exp_sim.p_sol[2][-1][0], -4.9334e-10, 12)
assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4)
assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4)
assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4)
assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials
assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8)
assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12)

return exp_mod, exp_sim

Expand Down
14 changes: 7 additions & 7 deletions examples/cvode_with_parameters_fcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -104,12 +104,12 @@ def fsens(t, y, s, p):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
nose.tools.assert_almost_equal(y[-1][1], 2.24046805e-05, 4)
nose.tools.assert_almost_equal(y[-1][2], 9.44595637e-02, 4)
nose.tools.assert_almost_equal(exp_sim.p_sol[0][-1][0], -1.8761, 2) #Values taken from the example in Sundials
nose.tools.assert_almost_equal(exp_sim.p_sol[1][-1][0], 2.9614e-06, 8)
nose.tools.assert_almost_equal(exp_sim.p_sol[2][-1][0], -4.9334e-10, 12)
assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4)
assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4)
assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4)
assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials
assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8)
assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12)

return exp_mod, exp_sim

Expand Down
18 changes: 9 additions & 9 deletions examples/cvode_with_parameters_modified.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand All @@ -30,9 +30,9 @@ def run_example(with_plots=True):
.. math::
\dot y_1 &= -p_1 y_1 + p_2 y_2 y_3 \\
\dot y_2 &= p_1 y_1 - p_2 y_2 y_3 - p_3 y_2^2 \\
\dot y_3 &= p_3 y_2^2
\\dot y_1 &= -p_1 y_1 + p_2 y_2 y_3 \\
\\dot y_2 &= p_1 y_1 - p_2 y_2 y_3 - p_3 y_2^2 \\
\\dot y_3 &= p_3 y_2^2
on return:
Expand Down Expand Up @@ -85,11 +85,11 @@ def f(t, y, p):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0], 9.05518032e-01, 4)
nose.tools.assert_almost_equal(y[-1][1], 2.24046805e-05, 4)
nose.tools.assert_almost_equal(y[-1][2], 9.44595637e-02, 4)
nose.tools.assert_almost_equal(exp_sim.p_sol[0][-1][0], -1.8761, 2) #Values taken from the example in Sundials
nose.tools.assert_almost_equal(exp_sim.p_sol[1][-1][0], 2.9614e-06, 8)
assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4)
assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4)
assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4)
assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials
assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8)

return exp_mod, exp_sim

Expand Down
6 changes: 3 additions & 3 deletions examples/cvode_with_preconditioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""

import numpy as np
import nose
import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem

Expand Down Expand Up @@ -107,8 +107,8 @@ def prec_solve(t, y, fy, r, gamma, delta, data):
exp_sim.plot()

#Basic verification
nose.tools.assert_almost_equal(y[-1,0],3.11178295,4)
nose.tools.assert_almost_equal(y[-1,1],3.19318992,4)
assert y[-1,0] == pytest.approx(3.11178295, abs = 1e-4)
assert y[-1,1] == pytest.approx(3.19318992, abs = 1e-4)

return exp_mod, exp_sim

Expand Down
4 changes: 2 additions & 2 deletions examples/dasp3_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest

try:
from assimulo.solvers import DASP3ODE
Expand Down Expand Up @@ -100,7 +100,7 @@ def dzdt(t,y,z):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1,0], 10.860063849896818, 3)
assert y[-1,0] == pytest.approx( 10.860063849896818, abs = 1e-3)

return exp_mod, exp_sim

Expand Down
6 changes: 3 additions & 3 deletions examples/dopri5_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import nose
import pytest
from assimulo.solvers import Dopri5
from assimulo.problem import Explicit_Problem

Expand All @@ -39,7 +39,7 @@ def f(t,y):

#Define an Assimulo problem
exp_mod = Explicit_Problem(f, 4.0,
name = 'DOPRI5 Example: $\dot y = - y$')
name = 'DOPRI5 Example: $\\dot y = - y$')

exp_sim = Dopri5(exp_mod) #Create a Dopri5 solver

Expand All @@ -56,7 +56,7 @@ def f(t,y):
pl.show()

#Basic test
nose.tools.assert_almost_equal(y[-1][0],0.02695199,5)
assert y[-1][0] == pytest.approx(0.02695199, abs = 1e-5)

return exp_mod, exp_sim

Expand Down
Loading

0 comments on commit f1296ff

Please sign in to comment.