Skip to content

Commit

Permalink
Replace nosetests with pytest (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMeisrimelModelon authored Nov 20, 2024
1 parent 6555e0b commit 3b2b79e
Show file tree
Hide file tree
Showing 72 changed files with 1,083 additions and 1,333 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 All @@ -44,4 +44,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
- name: Test
run: python3 -m nose --verbose tests/* tests/solvers/*
run: pytest
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
--- CHANGELOG ---

--- Assimulo-3.5.x ---
--- Assimulo-FUTURE---
* Added get_sundials_version function (import from assimulo.solvers.sundials).
* Fixed bug that Radau5ODE would not count state events in statistics.
* Removed tests from the Assimulo installation.
* Changed testing framework from `nose` to `pytest`.

--- Assimulo-3.5.2 ---
* Allow to build without distutils for Python>=3.12 support
Expand Down
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".

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

.. note::

To test Assimulo, go into the tests folder and type::
To test Assimulo, 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
5 changes: 2 additions & 3 deletions examples/cvode_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

Expand Down Expand Up @@ -66,8 +65,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 abs(y2[-1][0] - 0.00347746) < 1e-5
assert abs(exp_sim.get_last_step() - 0.0222169642893) < 1e-3

return exp_mod, exp_sim

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

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

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

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

return exp_mod, exp_sim

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

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

Expand Down Expand Up @@ -83,8 +82,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 abs(y[-1][0] - 692.800241862) < 1e-6
assert abs(y[-1][8] - 7.08468221e-1) < 1e-6

return exp_mod, exp_sim

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

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

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

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

Expand Down Expand Up @@ -156,14 +155,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 abs(y[-1][0] - 8.0) < 1e-6
assert abs(y[-1][1] - 3.0) < 1e-6
assert abs(y[-1][2] - 2.0) < 1e-6

return exp_mod, exp_sim

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



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

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

Expand Down Expand Up @@ -123,10 +122,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 abs(y[-1][0] - 1577.6552477) < 1e-5
assert abs(y[-1][1] - 611.9574565) < 1e-5
assert abs(y[-1][2] - 2215.88563217) < 1e-5
assert abs(exp_sim.p_sol[0][1][0] - 1.0) < 1e-6

return exp_mod, exp_sim

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

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

Expand Down Expand Up @@ -78,8 +77,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 abs(y[-1][0] + 121.75000000) < 1e-4
assert abs(y[-1][1] + 49.100000000) < 1e-6

return exp_mod, exp_sim

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

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

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

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

return exp_mod, exp_sim

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

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

Expand Down Expand Up @@ -85,8 +84,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 abs(y[-1][0] + 121.75000000) < 1e-4
assert abs(y[-1][1] + 49.100000000) < 1e-6

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,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

Expand Down Expand Up @@ -87,12 +86,13 @@ 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 abs(y[-1][0] - 9.05518032e-01) < 1e-4
assert abs(y[-1][1] - 2.24046805e-05) < 1e-4
assert abs(y[-1][2] - 9.44595637e-02) < 1e-4
# Values taken from the example in Sundials
assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2
assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8
assert abs(exp_sim.p_sol[2][-1][0] + 4.9334e-10) < 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,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

Expand Down Expand Up @@ -104,12 +103,13 @@ 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 abs(y[-1][0] - 9.05518032e-01) < 1e-4
assert abs(y[-1][1] - 2.24046805e-05) < 1e-4
assert abs(y[-1][2] - 9.44595637e-02) < 1e-4
#Values taken from the example in Sundials
assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2
assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8
assert abs(exp_sim.p_sol[2][-1][0] + 4.9334e-10) < 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,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

Expand All @@ -30,9 +29,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 +84,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)
assert abs(y[-1][0] - 9.05518032e-01) < 1e-4
assert abs(y[-1][1] - 2.24046805e-05) < 1e-4
assert abs(y[-1][2] - 9.44595637e-02) < 1e-4
# Values taken from the example in Sundials
assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2
assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8

return exp_mod, exp_sim

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

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

Expand Down Expand Up @@ -107,8 +106,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 abs(y[-1,0] - 3.11178295) < 1e-4
assert abs(y[-1,1] - 3.19318992) < 1e-4

return exp_mod, exp_sim

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

import numpy as np
import nose

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

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

return exp_mod, exp_sim

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

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

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

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

return exp_mod, exp_sim

Expand Down
Loading

0 comments on commit 3b2b79e

Please sign in to comment.