diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 3c5692b4..95845045 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -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
@@ -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/
diff --git a/INSTALL b/INSTALL
index 7a47af45..73cefad1 100644
--- a/INSTALL
+++ b/INSTALL
@@ -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
diff --git a/doc/sphinx/source/installation.rst b/doc/sphinx/source/installation.rst
index 756bf565..b50a0d9a 100644
--- a/doc/sphinx/source/installation.rst
+++ b/doc/sphinx/source/installation.rst
@@ -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
==========
@@ -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:
diff --git a/examples/cvode_basic.py b/examples/cvode_basic.py
index 20c11264..e453e804 100644
--- a/examples/cvode_basic.py
+++ b/examples/cvode_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-5)
+ assert exp_sim.get_last_step() == pytest.approx(0.0222169642893, rel = 1e-3)
return exp_mod, exp_sim
diff --git a/examples/cvode_basic_backward.py b/examples/cvode_basic_backward.py
index c5454800..4fc55f9f 100644
--- a/examples/cvode_basic_backward.py
+++ b/examples/cvode_basic_backward.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-3)
return exp_mod, exp_sim
diff --git a/examples/cvode_gyro.py b/examples/cvode_gyro.py
index eb9590a1..5684d38d 100644
--- a/examples/cvode_gyro.py
+++ b/examples/cvode_gyro.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.problem import Explicit_Problem
from assimulo.solvers import CVode
@@ -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
diff --git a/examples/cvode_stability.py b/examples/cvode_stability.py
index 4a7a7eaf..706c97c9 100644
--- a/examples/cvode_stability.py
+++ b/examples/cvode_stability.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_disc.py b/examples/cvode_with_disc.py
index 1752b2cb..96daa656 100644
--- a/examples/cvode_with_disc.py
+++ b/examples/cvode_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -156,9 +156,9 @@ 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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_initial_sensitivity.py b/examples/cvode_with_initial_sensitivity.py
index 848eeb16..4110fba5 100644
--- a/examples/cvode_with_initial_sensitivity.py
+++ b/examples/cvode_with_initial_sensitivity.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-5)
+ assert y[-1][1] == pytest.approx(611.9574565, rel = 1e-5)
+ assert y[-1][2] == pytest.approx(2215.88563217, rel = 1e-5)
+ assert exp_sim.p_sol[0][1][0] == pytest.approx(1.0)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_jac.py b/examples/cvode_with_jac.py
index 7bb4d1fe..f8885dd3 100644
--- a/examples/cvode_with_jac.py
+++ b/examples/cvode_with_jac.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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_almost_equal(y[-1][0],-121.75000000,4)
+ assert_almost_equal(y[-1][1],-49.100000000)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py
index ca0ccb6b..fc77f31e 100644
--- a/examples/cvode_with_jac_sparse.py
+++ b/examples/cvode_with_jac_sparse.py
@@ -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
@@ -93,7 +93,7 @@ def jac(t,y):
pl.show()
#Basic tests
- nose.tools.assert_almost_equal(y[-1][0],0.9851,3)
+ assert_almost_equal(y[-1][0],0.9851,3)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_jac_spgmr.py b/examples/cvode_with_jac_spgmr.py
index 3914b901..b797ecb8 100644
--- a/examples/cvode_with_jac_spgmr.py
+++ b/examples/cvode_with_jac_spgmr.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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_almost_equal(y[-1][0],-121.75000000,4)
+ assert_almost_equal(y[-1][1],-49.100000000)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_parameters.py b/examples/cvode_with_parameters.py
index 9746e1ad..021c1959 100644
--- a/examples/cvode_with_parameters.py
+++ b/examples/cvode_with_parameters.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-4)
+ assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4)
+ assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4)
+ assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials
+ assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8)
+ assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_parameters_fcn.py b/examples/cvode_with_parameters_fcn.py
index ee6156bd..62389c95 100644
--- a/examples/cvode_with_parameters_fcn.py
+++ b/examples/cvode_with_parameters_fcn.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-4)
+ assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4)
+ assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4)
+ assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials
+ assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8)
+ assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_parameters_modified.py b/examples/cvode_with_parameters_modified.py
index 396b934c..94624a87 100644
--- a/examples/cvode_with_parameters_modified.py
+++ b/examples/cvode_with_parameters_modified.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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, rel = 1e-4)
+ assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4)
+ assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4)
+ assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials
+ assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8)
return exp_mod, exp_sim
diff --git a/examples/cvode_with_preconditioning.py b/examples/cvode_with_preconditioning.py
index e497a19a..4d965727 100644
--- a/examples/cvode_with_preconditioning.py
+++ b/examples/cvode_with_preconditioning.py
@@ -20,7 +20,7 @@
"""
import numpy as np
-import nose
+import pytest
from assimulo.solvers import CVode
from assimulo.problem import Explicit_Problem
@@ -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_almost_equal(y[-1,0],3.11178295,4)
+ assert_almost_equal(y[-1,1],3.19318992,4)
return exp_mod, exp_sim
diff --git a/examples/dasp3_basic.py b/examples/dasp3_basic.py
index eaa83eed..a7a13934 100644
--- a/examples/dasp3_basic.py
+++ b/examples/dasp3_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
try:
from assimulo.solvers import DASP3ODE
@@ -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_almost_equal(y[-1,0], 10.860063849896818, 3)
return exp_mod, exp_sim
diff --git a/examples/dopri5_basic.py b/examples/dopri5_basic.py
index 413d6a48..393b9427 100644
--- a/examples/dopri5_basic.py
+++ b/examples/dopri5_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Dopri5
from assimulo.problem import Explicit_Problem
@@ -56,7 +56,7 @@ def f(t,y):
pl.show()
#Basic test
- nose.tools.assert_almost_equal(y[-1][0],0.02695199,5)
+ assert_almost_equal(y[-1][0],0.02695199,5)
return exp_mod, exp_sim
diff --git a/examples/dopri5_with_disc.py b/examples/dopri5_with_disc.py
index 5cf21136..2c4ce9c5 100644
--- a/examples/dopri5_with_disc.py
+++ b/examples/dopri5_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Dopri5
from assimulo.problem import Explicit_Problem
@@ -155,9 +155,9 @@ 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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
return exp_mod, exp_sim
diff --git a/examples/euler_basic.py b/examples/euler_basic.py
index 40de392d..ed2e3cab 100644
--- a/examples/euler_basic.py
+++ b/examples/euler_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import ExplicitEuler
from assimulo.problem import Explicit_Problem
@@ -61,7 +61,7 @@ def f(t,y):
pl.show()
#Basic test
- nose.tools.assert_almost_equal(y2[-1][0], 0.02628193)
+ assert y2[-1][0] == pytest.approx(0.02628193)
return exp_mod, exp_sim
diff --git a/examples/euler_vanderpol.py b/examples/euler_vanderpol.py
index d9212f5a..45af37bc 100644
--- a/examples/euler_vanderpol.py
+++ b/examples/euler_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import ImplicitEuler
from assimulo.problem import Explicit_Problem
@@ -86,7 +86,7 @@ def jac(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
+ assert_less(np.abs(float(x1[-1]) - 1.8601438), 1e-1)
return exp_mod, exp_sim
diff --git a/examples/euler_with_disc.py b/examples/euler_with_disc.py
index 8707ecbc..ecc7d3aa 100644
--- a/examples/euler_with_disc.py
+++ b/examples/euler_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import ExplicitEuler
from assimulo.problem import Explicit_Problem
@@ -152,9 +152,9 @@ 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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
return exp_mod, exp_sim
diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py
index 834d5181..993b71d3 100644
--- a/examples/glimda_vanderpol.py
+++ b/examples/glimda_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import GLIMDA
from assimulo.problem import Implicit_Problem
@@ -86,7 +86,7 @@ def f(t,y,yd):
#Basic test
x1 = y[:,0]
- nose.tools.assert_almost_equal(float(x1[-1]), 1.706168035, 3)
+ assert float(x1[-1]) == pytest.approx(1.706168035, rel = 1e-3)
return imp_mod, imp_sim
diff --git a/examples/ida_basic_backward.py b/examples/ida_basic_backward.py
index e7698879..fd6913bf 100644
--- a/examples/ida_basic_backward.py
+++ b/examples/ida_basic_backward.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -62,7 +62,7 @@ def f(t,y,yd):
pl.show()
#Basic test
- nose.tools.assert_almost_equal(y[-1][0], 4.00000000, 3)
+ assert y[-1][0] == pytest.approx(4.00000000, rel = 1e-3)
return imp_mod, imp_sim
diff --git a/examples/ida_with_disc.py b/examples/ida_with_disc.py
index 1905b66f..9d0a3b6f 100644
--- a/examples/ida_with_disc.py
+++ b/examples/ida_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -158,9 +158,9 @@ 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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
return imp_mod, imp_sim
diff --git a/examples/ida_with_initial_sensitivity.py b/examples/ida_with_initial_sensitivity.py
index 3081eb45..d4bfad0e 100644
--- a/examples/ida_with_initial_sensitivity.py
+++ b/examples/ida_with_initial_sensitivity.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -114,10 +114,10 @@ def f(t, y, yd,p):
pl.show()
#Basic test
- nose.tools.assert_almost_equal(y[-1][0], 1577.6552477,3)
- nose.tools.assert_almost_equal(y[-1][1], 611.9574565, 3)
- nose.tools.assert_almost_equal(y[-1][2], 2215.88563217, 3)
- nose.tools.assert_almost_equal(imp_sim.p_sol[0][1][0], 1.0)
+ assert_almost_equal(y[-1][0], 1577.6552477,3)
+ assert y[-1][1] == pytest.approx(611.9574565, rel = 1e-3)
+ assert y[-1][2] == pytest.approx(2215.88563217, rel = 1e-3)
+ assert imp_sim.p_sol[0][1][0] == pytest.approx(1.0)
return imp_mod, imp_sim
diff --git a/examples/ida_with_jac.py b/examples/ida_with_jac.py
index 9cfa3027..a57d70ec 100644
--- a/examples/ida_with_jac.py
+++ b/examples/ida_with_jac.py
@@ -18,7 +18,7 @@
import numpy as np
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
-import nose
+import pytest
def run_example(with_plots=True):
r"""
@@ -107,10 +107,10 @@ def jac(c,t,y,yd):
t, y, yd = imp_sim.simulate(5,1000) #Simulate 5 seconds with 1000 communication points
#Basic tests
- nose.tools.assert_almost_equal(y[-1][0],0.9401995, places=4)
- nose.tools.assert_almost_equal(y[-1][1],-0.34095124, places=4)
- nose.tools.assert_almost_equal(yd[-1][0], -0.88198927, places=4)
- nose.tools.assert_almost_equal(yd[-1][1], -2.43227069, places=4)
+ assert_almost_equal(y[-1][0],0.9401995, places=4)
+ assert_almost_equal(y[-1][1],-0.34095124, places=4)
+ assert yd[-1][0] == pytest.approx(-0.88198927, rel = 1e-4)
+ assert yd[-1][1] == pytest.approx(-2.43227069, rel = 1e-4)
#Plot
if with_plots:
diff --git a/examples/ida_with_jac_spgmr.py b/examples/ida_with_jac_spgmr.py
index 4650a5ae..5ae85f0d 100644
--- a/examples/ida_with_jac_spgmr.py
+++ b/examples/ida_with_jac_spgmr.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -77,8 +77,8 @@ def jacv(t,y,yd,res,v,c):
t, y, yd = imp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points
#Basic tests
- nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
- nose.tools.assert_almost_equal(y[-1][1],-49.100000000)
+ assert_almost_equal(y[-1][0],-121.75000000,4)
+ assert_almost_equal(y[-1][1],-49.100000000)
#Plot
if with_plots:
diff --git a/examples/ida_with_parameters.py b/examples/ida_with_parameters.py
index 6c5cc9f5..0820ddc6 100644
--- a/examples/ida_with_parameters.py
+++ b/examples/ida_with_parameters.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
@@ -78,12 +78,12 @@ def f(t, y, yd, p):
t, y, yd = imp_sim.simulate(4,400) #Simulate 4 seconds with 400 communication points
#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(imp_sim.p_sol[0][-1][0], -1.8761, 2) #Values taken from the example in Sundials
- nose.tools.assert_almost_equal(imp_sim.p_sol[1][-1][0], 2.9614e-06, 8)
- nose.tools.assert_almost_equal(imp_sim.p_sol[2][-1][0], -4.9334e-10, 12)
+ assert y[-1][0] == pytest.approx(9.05518032e-01, rel = 1e-4)
+ assert y[-1][1] == pytest.approx(2.24046805e-05, rel = 1e-4)
+ assert y[-1][2] == pytest.approx(9.44595637e-02, rel = 1e-4)
+ assert imp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, rel = 1e-2) #Values taken from the example in Sundials
+ assert imp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, rel = 1e-8)
+ assert imp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, rel = 1e-12)
#Plot
if with_plots:
diff --git a/examples/ida_with_user_defined_handle_result.py b/examples/ida_with_user_defined_handle_result.py
index 365305ec..090286ee 100644
--- a/examples/ida_with_user_defined_handle_result.py
+++ b/examples/ida_with_user_defined_handle_result.py
@@ -18,7 +18,7 @@
import numpy as np
from assimulo.solvers import IDA
from assimulo.problem import Implicit_Problem
-import nose
+import pytest
def run_example(with_plots=True):
r"""
@@ -107,11 +107,11 @@ def handle_result(solver, t ,y, yd):
pl.show()
#Basic tests
- nose.tools.assert_almost_equal(y[-1][0],0.9401995, places=4)
- nose.tools.assert_almost_equal(y[-1][1],-0.34095124, places=4)
- nose.tools.assert_almost_equal(yd[-1][0], -0.88198927, places=4)
- nose.tools.assert_almost_equal(yd[-1][1], -2.43227069, places=4)
- nose.tools.assert_almost_equal(order[-1], 5, places=4)
+ assert_almost_equal(y[-1][0],0.9401995, places=4)
+ assert_almost_equal(y[-1][1],-0.34095124, places=4)
+ assert yd[-1][0] == pytest.approx(-0.88198927, rel = 1e-4)
+ assert yd[-1][1] == pytest.approx(-2.43227069, rel = 1e-4)
+ assert order[-1] == pytest.approx(5, rel = 1e-4)
return imp_mod, imp_sim
diff --git a/examples/kinsol_basic.py b/examples/kinsol_basic.py
index 9144d78a..633d8216 100644
--- a/examples/kinsol_basic.py
+++ b/examples/kinsol_basic.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo.solvers import KINSOL
from assimulo.problem import Algebraic_Problem
@@ -46,7 +46,7 @@ def res(y):
y = alg_solver.solve()
#Basic test
- nose.tools.assert_almost_equal(y, 1.0, 5)
+ assert y == pytest.approx(1.0, rel = 1e-5)
return alg_mod, alg_solver
diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py
index 29f263ab..5e39a9a7 100644
--- a/examples/kinsol_ors.py
+++ b/examples/kinsol_ors.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import os
-import nose
+import pytest
import numpy as np
import scipy as sp
import scipy.sparse as sps
@@ -126,7 +126,7 @@ def setup_param(solver):
#Basic test
for j in range(len(y)):
- nose.tools.assert_almost_equal(y[j], 1.0, 4)
+ assert y[j] == pytest.approx(1.0, rel = 1e-4)
return [alg_mod, alg_mod_prec], [alg_solver, alg_solver_prec]
diff --git a/examples/kinsol_with_jac.py b/examples/kinsol_with_jac.py
index 6fcf0f38..a6cb725d 100644
--- a/examples/kinsol_with_jac.py
+++ b/examples/kinsol_with_jac.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import KINSOL
from assimulo.problem import Algebraic_Problem
@@ -51,8 +51,8 @@ def jac(y):
y = alg_solver.solve()
#Basic test
- nose.tools.assert_almost_equal(y[0], 1.5, 5)
- nose.tools.assert_almost_equal(y[1], 1.0, 5)
+ assert y[0] == pytest.approx(1.5, rel = 1e-5)
+ assert y[1] == pytest.approx(1.0, rel = 1e-5)
return alg_mod, alg_solver
diff --git a/examples/lsodar_vanderpol.py b/examples/lsodar_vanderpol.py
index ee86735d..300da948 100644
--- a/examples/lsodar_vanderpol.py
+++ b/examples/lsodar_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
@@ -75,7 +75,7 @@ def f(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(x1[-1] - 1.706168035), 1e-3)
+ assert_less(np.abs(x1[-1] - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/lsodar_with_disc.py b/examples/lsodar_with_disc.py
index a2952485..398c4008 100644
--- a/examples/lsodar_with_disc.py
+++ b/examples/lsodar_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import LSODAR
from assimulo.problem import Explicit_Problem
@@ -152,9 +152,9 @@ 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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
return exp_mod, exp_sim
diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py
index 852b2e11..cc9a6e79 100644
--- a/examples/mech_system_pendulum.py
+++ b/examples/mech_system_pendulum.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
import numpy as np
from assimulo.special_systems import Mechanical_System
from assimulo.solvers import IDA, ODASSL
@@ -60,7 +60,7 @@ def run_example(index="ind1", with_plots=True, with_test=False):
print(final_residual, 'Norm: ', np.linalg.norm(final_residual))
if with_test:
- nose.tools.assert_less(np.linalg.norm(final_residual), 1.5e-1)
+ assert_less(np.linalg.norm(final_residual), 1.5e-1)
if with_plots:
dae_pend.plot(mask=[1,1]+(len(my_pend.y0)-2)*[0])
return my_pend, dae_pend
diff --git a/examples/radau5dae_time_events.py b/examples/radau5dae_time_events.py
index b4b69dd2..7e23e215 100644
--- a/examples/radau5dae_time_events.py
+++ b/examples/radau5dae_time_events.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Radau5DAE
from assimulo.problem import Implicit_Problem
@@ -73,7 +73,7 @@ def run_example(with_plots=True):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(float(x1[-1]) - 1.14330840983), 1e-3)
+ assert_less(np.abs(float(x1[-1]) - 1.14330840983), 1e-3)
return imp_mod, imp_sim
if __name__=='__main__':
diff --git a/examples/radau5dae_vanderpol.py b/examples/radau5dae_vanderpol.py
index ea5612ce..65e35a59 100644
--- a/examples/radau5dae_vanderpol.py
+++ b/examples/radau5dae_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Radau5DAE
from assimulo.problem import Implicit_Problem
@@ -86,7 +86,7 @@ def f(t,y,yd):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return imp_mod, imp_sim
diff --git a/examples/radau5ode_vanderpol.py b/examples/radau5ode_vanderpol.py
index bbc852f9..da6f81d4 100644
--- a/examples/radau5ode_vanderpol.py
+++ b/examples/radau5ode_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -76,7 +76,7 @@ def f(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/radau5ode_with_disc.py b/examples/radau5ode_with_disc.py
index 544c34f7..17acc0a9 100644
--- a/examples/radau5ode_with_disc.py
+++ b/examples/radau5ode_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -134,9 +134,9 @@ def run_example(with_plots=True):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
#Plot
if with_plots:
diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py
index 9ef1d6f3..c80b55c6 100644
--- a/examples/radau5ode_with_disc_sparse.py
+++ b/examples/radau5ode_with_disc_sparse.py
@@ -17,7 +17,7 @@
import numpy as np
import scipy.sparse as sps
-import nose
+import pytest
from assimulo.solvers import Radau5ODE
from assimulo.problem import Explicit_Problem
@@ -142,9 +142,9 @@ def run_example(with_plots=True):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
#Plot
if with_plots:
diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py
index 633f0535..1553ab24 100644
--- a/examples/radau5ode_with_jac_sparse.py
+++ b/examples/radau5ode_with_jac_sparse.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
import numpy as np
import scipy.sparse as sps
from assimulo.solvers import Radau5ODE
@@ -89,7 +89,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, rel = 1e-3)
return exp_mod, exp_sim
diff --git a/examples/rodasode_vanderpol.py b/examples/rodasode_vanderpol.py
index 61da426b..1abc2533 100644
--- a/examples/rodasode_vanderpol.py
+++ b/examples/rodasode_vanderpol.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import RodasODE
from assimulo.problem import Explicit_Problem
@@ -86,7 +86,7 @@ def jac(t,y):
#Basic test
x1 = y[:,0]
- nose.tools.assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
+ assert_less(np.abs(float(x1[-1]) - 1.706168035), 1e-3)
return exp_mod, exp_sim
diff --git a/examples/rungekutta34_basic.py b/examples/rungekutta34_basic.py
index fea7749f..3037a451 100644
--- a/examples/rungekutta34_basic.py
+++ b/examples/rungekutta34_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import RungeKutta34
from assimulo.problem import Explicit_Problem
@@ -49,7 +49,7 @@ def f(t,y):
t, y = exp_sim.simulate(5) #Simulate 5 seconds
#Basic test
- nose.tools.assert_almost_equal(y[-1][0], 0.02695199, 5)
+ assert y[-1][0] == pytest.approx(0.02695199, rel = 1e-5)
#Plot
if with_plots:
diff --git a/examples/rungekutta34_with_disc.py b/examples/rungekutta34_with_disc.py
index 97e222b7..fe84ea06 100644
--- a/examples/rungekutta34_with_disc.py
+++ b/examples/rungekutta34_with_disc.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import RungeKutta34
from assimulo.problem import Explicit_Problem
@@ -136,9 +136,9 @@ def run_example(with_plots=True):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
#Plot
if with_plots:
diff --git a/examples/rungekutta4_basic.py b/examples/rungekutta4_basic.py
index cb009129..220f6822 100644
--- a/examples/rungekutta4_basic.py
+++ b/examples/rungekutta4_basic.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
import numpy as np
-import nose
+import pytest
from assimulo.solvers import RungeKutta4
from assimulo.problem import Explicit_Problem
@@ -49,7 +49,7 @@ def f(t,y):
t, y = exp_sim.simulate(5, 100) #Simulate 5 seconds
#Basic test
- nose.tools.assert_almost_equal(y[-1][0], 0.02695179)
+ assert y[-1][0] == pytest.approx(0.02695179)
#Plot
if with_plots:
diff --git a/setup.cfg b/setup.cfg
index 935d6c9d..d88b5ae0 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -9,5 +9,5 @@ install_requires =
numpy >= 1.26.3
scipy >= 1.11.4
cython >= 3.0.7
- nose-py3 >= 1.6.3
+ pytest >= 7.4.4
matplotlib > 3
diff --git a/tests/solvers/test_euler.py b/tests/solvers/test_euler.py
index 501f2e8a..87e1b7c7 100644
--- a/tests/solvers/test_euler.py
+++ b/tests/solvers/test_euler.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.euler import ExplicitEuler, ImplicitEuler
from assimulo.problem import Explicit_Problem
@@ -118,15 +118,16 @@ def init_mode(self, solver):
class Test_Explicit_Euler:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y: 1.0
y0 = 1.0
- self.problem = Explicit_Problem(f, y0)
- self.simulator = ExplicitEuler(self.problem)
+ cls.problem = Explicit_Problem(f, y0)
+ cls.simulator = ExplicitEuler(cls.problem)
@testattr(stddist = True)
def test_event_localizer(self):
@@ -141,17 +142,18 @@ def test_event_localizer(self):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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)
@testattr(stddist = True)
def test_h(self):
- nose.tools.assert_almost_equal(self.simulator.h, 0.01)
+ assert self.simulator.h == pytest.approx(0.01)
self.simulator.h = 1.0
- nose.tools.assert_almost_equal(self.simulator.h, 1.0)
- nose.tools.assert_raises(AssimuloException, self.simulator._set_h, [1])
+ assert self.simulator.h == pytest.approx(1.0)
+ with pytest.raises(AssimuloException):
+ self.simulator._set_h([1])
@testattr(stddist = True)
def test_time_event(self):
@@ -175,9 +177,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -187,7 +189,7 @@ def handle_event(solver, event_info):
exp_sim = ExplicitEuler(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_integrator(self):
@@ -196,8 +198,8 @@ def test_integrator(self):
"""
values = self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_step(self):
@@ -209,8 +211,8 @@ def test_step(self):
self.simulator.h = 0.1
self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_exception(self):
@@ -223,7 +225,8 @@ def f(t,y):
prob = Explicit_Problem(f,0.0)
sim = ExplicitEuler(prob)
- nose.tools.assert_raises(NotImplementedError, sim.simulate, 1.0)
+ with pytest.raises(NotImplementedError):
+ sim.simulate(1.0)
@testattr(stddist = True)
def test_switches(self):
@@ -242,9 +245,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = ExplicitEuler(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_time_limit(self):
@@ -262,30 +265,31 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
class Test_Implicit_Euler:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y: 1.0
y0 = 1.0
- self.problem = Explicit_Problem(f, y0)
- self.simulator = ImplicitEuler(self.problem)
+ cls.problem = Explicit_Problem(f, y0)
+ cls.simulator = ImplicitEuler(cls.problem)
@testattr(stddist = True)
def test_reset_statistics(self):
- nose.tools.assert_equal(self.simulator.statistics["nsteps"], 0)
+ assert self.simulator.statistics["nsteps"] == 0
self.simulator.simulate(5)
nsteps = self.simulator.statistics["nsteps"]
self.simulator.simulate(6)
- nose.tools.assert_less(self.simulator.statistics["nsteps"], nsteps)
+ assert self.simulator.statistics["nsteps"] < nsteps
@testattr(stddist = True)
def test_usejac_csc_matrix(self):
@@ -301,23 +305,24 @@ def test_usejac_csc_matrix(self):
exp_sim = ImplicitEuler(exp_mod)
exp_sim.simulate(5.,100)
- nose.tools.assert_equal(exp_sim.statistics["nfcnjacs"], 0)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.995500, 4)
+ assert exp_sim.statistics["nfcnjacs"] == 0
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, rel = 1e-4)
exp_sim.reset()
exp_sim.usejac=False
exp_sim.simulate(5.,100)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.995500, 4)
- nose.tools.assert_greater(exp_sim.statistics["nfcnjacs"], 0)
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.995500, rel = 1e-4)
+ assert exp_sim.statistics["nfcnjacs"] > 0
@testattr(stddist = True)
def test_h(self):
- nose.tools.assert_almost_equal(self.simulator.h, 0.01)
+ assert self.simulator.h == pytest.approx(0.01)
self.simulator.h = 1.0
- nose.tools.assert_almost_equal(self.simulator.h, 1.0)
- nose.tools.assert_raises(AssimuloException, self.simulator._set_h, [1])
+ assert self.simulator.h == pytest.approx(1.0)
+ with pytest.raises(AssimuloException):
+ self.simulator._set_h([1])
@testattr(stddist = True)
def test_time_event(self):
@@ -341,9 +346,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -353,7 +358,7 @@ def handle_event(solver, event_info):
exp_sim = ImplicitEuler(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_integrator(self):
@@ -362,8 +367,8 @@ def test_integrator(self):
"""
values = self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_step(self):
@@ -375,8 +380,8 @@ def test_step(self):
self.simulator.h = 0.1
self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_stiff_problem(self):
@@ -391,7 +396,7 @@ def test_stiff_problem(self):
y_correct = lambda t: np.exp(-15*t)
abs_err = np.abs(y[:,0]-y_correct(np.array(t)))
- nose.tools.assert_less(np.max(abs_err), 0.1)
+ assert np.max(abs_err) < 0.1
@testattr(stddist = True)
def test_switches(self):
@@ -410,9 +415,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = ImplicitEuler(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_time_limit(self):
@@ -430,5 +435,5 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
diff --git a/tests/solvers/test_glimda.py b/tests/solvers/test_glimda.py
index ba7d06be..59cc28db 100644
--- a/tests/solvers/test_glimda.py
+++ b/tests/solvers/test_glimda.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers import GLIMDA
from assimulo.problem import Implicit_Problem, Explicit_Problem
@@ -27,7 +27,8 @@ class Test_GLIMDA:
"""
Tests the GLIMDA solver.
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -47,17 +48,17 @@ def f(t,y,yd):
yd0 = [-.6,-200000.]
#Define an Assimulo problem
- self.mod = Implicit_Problem(f,y0,yd0)
- self.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
+ cls.mod = Implicit_Problem(f,y0,yd0)
+ cls.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
#Define an explicit solver
- self.sim = GLIMDA(self.mod) #Create a Radau5 solve
- self.sim_t0 = GLIMDA(self.mod_t0)
+ cls.sim = GLIMDA(cls.mod) #Create a Radau5 solve
+ cls.sim_t0 = GLIMDA(cls.mod_t0)
#Sets the parameters
- self.sim.atol = 1e-4 #Default 1e-6
- self.sim.rtol = 1e-4 #Default 1e-6
- self.sim.inith = 1.e-4 #Initial step-size
+ cls.sim.atol = 1e-4 #Default 1e-6
+ cls.sim.rtol = 1e-4 #Default 1e-6
+ cls.sim.inith = 1.e-4 #Initial step-size
@testattr(stddist = True)
def test_simulate_explicit(self):
@@ -70,126 +71,134 @@ def test_simulate_explicit(self):
problem = Explicit_Problem(f,y0)
simulator = GLIMDA(problem)
- nose.tools.assert_equal(simulator.yd0[0], -simulator.y0[0])
+ assert simulator.yd0[0] == -simulator.y0[0]
t,y = simulator.simulate(1.0)
- nose.tools.assert_almost_equal(float(y[-1]), float(np.exp(-1.0)),4)
+ assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
@testattr(stddist = True)
def test_maxord(self):
"""
Tests the maximum order of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.maxord, 3)#Default
- nose.tools.assert_equal(self.sim.options["maxord"], 3)
+ assert self.sim.maxord == 3#Default
+ assert self.sim.options["maxord"] == 3
self.sim.maxord = 2
- nose.tools.assert_equal(self.sim.maxord, 2)#Default
- nose.tools.assert_equal(self.sim.options["maxord"], 2)
+ assert self.sim.maxord == 2#Default
+ assert self.sim.options["maxord"] == 2
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_maxord, 4)
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_maxord, 0)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_maxord(4)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_maxord(0)
@testattr(stddist = True)
def test_minord(self):
"""
Tests the minimum order of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.minord, 1)#Default
- nose.tools.assert_equal(self.sim.options["minord"], 1)
+ assert self.sim.minord == 1#Default
+ assert self.sim.options["minord"] == 1
self.sim.minord = 2
- nose.tools.assert_equal(self.sim.minord, 2)#Default
- nose.tools.assert_equal(self.sim.options["minord"], 2)
+ assert self.sim.minord == 2#Default
+ assert self.sim.options["minord"] == 2
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_minord, 4)
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_minord, 0)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_minord(4)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_minord(0)
@testattr(stddist = True)
def test_maxsteps(self):
"""
Tests the maximum allowed steps of GLIMDA
"""
- nose.tools.assert_equal(self.sim.maxsteps, 100000)
- nose.tools.assert_equal(self.sim.options["maxsteps"], 100000)
+ assert self.sim.maxsteps == 100000
+ assert self.sim.options["maxsteps"] == 100000
self.sim.maxsteps = 100
- nose.tools.assert_equal(self.sim.maxsteps, 100)
- nose.tools.assert_equal(self.sim.options["maxsteps"], 100)
+ assert self.sim.maxsteps == 100
+ assert self.sim.options["maxsteps"] == 100
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_maxsteps, -1)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_maxsteps(-1)
@testattr(stddist = True)
def test_newt(self):
"""
Tests the maximum allowed number of Newton iterations GLIMDA
"""
- nose.tools.assert_equal(self.sim.newt, 5)
- nose.tools.assert_equal(self.sim.options["newt"], 5)
+ assert self.sim.newt == 5
+ assert self.sim.options["newt"] == 5
self.sim.newt = 3
- nose.tools.assert_equal(self.sim.newt, 3)
- nose.tools.assert_equal(self.sim.options["newt"], 3)
+ assert self.sim.newt == 3
+ assert self.sim.options["newt"] == 3
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_newt, -1)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_newt(-1)
@testattr(stddist = True)
def test_minh(self):
"""
Tests the minimum stepsize of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.minh, np.finfo(np.double).eps)
- nose.tools.assert_equal(self.sim.options["minh"], np.finfo(np.double).eps)
+ assert self.sim.minh == np.finfo(np.double).eps
+ assert self.sim.options["minh"] == np.finfo(np.double).eps
self.sim.minh = 1e-5
- nose.tools.assert_equal(self.sim.minh, 1e-5)
- nose.tools.assert_equal(self.sim.options["minh"], 1e-5)
+ assert self.sim.minh == 1e-5
+ assert self.sim.options["minh"] == 1e-5
@testattr(stddist = True)
def test_order(self):
"""
Tests the order of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.order, 0)
- nose.tools.assert_equal(self.sim.options["order"], 0)
+ assert self.sim.order == 0
+ assert self.sim.options["order"] == 0
self.sim.order = 1
- nose.tools.assert_equal(self.sim.order, 1)
- nose.tools.assert_equal(self.sim.options["order"], 1)
+ assert self.sim.order == 1
+ assert self.sim.options["order"] == 1
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_order, -1)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_order(-1)
@testattr(stddist = True)
def test_maxh(self):
"""
Tests the maximum stepsize of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.maxh, np.inf)
- nose.tools.assert_equal(self.sim.options["maxh"], np.inf)
+ assert self.sim.maxh == np.inf
+ assert self.sim.options["maxh"] == np.inf
self.sim.maxh = 1e5
- nose.tools.assert_equal(self.sim.maxh, 1e5)
- nose.tools.assert_equal(self.sim.options["maxh"], 1e5)
+ assert self.sim.maxh == 1e5
+ assert self.sim.options["maxh"] == 1e5
@testattr(stddist = True)
def test_maxretry(self):
"""
Tests the maximum number of retries of GLIMDA.
"""
- nose.tools.assert_equal(self.sim.maxretry, 15)
- nose.tools.assert_equal(self.sim.options["maxretry"], 15)
+ assert self.sim.maxretry == 15
+ assert self.sim.options["maxretry"] == 15
self.sim.maxretry = 10
- nose.tools.assert_equal(self.sim.maxretry, 10)
- nose.tools.assert_equal(self.sim.options["maxretry"], 10)
+ assert self.sim.maxretry == 10
+ assert self.sim.options["maxretry"] == 10
- nose.tools.assert_raises(GLIMDA_Exception, self.sim._set_maxretry, -1)
+ with pytest.raises(GLIMDA_Exception):
+ self.sim._set_maxretry(-1)
diff --git a/tests/solvers/test_kinsol.py b/tests/solvers/test_kinsol.py
index 7a886e2c..e95446d8 100644
--- a/tests/solvers/test_kinsol.py
+++ b/tests/solvers/test_kinsol.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.kinsol import KINSOL
from assimulo.problem import Algebraic_Problem
@@ -26,9 +26,9 @@ class Test_KINSOL:
def test_problem_name_attribute(self):
res = lambda y: y
model = Algebraic_Problem(res, 1)
- nose.tools.assert_equal(model.name, "---")
+ assert model.name == "---"
model = Algebraic_Problem(res, 1, name="Test")
- nose.tools.assert_equal(model.name, "Test")
+ assert model.name == "Test"
@testattr(stddist = True)
def test_properties_simple(self):
@@ -37,19 +37,19 @@ def test_properties_simple(self):
solver = KINSOL(model)
solver.max_iter = 150
- nose.tools.assert_equal(solver.max_iter, 150)
+ assert solver.max_iter == 150
solver.no_initial_setup = True
- nose.tools.assert_true(solver.no_initial_setup)
+ assert solver.no_initial_setup
solver.max_solves_between_setup_calls = 15
- nose.tools.assert_equal(solver.max_solves_between_setup_calls, 15)
+ assert solver.max_solves_between_setup_calls == 15
solver.max_newton_step = 1.0
- nose.tools.assert_equal(solver.max_newton_step, 1.0)
+ assert solver.max_newton_step == 1.0
solver.no_min_epsilon = True
- nose.tools.assert_true(solver.no_min_epsilon)
+ assert solver.no_min_epsilon
solver.max_beta_fails = 15
- nose.tools.assert_equal(solver.max_beta_fails, 15)
+ assert solver.max_beta_fails == 15
diff --git a/tests/solvers/test_odassl.py b/tests/solvers/test_odassl.py
index 973ac05d..099c9cce 100644
--- a/tests/solvers/test_odassl.py
+++ b/tests/solvers/test_odassl.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.odassl import ODASSL
from assimulo.problem import Implicit_Problem
@@ -24,7 +24,8 @@
class Test_ODASSL:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
@@ -32,8 +33,8 @@ def setUp(self):
y0 = [1.0, 1.0, 1.0]
yd0 = [-1.0, -1.0, -1.0]
- self.problem = Overdetermined_Problem(f,y0, yd0)
- self.simulator = ODASSL(self.problem)
+ cls.problem = Overdetermined_Problem(f,y0, yd0)
+ cls.simulator = ODASSL(cls.problem)
@testattr(stddist = True)
def test_overdetermined(self):
diff --git a/tests/solvers/test_odepack.py b/tests/solvers/test_odepack.py
index b5037e67..212a9b97 100644
--- a/tests/solvers/test_odepack.py
+++ b/tests/solvers/test_odepack.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.lib.odepack import dsrcar, dcfode
from assimulo.solvers import LSODAR
@@ -122,7 +122,8 @@ class Test_LSODAR:
"""
Tests the LSODAR solver.
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -167,16 +168,16 @@ def jac_sparse(t,y):
exp_mod.jac = jac
exp_mod_sp.jac = jac_sparse
- self.mod = exp_mod
+ cls.mod = exp_mod
#Define an explicit solver
- self.sim = LSODAR(exp_mod) #Create a LSODAR solve
- self.sim_sp = LSODAR(exp_mod_sp)
+ cls.sim = LSODAR(exp_mod) #Create a LSODAR solve
+ cls.sim_sp = LSODAR(exp_mod_sp)
#Sets the parameters
- self.sim.atol = 1e-6 #Default 1e-6
- self.sim.rtol = 1e-6 #Default 1e-6
- self.sim.usejac = False
+ cls.sim.atol = 1e-6 #Default 1e-6
+ cls.sim.rtol = 1e-6 #Default 1e-6
+ cls.sim.usejac = False
@testattr(stddist = True)
def test_event_localizer(self):
@@ -191,9 +192,9 @@ def test_event_localizer(self):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
@testattr(stddist = True)
def test_simulation(self):
@@ -202,13 +203,13 @@ def test_simulation(self):
"""
self.sim.simulate(1.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_setcoefficients(self):
elco,tesco=dcfode(1)
- nose.tools.assert_almost_equal(elco[0,2],5./12.,9) # AM-2
- nose.tools.assert_almost_equal(tesco[0,2],2.,9) # AM-2 error coeff
+ assert_almost_equal(elco[0,2],5./12.,9) # AM-2
+ assert_almost_equal(tesco[0,2],2.,9) # AM-2 error coeff
@testattr(stddist = True)
def test_readcommon(self):
@@ -219,8 +220,8 @@ def test_readcommon(self):
r=np.ones((245,),'d')
i=np.ones((55,),'i')
dsrcar(r,i,1)
- nose.tools.assert_almost_equal(r[217], 2.22044605e-16, 20)
- nose.tools.assert_equal(i[36], 3)
+ assert r[217] == pytest.approx(2.22044605e-16, rel = 1e-20)
+ assert i[36] == 3
@testattr(stddist = True)
def test_writereadcommon(self):
@@ -233,8 +234,8 @@ def test_writereadcommon(self):
r[0]=100.
i[0]=10
dsrcar(r,i,1)
- nose.tools.assert_almost_equal(r[0], 1., 4)
- nose.tools.assert_equal(i[0], 1)
+ assert r[0] == pytest.approx(1., rel = 1e-4)
+ assert i[0] == 1
def test_rkstarter(self):
"""
@@ -275,7 +276,7 @@ def test_interpol(self):
self.sim.reset()
t_sol1,y_sol1=self.sim.simulate(0.5)
ind05=np.nonzero(np.array(t_sol)==0.5)[0][0]
- nose.tools.assert_almost_equal(y_sol[ind05,0],y_sol1[-1,0],6)
+ assert_almost_equal(y_sol[ind05,0],y_sol1[-1,0],6)
@testattr(stddist = True)
def test_simulation_with_jac(self):
@@ -285,13 +286,13 @@ def test_simulation_with_jac(self):
self.sim.usejac = True
self.sim.simulate(1.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp(self):
self.sim.simulate(1.,100) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_usejac_csc_matrix(self):
@@ -299,32 +300,32 @@ def test_usejac_csc_matrix(self):
self.sim_sp.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim_sp.statistics["nfcnjacs"], 0)
+ assert self.sim_sp.statistics["nfcnjacs"] == 0
- nose.tools.assert_almost_equal(self.sim_sp.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp_list(self):
self.sim.simulate(1.,ncp_list=[0.5]) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_maxh(self):
self.sim.hmax = 1.0
- nose.tools.assert_equal(self.sim.options["maxh"], 1.0)
- nose.tools.assert_equal(self.sim.maxh, 1.0)
+ assert self.sim.options["maxh"] == 1.0
+ assert self.sim.maxh == 1.0
self.sim.maxh = 2.0
- nose.tools.assert_equal(self.sim.options["maxh"], 2.0)
- nose.tools.assert_equal(self.sim.maxh, 2.0)
+ assert self.sim.options["maxh"] == 2.0
+ assert self.sim.maxh == 2.0
@testattr(stddist = True)
def test_simulation_ncp_list_2(self):
self.sim.simulate(1.,ncp_list=[0.5,4]) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp_with_jac(self):
@@ -334,7 +335,7 @@ def test_simulation_ncp_with_jac(self):
self.sim.usejac= True
self.sim.simulate(1.,100) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], -1.863646028, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(-1.863646028, rel = 1e-4)
@testattr(stddist = True)
def test_time_limit(self):
@@ -352,5 +353,5 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
diff --git a/tests/solvers/test_radau5.py b/tests/solvers/test_radau5.py
index 5731d623..24a11710 100644
--- a/tests/solvers/test_radau5.py
+++ b/tests/solvers/test_radau5.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.radau5 import Radau5DAE, _Radau5DAE
from assimulo.solvers.radau5 import Radau5ODE, _Radau5ODE
@@ -169,7 +169,8 @@ class Test_Explicit_Radau5_Py:
"""
Tests the explicit Radau solver (Python implementation).
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -200,17 +201,17 @@ def jac(t,y):
exp_mod_t0 = Explicit_Problem(f,y0,1.0)
exp_mod.jac = jac
- self.mod = exp_mod
+ cls.mod = exp_mod
#Define an explicit solver
- self.sim = _Radau5ODE(exp_mod) #Create a Radau5 solve
- self.sim_t0 = _Radau5ODE(exp_mod_t0)
+ cls.sim = _Radau5ODE(exp_mod) #Create a Radau5 solve
+ cls.sim_t0 = _Radau5ODE(exp_mod_t0)
#Sets the parameters
- self.sim.atol = 1e-4 #Default 1e-6
- self.sim.rtol = 1e-4 #Default 1e-6
- self.sim.inith = 1.e-4 #Initial step-size
- self.sim.usejac = False
+ cls.sim.atol = 1e-4 #Default 1e-6
+ cls.sim.rtol = 1e-4 #Default 1e-6
+ cls.sim.inith = 1.e-4 #Initial step-size
+ cls.sim.usejac = False
@testattr(stddist = True)
def test_event_localizer(self):
@@ -226,9 +227,9 @@ def test_event_localizer(self):
# t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
# #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_almost_equal(y[-1][0],8.0)
+ # assert_almost_equal(y[-1][1],3.0)
+ # assert_almost_equal(y[-1][2],2.0)
@testattr(stddist = True)
def test_time_event(self):
@@ -252,9 +253,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -264,7 +265,7 @@ def handle_event(solver, event_info):
exp_sim = _Radau5ODE(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_init(self):
@@ -272,7 +273,7 @@ def test_init(self):
#Test both y0 in problem and not.
sim = _Radau5ODE(self.mod)
- nose.tools.assert_equal(sim._leny, 2)
+ assert sim._leny == 2
@testattr(stddist = True)
def test_collocation_polynomial(self):
@@ -283,25 +284,25 @@ def test_collocation_polynomial(self):
self.sim.simulate(2.,200) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- #nose.tools.assert_almost_equal(self.sim.y[-2][0], 1.71505001, 4)
+ #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4)
print
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
self.sim.report_continuously = True
self.sim.reset()
self.sim.simulate(2.,200) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- #nose.tools.assert_almost_equal(self.sim.y[-2][0], 1.71505001, 4)
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
self.sim_t0.simulate(3.)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[0], 1.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[-1], 3.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4)
+ assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4)
+ assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation(self):
@@ -310,9 +311,9 @@ def test_simulation(self):
"""
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp(self):
@@ -322,13 +323,13 @@ def test_simulation_ncp(self):
self.sim.report_continuously = True
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
self.sim.reset()
self.sim.report_continuously = False
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
@testattr(stddist = True)
def test_usejac(self):
@@ -339,9 +340,9 @@ def test_usejac(self):
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nfcnjacs"], 0)
+ assert self.sim.statistics["nfcnjacs"] == 0
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_thet(self):
@@ -351,7 +352,7 @@ def test_thet(self):
self.sim.thet = -1
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nsteps"], self.sim.statistics["njacs"])
+ assert self.sim.statistics["nsteps"] == self.sim.statistics["njacs"]
@testattr(stddist = True)
def test_maxh(self):
@@ -360,7 +361,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
+ assert max(np.diff(self.sim.t_sol))-np.finfo('double').eps <= 0.01
@testattr(stddist = True)
def test_newt(self):
@@ -370,7 +371,7 @@ def test_newt(self):
self.sim.newt = 10
self.sim.simulate(1.0)
- nose.tools.assert_equal(self.sim.statistics["nnfails"], 1)
+ assert self.sim.statistics["nnfails"] == 1
@testattr(stddist = True)
def test_safe(self):
@@ -379,7 +380,7 @@ def test_safe(self):
"""
self.sim.safe = 0.99
self.sim.simulate(1.0)
- nose.tools.assert_less(self.sim.statistics["nsteps"], 150)
+ assert self.sim.statistics["nsteps"] < 150
@testattr(stddist = True)
def test_reset_statistics(self):
@@ -392,7 +393,7 @@ def test_reset_statistics(self):
self.sim.reset()
self.sim.simulate(1.0)
- nose.tools.assert_less(self.sim.statistics["nsteps"], steps*1.5)
+ assert self.sim.statistics["nsteps"] < steps*1.5
@testattr(stddist = True)
def test_atol(self):
@@ -411,24 +412,25 @@ def test_atol(self):
self.sim.simulate(1.0)
steps2 = self.sim.statistics["nsteps"]
- nose.tools.assert_greater(steps2, steps)
+ assert steps2 > steps
self.sim.reset()
self.sim.atol = [1e-8, 1e-8]
steps3 = self.sim.statistics["nsteps"]
- nose.tools.assert_equal(steps3, steps2)
+ assert steps3 == steps2
err_msg = "atol must be of length one or same as the dimension of the problem."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
self.sim.atol = [1e-6,1e-6,1e-6]
class Test_Explicit_Radau5:
"""
Tests the explicit Radau solver.
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -473,18 +475,18 @@ def jac_sparse(t,y):
exp_mod.jac = jac
exp_mod_sp.jac = jac_sparse
- self.mod = exp_mod
+ cls.mod = exp_mod
#Define an explicit solver
- self.sim = Radau5ODE(exp_mod) #Create a Radau5 solve
- self.sim_t0 = Radau5ODE(exp_mod_t0)
- self.sim_sp = Radau5ODE(exp_mod_sp)
+ cls.sim = Radau5ODE(exp_mod) #Create a Radau5 solve
+ cls.sim_t0 = Radau5ODE(exp_mod_t0)
+ cls.sim_sp = Radau5ODE(exp_mod_sp)
#Sets the parameters
- self.sim.atol = 1e-4 #Default 1e-6
- self.sim.rtol = 1e-4 #Default 1e-6
- self.sim.inith = 1.e-4 #Initial step-size
- self.sim.usejac = False
+ cls.sim.atol = 1e-4 #Default 1e-6
+ cls.sim.rtol = 1e-4 #Default 1e-6
+ cls.sim.inith = 1.e-4 #Initial step-size
+ cls.sim.usejac = False
@testattr(stddist = True)
def test_event_localizer(self):
@@ -499,9 +501,9 @@ def test_event_localizer(self):
t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points
#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_almost_equal(y[-1][0],8.0)
+ assert_almost_equal(y[-1][1],3.0)
+ assert_almost_equal(y[-1][2],2.0)
@testattr(stddist = True)
def test_nbr_fcn_evals_due_to_jac(self):
@@ -510,12 +512,12 @@ def test_nbr_fcn_evals_due_to_jac(self):
sim.usejac = False
sim.simulate(1)
- nose.tools.assert_greater(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] > 0
sim = Radau5ODE(self.mod)
sim.simulate(1)
- nose.tools.assert_equal(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] == 0
@testattr(stddist = True)
def test_time_event(self):
@@ -539,9 +541,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -551,7 +553,7 @@ def handle_event(solver, event_info):
exp_sim = Radau5ODE(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_init(self):
@@ -559,7 +561,7 @@ def test_init(self):
#Test both y0 in problem and not.
sim = Radau5ODE(self.mod)
- nose.tools.assert_equal(sim._leny, 2)
+ assert sim._leny == 2
@testattr(stddist = True)
def test_collocation_polynomial(self):
@@ -570,24 +572,24 @@ def test_collocation_polynomial(self):
self.sim.simulate(2.,200) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- #nose.tools.assert_almost_equal(self.sim.y[-2][0], 1.71505001, 4)
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
self.sim.report_continuously = True
self.sim.reset()
self.sim.simulate(2.,200) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- #nose.tools.assert_almost_equal(self.sim.y[-2][0], 1.71505001, 4)
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ #assert self.sim.y[-2][0] == pytest.approx(1.71505001, rel = 1e-4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
self.sim_t0.simulate(3.)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[0], 1.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[-1], 3.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4)
+ assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4)
+ assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation(self):
@@ -596,9 +598,9 @@ def test_simulation(self):
"""
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_less(self.sim.statistics["nsteps"], 300)
+ assert self.sim.statistics["nsteps"] < 300
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp(self):
@@ -608,13 +610,13 @@ def test_simulation_ncp(self):
self.sim.report_continuously = True
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
self.sim.reset()
self.sim.report_continuously = False
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
@testattr(stddist = True)
def test_usejac(self):
@@ -625,9 +627,9 @@ def test_usejac(self):
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nfcnjacs"], 0)
+ assert self.sim.statistics["nfcnjacs"] == 0
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_usejac_csc_matrix(self):
@@ -638,9 +640,9 @@ def test_usejac_csc_matrix(self):
self.sim_sp.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim_sp.statistics["nfcnjacs"], 0)
+ assert self.sim_sp.statistics["nfcnjacs"] == 0
- nose.tools.assert_almost_equal(self.sim_sp.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_sp.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_thet(self):
@@ -650,7 +652,7 @@ def test_thet(self):
self.sim.thet = -1
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nsteps"], self.sim.statistics["njacs"])
+ assert self.sim.statistics["nsteps"] == self.sim.statistics["njacs"]
@testattr(stddist = True)
def test_maxh(self):
@@ -659,7 +661,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
+ assert max(np.diff(self.sim.t_sol))-np.finfo('double').eps <= 0.01
@testattr(stddist = True)
def test_newt(self):
@@ -671,7 +673,7 @@ def test_newt(self):
# self.sim.reset()
# self.sim.newt = 10
# self.sim.simulate(1.0)
- # nose.tools.assert_equal(self.sim.statistics["nniterfail"], 1)
+ # assert_equal(self.sim.statistics["nniterfail"], 1)
@testattr(stddist = True)
def test_safe(self):
@@ -680,7 +682,7 @@ def test_safe(self):
"""
self.sim.safe = 0.99
self.sim.simulate(1.0)
- nose.tools.assert_less(self.sim.statistics["nsteps"], 150)
+ assert self.sim.statistics["nsteps"] < 150
@testattr(stddist = True)
def test_reset_statistics(self):
@@ -693,14 +695,14 @@ def test_reset_statistics(self):
self.sim.reset()
self.sim.simulate(1.0)
- nose.tools.assert_less(self.sim.statistics["nsteps"], steps*1.5)
+ assert self.sim.statistics["nsteps"] < steps*1.5
@testattr(stddist = True)
def test_weighted_error(self):
def handle_result(solver, t, y):
err = solver.get_weighted_local_errors()
- nose.tools.assert_equal(len(err), len(y))
+ assert len(err) == len(y)
self.mod.handle_result = handle_result
@@ -726,17 +728,17 @@ def test_atol(self):
self.sim.simulate(1.0)
steps2 = self.sim.statistics["nsteps"]
- nose.tools.assert_greater(steps2, steps)
+ assert steps2 > steps
self.sim.reset()
self.sim.atol = [1e-8, 1e-8]
steps3 = self.sim.statistics["nsteps"]
- nose.tools.assert_equal(steps3, steps2)
+ assert steps3 == steps2
err_msg = "atol must be of length one or same as the dimension of the problem."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
self.sim.atol = [1e-6,1e-6,1e-6]
@testattr(stddist = True)
@@ -756,9 +758,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = Radau5ODE(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_nmax_steps(self):
@@ -771,7 +773,7 @@ def test_nmax_steps(self):
sim.maxsteps = 9
err_msg = f'Radau5 failed with flag -5. At time {float_regex}. Message: Maximal number of steps = 9 exceeded.'
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -788,7 +790,7 @@ def test_step_size_too_small(self):
sim.maxh = 1.e-1
err_msg = f"Radau5 failed with flag -6. At time {float_regex}. Message: Stepsize too small with h = {float_regex}."
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1. + 1.e-16)
@testattr(stddist = True)
@@ -803,7 +805,7 @@ def f(t, y):
sim = Radau5ODE(prob)
err_msg = f'Repeated unexpected step rejections.'
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -820,7 +822,7 @@ def test_sparse_solver_jac_disabled(self):
sim.usejac = False
sim.simulate(1.)
- nose.tools.assert_equal(sim.linear_solver, 'DENSE')
+ assert sim.linear_solver == 'DENSE'
@testattr(stddist = True)
def test_solver_no_jac(self):
@@ -835,7 +837,7 @@ def test_solver_no_jac(self):
sim.usejac = True
err_msg = "Use of an analytical Jacobian is enabled, but problem does contain a 'jac' function."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -855,7 +857,7 @@ def test_solver_sparse_jac_wrong_format(self):
sim.usejac = True
err_msg = f'Radau5 failed with flag -11. At time {float_regex}. Message: Jacobian given in wrong format, required sparsity format: CSC.'
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -876,7 +878,7 @@ def test_solver_sparse_jac_nnz_too_small(self):
sim.usejac = True
err_msg = f'Radau5 failed with flag -9. At time {float_regex}. Message: Number of nonzero elements in provided jacobian is too small, specified = 1, actual = 5.'
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -914,7 +916,7 @@ def test_sparse_solver_no_nnz(self):
sim.usejac = True
err_msg = "Number of non-zero elements of sparse Jacobian must be non-negative. Detected default value of '-1', has 'problem.jac_fcn_nnz' been set?"
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -936,7 +938,7 @@ def test_sparse_solver_invalid_nnz_type(self):
sim.usejac = True
err_msg = "Number of non-zero elements of sparse Jacobian must be an integer, received: {}."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg.format(nnz)):
+ with pytest.raises(Radau_Exception, err_msg.format(nnz)):
sim.simulate(1.)
@testattr(stddist = True)
@@ -958,7 +960,7 @@ def test_sparse_solver_invalid_nnz_negative(self):
sim.usejac = True
err_msg = "Number of non-zero elements of sparse Jacobian must be non-negative, given value = {}."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg.format(nnz)):
+ with pytest.raises(Radau_Exception, err_msg.format(nnz)):
sim.simulate(1.)
@testattr(stddist = True)
@@ -980,7 +982,7 @@ def test_sparse_solver_invalid_nnz_too_large(self):
sim.usejac = True
err_msg = "Number of non-zero elements of sparse Jacobian infeasible, must be smaller than the problem dimension squared."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
sim.simulate(1.)
def test_sparse_solver_jacobian(self):
@@ -1009,7 +1011,7 @@ def test_sparse_solver_jacobian(self):
sim.linear_solver = 'SPARSE'
sim.usejac = True
- nose.tools.ok_(sim.simulate(1.), msg = f"Jacobian #{i} failed: {jac(0, 0)}")
+ ok_(sim.simulate(1.), msg = f"Jacobian #{i} failed: {jac(0, 0)}")
@testattr(stddist = True)
def test_linear_solver(self):
@@ -1017,22 +1019,22 @@ def test_linear_solver(self):
This tests the functionality of the property linear_solver.
"""
self.sim.linear_solver = 'dense'
- nose.tools.assert_equal(self.sim.linear_solver, 'DENSE')
+ assert self.sim.linear_solver == 'DENSE'
self.sim.linear_solver = 'sparse'
- nose.tools.assert_equal(self.sim.linear_solver, 'SPARSE')
+ assert self.sim.linear_solver == 'SPARSE'
self.sim.linear_solver = 'DENSE'
- nose.tools.assert_equal(self.sim.linear_solver, 'DENSE')
+ assert self.sim.linear_solver == 'DENSE'
self.sim.linear_solver = 'SPARSE'
- nose.tools.assert_equal(self.sim.linear_solver, 'SPARSE')
+ assert self.sim.linear_solver == 'SPARSE'
err_msg = "'linear_solver' parameter needs to be either 'DENSE' or 'SPARSE'. Set value: {}"
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg.format('default')):
+ with pytest.raises(Radau_Exception, err_msg.format('default')):
self.sim.linear_solver = 'default'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg.format('GMRES')):
+ with pytest.raises(Radau_Exception, err_msg.format('GMRES')):
self.sim.linear_solver = 'GMRES'
err_msg = "'linear_solver' parameter needs to be the STRING 'DENSE' or 'SPARSE'. Set value: {}, type: {}"
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg.format('0', "")):
+ with pytest.raises(Radau_Exception, err_msg.format('0', "")):
self.sim.linear_solver = 0
@testattr(stddist = True)
@@ -1047,7 +1049,7 @@ def test_keyboard_interrupt_fcn(self):
sim.simulate(1.)
raise Exception("Simulation passed without interrupt.")
except KeyboardInterrupt as e:
- nose.tools.assert_equal(str(e), "f")
+ assert str(e) == "f"
@testattr(stddist = True)
def test_keyboard_interrupt_jac(self):
@@ -1064,7 +1066,7 @@ def test_keyboard_interrupt_jac(self):
sim.simulate(1.)
raise Exception("Simulation passed without interrupt.")
except KeyboardInterrupt as e:
- nose.tools.assert_equal(str(e), "jac")
+ assert str(e) == "jac"
@testattr(stddist = True)
def test_keyboard_interrupt_jac_sparse(self):
@@ -1083,7 +1085,7 @@ def test_keyboard_interrupt_jac_sparse(self):
sim.simulate(1.)
raise Exception("Simulation passed without interrupt.")
except KeyboardInterrupt as e:
- nose.tools.assert_equal(str(e), "jac")
+ assert str(e) == "jac"
@testattr(stddist = True)
def test_keyboard_interrupt_event_indicator(self):
@@ -1100,7 +1102,7 @@ def test_keyboard_interrupt_event_indicator(self):
sim.simulate(1.)
raise Exception("Simulation passed without interrupt.")
except KeyboardInterrupt as e:
- nose.tools.assert_equal(str(e), "event")
+ assert str(e) == "event"
@testattr(stddist = True)
def test_time_limit(self):
@@ -1118,7 +1120,7 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -1154,7 +1156,8 @@ class Test_Implicit_Radau5:
"""
Tests the implicit Radau solver.
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -1174,24 +1177,24 @@ def f(t,y,yd):
yd0 = [-.6,-200000.]
#Define an Assimulo problem
- self.mod = Implicit_Problem(f,y0,yd0)
- self.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
+ cls.mod = Implicit_Problem(f,y0,yd0)
+ cls.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
#Define an implicit solver
- self.sim = Radau5DAE(self.mod) #Create a Radau5 solve
- self.sim_t0 = Radau5DAE(self.mod_t0)
+ cls.sim = Radau5DAE(cls.mod) #Create a Radau5 solve
+ cls.sim_t0 = Radau5DAE(cls.mod_t0)
#Sets the parameters
- self.sim.atol = 1e-4 #Default 1e-6
- self.sim.rtol = 1e-4 #Default 1e-6
- self.sim.inith = 1.e-4 #Initial step-size
+ cls.sim.atol = 1e-4 #Default 1e-6
+ cls.sim.rtol = 1e-4 #Default 1e-6
+ cls.sim.inith = 1.e-4 #Initial step-size
@testattr(stddist = True)
def test_implementation_get(self):
"""
Test getting of implementation property of Radau5DAE.
"""
- nose.tools.assert_equal(self.sim.implementation, 'f')
+ assert self.sim.implementation == 'f'
@testattr(stddist = True)
def test_implementation_set(self):
@@ -1199,7 +1202,7 @@ def test_implementation_set(self):
Test setting of implementation property of Radau5DAE.
"""
err_msg = "Radau5DAE does not support setting the 'implementation' attribute, since it only supports the Fortran implementation of Radau5."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
self.sim.implementation = 'c'
@testattr(stddist = True)
@@ -1207,7 +1210,7 @@ def test_linear_solver_get(self):
"""
Test getting of linear_solver property of Radau5DAE.
"""
- nose.tools.assert_equal(self.sim.linear_solver, 'DENSE')
+ assert self.sim.linear_solver == 'DENSE'
@testattr(stddist = True)
def test_linear_solver_set(self):
@@ -1215,7 +1218,7 @@ def test_linear_solver_set(self):
Test setting of linear_solver property of Radau5DAE.
"""
err_msg = "Radau5DAE does not support setting the 'linear_solver' attribute, since it only supports the DENSE linear solver in Fortran implementation of Radau5."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, err_msg):
self.sim.linear_solver = 'SPARSE'
@testattr(stddist = True)
@@ -1225,7 +1228,7 @@ def test_nbr_fcn_evals_due_to_jac(self):
sim.usejac = False
sim.simulate(1)
- nose.tools.assert_greater(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] > 0
@testattr(stddist = True)
def test_simulate_explicit(self):
@@ -1238,11 +1241,11 @@ def test_simulate_explicit(self):
problem = Explicit_Problem(f,y0)
simulator = Radau5DAE(problem)
- nose.tools.assert_equal(simulator.yd0[0], -simulator.y0[0])
+ assert simulator.yd0[0] == -simulator.y0[0]
t,y = simulator.simulate(1.0)
- nose.tools.assert_almost_equal(float(y[-1]), float(np.exp(-1.0)),4)
+ assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
@testattr(stddist = True)
def test_time_event(self):
@@ -1266,9 +1269,9 @@ def time_events(t,y,yd,sw):
def handle_event(solver, event_info):
#solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Implicit_Problem(f,0.0,0.0)
exp_mod.time_events = time_events
@@ -1279,7 +1282,7 @@ def handle_event(solver, event_info):
exp_sim.verbosity = 0
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_init(self):
@@ -1290,7 +1293,7 @@ def test_init(self):
sim = Radau5DAE(self.mod)
- nose.tools.assert_equal(sim._leny, 2)
+ assert sim._leny == 2
@testattr(stddist = True)
def test_thet(self):
@@ -1299,7 +1302,7 @@ def test_thet(self):
"""
self.sim.thet = -1
self.sim.simulate(.5) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nsteps"], self.sim.statistics["njacs"])
+ assert self.sim.statistics["nsteps"] == self.sim.statistics["njacs"]
@testattr(stddist = True)
def test_simulation(self):
@@ -1308,7 +1311,7 @@ def test_simulation(self):
"""
#Simulate
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.706272, 3)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, rel = 1e-3)
self.sim.reset()
@@ -1316,12 +1319,12 @@ def test_simulation(self):
#Simulate
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.706166, 3)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.706166, rel = 1e-3)
self.sim_t0.simulate(3.)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[0], 1.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[-1], 3.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4)
+ assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4)
+ assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp(self):
@@ -1331,13 +1334,13 @@ def test_simulation_ncp(self):
self.sim.report_continuously = True
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
self.sim.reset()
self.sim.report_continuously = False
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
@testattr(stddist = True)
@@ -1347,7 +1350,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
+ assert max(np.diff(self.sim.t_sol))-np.finfo('double').eps <= 0.01
@testattr(stddist = True)
def test_switches(self):
@@ -1366,9 +1369,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = Radau5DAE(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_nmax_steps(self):
@@ -1381,7 +1384,7 @@ def test_nmax_steps(self):
sim.maxsteps = 9
err_msg = "The solver took max internal steps but could not reach the next output time."
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@testattr(stddist = True)
@@ -1404,7 +1407,7 @@ def test_step_size_too_small(self):
sim.maxh = 1.e-1
err_msg = f"The step size became too small. At time {float_regex}."
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1. + 1.e-16)
@testattr(stddist = True)
@@ -1418,7 +1421,7 @@ def f(t, y, yd):
sim = Radau5DAE(prob)
err_msg = f'Repeated unexpected step rejections.'
- with nose.tools.assert_raises_regex(Radau5Error, err_msg):
+ with pytest.raises(Radau5Error, err_msg):
sim.simulate(1.)
@@ -1426,7 +1429,8 @@ class Test_Implicit_Radau5_Py:
"""
Tests the implicit Radau solver (Python implementation).
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -1446,17 +1450,17 @@ def f(t,y,yd):
yd0 = [-.6,-200000.]
#Define an Assimulo problem
- self.mod = Implicit_Problem(f,y0,yd0)
- self.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
+ cls.mod = Implicit_Problem(f,y0,yd0)
+ cls.mod_t0 = Implicit_Problem(f,y0,yd0,1.0)
#Define an explicit solver
- self.sim = _Radau5DAE(self.mod) #Create a Radau5 solve
- self.sim_t0 = _Radau5DAE(self.mod_t0)
+ cls.sim = _Radau5DAE(cls.mod) #Create a Radau5 solve
+ cls.sim_t0 = _Radau5DAE(cls.mod_t0)
#Sets the parameters
- self.sim.atol = 1e-4 #Default 1e-6
- self.sim.rtol = 1e-4 #Default 1e-6
- self.sim.inith = 1.e-4 #Initial step-size
+ cls.sim.atol = 1e-4 #Default 1e-6
+ cls.sim.rtol = 1e-4 #Default 1e-6
+ cls.sim.inith = 1.e-4 #Initial step-size
@testattr(stddist = True)
def test_time_event(self):
@@ -1480,9 +1484,9 @@ def time_events(t,y,yd,sw):
def handle_event(solver, event_info):
#solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Implicit_Problem(f,0.0,0.0)
exp_mod.time_events = time_events
@@ -1493,7 +1497,7 @@ def handle_event(solver, event_info):
exp_sim.verbosity = 0
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_init(self):
@@ -1504,7 +1508,7 @@ def test_init(self):
sim = _Radau5DAE(self.mod)
- nose.tools.assert_equal(sim._leny, 2)
+ assert sim._leny == 2
@testattr(stddist = True)
def test_thet(self):
@@ -1514,7 +1518,7 @@ def test_thet(self):
self.sim.thet = -1
self.sim.simulate(.5) #Simulate 2 seconds
- nose.tools.assert_equal(self.sim.statistics["nsteps"], self.sim.statistics["njacs"])
+ assert self.sim.statistics["nsteps"] == self.sim.statistics["njacs"]
@testattr(stddist = True)
def test_simulation(self):
@@ -1523,7 +1527,7 @@ def test_simulation(self):
"""
#Simulate
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.706272, 3)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.706272, rel = 1e-3)
self.sim.reset()
@@ -1531,12 +1535,12 @@ def test_simulation(self):
#Simulate
self.sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_almost_equal(self.sim.y_sol[-1][0], 1.706947, 2)
+ assert self.sim.y_sol[-1][0] == pytest.approx(1.706947, rel = 1e-2)
self.sim_t0.simulate(3.)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[0], 1.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.t_sol[-1], 3.0000000, 4)
- nose.tools.assert_almost_equal(self.sim_t0.y_sol[-1][0], 1.7061680350, 4)
+ assert self.sim_t0.t_sol[0] == pytest.approx(1.0000000, rel = 1e-4)
+ assert self.sim_t0.t_sol[-1] == pytest.approx(3.0000000, rel = 1e-4)
+ assert self.sim_t0.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_simulation_ncp(self):
@@ -1546,13 +1550,13 @@ def test_simulation_ncp(self):
self.sim.report_continuously = True
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
self.sim.reset()
self.sim.report_continuously = False
self.sim.simulate(1.0, 200) #Simulate 1 second
- nose.tools.assert_equal(len(self.sim.t_sol), 201)
+ assert len(self.sim.t_sol) == 201
@testattr(stddist = True)
def test_maxh(self):
@@ -1561,7 +1565,7 @@ def test_maxh(self):
"""
self.sim.maxh = 0.01
self.sim.simulate(0.5)
- nose.tools.assert_less_equal(max(np.diff(self.sim.t_sol))-np.finfo('double').eps, 0.01)
+ assert max(np.diff(self.sim.t_sol))-np.finfo('double').eps <= 0.01
@testattr(stddist = True)
def test_keyboard_interrupt_fcn(self):
@@ -1574,14 +1578,15 @@ def test_keyboard_interrupt_fcn(self):
sim = Radau5DAE(prob)
err_msg = "Unrecoverable exception encountered during callback to problem (right-hand side/jacobian)."
- with nose.tools.assert_raises_regex(Radau5Error, re.escape(err_msg)):
+ with pytest.raises(Radau5Error, re.escape(err_msg)):
sim.simulate(1.)
class Test_Radau_Common:
"""
Tests the common attributes of the Radau solvers.
"""
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -1591,7 +1596,7 @@ def setUp(self):
#Define an explicit Assimulo problem
y0 = [2.0,-0.6] #Initial conditions
exp_mod = Explicit_Problem(f,y0)
- self.sim = Radau5ODE(exp_mod)
+ cls.sim = Radau5ODE(exp_mod)
@testattr(stddist = True)
def test_fac1(self):
@@ -1599,14 +1604,14 @@ def test_fac1(self):
This tests the functionality of the property fac1.
"""
self.sim.fac1 = 0.01
- nose.tools.assert_equal(self.sim.fac1, 0.01)
+ assert self.sim.fac1 == 0.01
self.sim.fac1 = 0.001
- nose.tools.assert_equal(self.sim.fac1, 0.001)
+ assert self.sim.fac1 == 0.001
err_msg = "The attribute 'fac1' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fac1 = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fac1 = [-1.0]
@testattr(stddist = True)
@@ -1615,14 +1620,14 @@ def test_fac2(self):
This tests the functionality of the property fac2.
"""
self.sim.fac2 = 0.01
- nose.tools.assert_equal(self.sim.fac2, 0.01)
+ assert self.sim.fac2 == 0.01
self.sim.fac2 = 0.001
- nose.tools.assert_equal(self.sim.fac2, 0.001)
+ assert self.sim.fac2 == 0.001
err_msg = "The attribute 'fac2' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fac2 = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fac2 = [-1.0]
@testattr(stddist = True)
@@ -1631,14 +1636,14 @@ def test_fnewt(self):
This tests the functionality of the property fnewt.
"""
self.sim.fnewt = 0.01
- nose.tools.assert_equal(self.sim.fnewt, 0.01)
+ assert self.sim.fnewt == 0.01
self.sim.fnewt = 0.001
- nose.tools.assert_equal(self.sim.fnewt, 0.001)
+ assert self.sim.fnewt == 0.001
err_msg = "The attribute 'fnewt' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fnewt = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.fnewt = [-1.0]
@testattr(stddist = True)
@@ -1647,9 +1652,9 @@ def test_h(self):
This tests the functionality of the property h.
"""
self.sim.h = 0.01
- nose.tools.assert_equal(self.sim.h, 0.01)
+ assert self.sim.h == 0.01
self.sim.h = 0.001
- nose.tools.assert_equal(self.sim.h, 0.001)
+ assert self.sim.h == 0.001
@testattr(stddist = True)
def test_initial_step(self):
@@ -1657,14 +1662,14 @@ def test_initial_step(self):
This tests the functionality of the property initial step.
"""
self.sim.inith = 0.01
- nose.tools.assert_equal(self.sim.inith, 0.01)
+ assert self.sim.inith == 0.01
self.sim.inith = 0.001
- nose.tools.assert_equal(self.sim.inith, 0.001)
+ assert self.sim.inith == 0.001
err_msg = 'The initial step must be an integer or float.'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.inith = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.inith = [-1.0]
@testattr(stddist = True)
@@ -1673,16 +1678,16 @@ def test_newt(self):
This tests the functionality of the property newt.
"""
self.sim.newt = 1
- nose.tools.assert_equal(self.sim.newt, 1)
+ assert self.sim.newt == 1
self.sim.newt = 10
- nose.tools.assert_equal(self.sim.newt, 10)
+ assert self.sim.newt == 10
self.sim.newt = 9.8
- nose.tools.assert_equal(self.sim.newt, 9)
+ assert self.sim.newt == 9
err_msg = "The attribute 'newt' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.newt = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.newt = [-1.0]
@testattr(stddist = True)
@@ -1691,14 +1696,14 @@ def test_quot1(self):
This tests the functionality of the property quot1.
"""
self.sim.quot1 = 0.01
- nose.tools.assert_equal(self.sim.quot1, 0.01)
+ assert self.sim.quot1 == 0.01
self.sim.quot1 = 0.001
- nose.tools.assert_equal(self.sim.quot1, 0.001)
+ assert self.sim.quot1 == 0.001
err_msg = "The attribute 'quot1' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.quot1 = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.quot1 = [-1.0]
@testattr(stddist = True)
@@ -1707,14 +1712,14 @@ def test_quot2(self):
This tests the functionality of the property quot2.
"""
self.sim.quot2 = 0.01
- nose.tools.assert_equal(self.sim.quot2, 0.01)
+ assert self.sim.quot2 == 0.01
self.sim.quot2 = 0.001
- nose.tools.assert_equal(self.sim.quot2, 0.001)
+ assert self.sim.quot2 == 0.001
err_msg = "The attribute 'quot2' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.quot2 = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.quot2 = [-1.0]
@testattr(stddist = True)
@@ -1723,14 +1728,14 @@ def test_safe(self):
This tests the functionality of the property safe.
"""
self.sim.safe = 0.01
- nose.tools.assert_equal(self.sim.safe, 0.01)
+ assert self.sim.safe == 0.01
self.sim.safe = 0.001
- nose.tools.assert_equal(self.sim.safe, 0.001)
+ assert self.sim.safe == 0.001
err_msg = "The attribute 'safe' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.safe = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.safe = [-1.0]
@testattr(stddist = True)
@@ -1739,14 +1744,14 @@ def test_thet(self):
This tests the functionality of the property thet.
"""
self.sim.thet = 0.01
- nose.tools.assert_equal(self.sim.thet, 0.01)
+ assert self.sim.thet == 0.01
self.sim.thet = 0.001
- nose.tools.assert_equal(self.sim.thet, 0.001)
+ assert self.sim.thet == 0.001
err_msg = "The attribute 'thet' must be an integer or float."
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.thet = 'Test'
- with nose.tools.assert_raises_regex(Radau_Exception, err_msg):
+ with pytest.raises(Radau_Exception, match = err_msg):
self.sim.thet = [-1.0]
@testattr(stddist = True)
@@ -1755,10 +1760,10 @@ def test_usejac(self):
This tests the functionality of the property usejac.
"""
self.sim.usejac = True
- nose.tools.assert_true(self.sim.usejac)
+ assert self.sim.usejac
self.sim.usejac = False
- nose.tools.assert_false(self.sim.usejac)
+ assert not self.sim.usejac
self.sim.usejac = 1
- nose.tools.assert_true(self.sim.usejac)
+ assert self.sim.usejac
self.sim.usejac = []
- nose.tools.assert_false(self.sim.usejac)
+ assert not self.sim.usejac
diff --git a/tests/solvers/test_rosenbrock.py b/tests/solvers/test_rosenbrock.py
index f5a157ab..79f9b270 100644
--- a/tests/solvers/test_rosenbrock.py
+++ b/tests/solvers/test_rosenbrock.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.rosenbrock import RodasODE
from assimulo.problem import Explicit_Problem
@@ -26,7 +26,8 @@
float_regex = "[\s]*[\d]*.[\d]*((e|E)(\+|\-)\d\d|)"
class Test_RodasODE:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
#Define the rhs
def f(t,y):
eps = 1.e-6
@@ -62,8 +63,8 @@ def jac_sparse(t,y):
exp_mod_sp = Explicit_Problem(f,y0, name = 'Van der Pol (explicit)')
exp_mod.jac = jac
exp_mod_sp.jac = jac_sparse
- self.mod = exp_mod
- self.mod_sp = exp_mod_sp
+ cls.mod = exp_mod
+ cls.mod_sp = exp_mod_sp
@testattr(stddist = True)
def test_nbr_fcn_evals_due_to_jac(self):
@@ -72,12 +73,12 @@ def test_nbr_fcn_evals_due_to_jac(self):
sim.usejac = False
sim.simulate(1)
- nose.tools.assert_greater(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] > 0
sim = RodasODE(self.mod)
sim.simulate(1)
- nose.tools.assert_equal(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] == 0
@testattr(stddist = True)
def test_usejac_csc_matrix(self):
@@ -87,9 +88,9 @@ def test_usejac_csc_matrix(self):
sim.simulate(2.) #Simulate 2 seconds
- nose.tools.assert_equal(sim.statistics["nfcnjacs"], 0)
+ assert sim.statistics["nfcnjacs"] == 0
- nose.tools.assert_almost_equal(sim.y_sol[-1][0], 1.7061680350, 4)
+ assert sim.y_sol[-1][0] == pytest.approx(1.7061680350, rel = 1e-4)
@testattr(stddist = True)
def test_time_limit(self):
@@ -107,5 +108,5 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
diff --git a/tests/solvers/test_rungekutta.py b/tests/solvers/test_rungekutta.py
index 0634242e..a36aaec3 100644
--- a/tests/solvers/test_rungekutta.py
+++ b/tests/solvers/test_rungekutta.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.runge_kutta import Dopri5, RungeKutta34, RungeKutta4
from assimulo.problem import Explicit_Problem
@@ -26,15 +26,16 @@
class Test_Dopri5:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y:1.0
y0 = 1
- self.problem = Explicit_Problem(f,y0)
- self.simulator = Dopri5(self.problem)
+ cls.problem = Explicit_Problem(f,y0)
+ cls.simulator = Dopri5(cls.problem)
@testattr(stddist = True)
def test_integrator(self):
@@ -43,8 +44,8 @@ def test_integrator(self):
"""
values = self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_time_event(self):
@@ -68,9 +69,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -80,7 +81,7 @@ def handle_event(solver, event_info):
exp_sim = Dopri5(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
def test_switches(self):
"""
@@ -98,9 +99,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = Dopri5(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_time_limit(self):
@@ -118,20 +119,21 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
class Test_RungeKutta34:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y:1.0
y0 = 1
- self.problem = Explicit_Problem(f,y0)
- self.simulator = RungeKutta34(self.problem)
+ cls.problem = Explicit_Problem(f,y0)
+ cls.simulator = RungeKutta34(cls.problem)
@testattr(stddist = True)
def test_integrator(self):
@@ -140,8 +142,8 @@ def test_integrator(self):
"""
values = self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(self.simulator.y_sol[-1], 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert self.simulator.y_sol[-1] == pytest.approx(2.0)
@testattr(stddist = True)
def test_step(self):
@@ -153,8 +155,8 @@ def test_step(self):
self.simulator.h = 0.1
self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(self.simulator.y_sol[-1], 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert self.simulator.y_sol[-1] == pytest.approx(2.0)
@testattr(stddist = True)
def test_time_event(self):
@@ -178,9 +180,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -190,26 +192,30 @@ def handle_event(solver, event_info):
exp_sim = RungeKutta34(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_tolerance(self):
"""
This tests the functionality of the tolerances.
"""
- nose.tools.assert_raises(Explicit_ODE_Exception, self.simulator._set_rtol, 'hej')
- nose.tools.assert_raises(Explicit_ODE_Exception, self.simulator._set_atol, 'hej')
- nose.tools.assert_raises(Explicit_ODE_Exception, self.simulator._set_rtol, -1)
+ with pytest.raises(Explicit_ODE_Exception):
+ self.simulator._set_rtol('hej')
+ with pytest.raises(Explicit_ODE_Exception):
+ self.simulator._set_atol('hej')
+ with pytest.raises(Explicit_ODE_Exception):
+ self.simulator._set_rtol(-1)
self.simulator.rtol = 1.0
- nose.tools.assert_equal(self.simulator._get_rtol(), 1.0)
+ assert self.simulator._get_rtol() == 1.0
self.simulator.rtol = 1
- nose.tools.assert_equal(self.simulator._get_rtol(), 1)
+ assert self.simulator._get_rtol() == 1
self.simulator.atol = 1.0
- nose.tools.assert_equal(self.simulator.atol, 1.0)
+ assert self.simulator.atol == 1.0
- nose.tools.assert_raises(Explicit_ODE_Exception, self.simulator._set_atol, [1.0,1.0])
+ with pytest.raises(Explicit_ODE_Exception):
+ self.simulator._set_atol([1.0,1.0])
@testattr(stddist = True)
@@ -229,9 +235,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = RungeKutta34(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_time_limit(self):
@@ -249,20 +255,21 @@ def f(t, y):
sim.report_continuously = True
err_msg = f'The time limit was exceeded at integration time {float_regex}.'
- with nose.tools.assert_raises_regex(TimeLimitExceeded, err_msg):
+ with pytest.raises(TimeLimitExceeded, match = err_msg):
sim.simulate(1.)
class Test_RungeKutta4:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y:1.0
y0 = 1
- self.problem = Explicit_Problem(f,y0)
- self.simulator = RungeKutta4(self.problem)
+ cls.problem = Explicit_Problem(f,y0)
+ cls.simulator = RungeKutta4(cls.problem)
@testattr(stddist = True)
def test_time_event(self):
@@ -286,9 +293,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -298,14 +305,14 @@ def handle_event(solver, event_info):
exp_sim = RungeKutta4(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_integrate(self):
values = self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
@testattr(stddist = True)
def test_step(self):
@@ -314,5 +321,5 @@ def test_step(self):
self.simulator.h = 0.1
self.simulator.simulate(1)
- nose.tools.assert_almost_equal(self.simulator.t_sol[-1], 1.0)
- nose.tools.assert_almost_equal(float(self.simulator.y_sol[-1]), 2.0)
+ assert self.simulator.t_sol[-1] == pytest.approx(1.0)
+ assert float(self.simulator.y_sol[-1]) == pytest.approx(2.0)
diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py
index 3f477dfa..853d2e58 100644
--- a/tests/solvers/test_sundials.py
+++ b/tests/solvers/test_sundials.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.solvers.sundials import CVode, IDA, CVodeError
from assimulo.problem import Explicit_Problem
@@ -116,16 +116,17 @@ def init_mode(self, solver):
class Test_CVode:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
f = lambda t,y:np.array(y)
y0 = [1.0]
- self.problem = Explicit_Problem(f,y0)
- self.simulator = CVode(self.problem)
- self.simulator.verbosity = 0
+ cls.problem = Explicit_Problem(f,y0)
+ cls.simulator = CVode(cls.problem)
+ cls.simulator.verbosity = 0
@testattr(stddist = True)
def test_backward_integration(self):
@@ -138,14 +139,14 @@ def f(t, y):
sim.backward = True
t, y = sim.simulate(0, ncp_list=np.arange(1, 10))
- nose.tools.assert_true(np.all(t == np.arange(0,11)[::-1]))
+ assert np.all(t == np.arange(0,11)[::-1])
mod = Explicit_Problem(f, y0=[1, 0], t0=10)
sim = CVode(mod)
sim.backward = True
t, y = sim.simulate(0, ncp_list=np.arange(1, 10)[::-1])
- nose.tools.assert_true(np.all(t == np.arange(0,11)[::-1]))
+ assert np.all(t == np.arange(0,11)[::-1])
@testattr(stddist = True)
def test_event_localizer(self):
@@ -162,9 +163,9 @@ def test_event_localizer(self):
t, y = exp_sim.simulate(10.0, 1000) #Simulate 10 seconds with 1000 communications points
#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)
@testattr(stddist = True)
def test_event_localizer_external(self):
@@ -181,25 +182,26 @@ def test_event_localizer_external(self):
t, y = exp_sim.simulate(10.0, 1000) #Simulate 10 seconds with 1000 communications points
#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)
@testattr(stddist = True)
def test_get_error_weights(self):
- nose.tools.assert_raises(CVodeError, self.simulator.get_error_weights)
+ with pytest.raises(CVodeError):
+ self.simulator.get_error_weights()
self.simulator.simulate(1.0)
weights = self.simulator.get_error_weights()
- nose.tools.assert_less(weights[0], 1e6)
+ assert weights[0] < 1e6
@testattr(stddist = True)
def test_get_used_initial_step(self):
self.simulator.simulate(1.0)
step = self.simulator.get_used_initial_step()
- nose.tools.assert_almost_equal(step, 0.001, 3)
+ assert step == pytest.approx(0.001, rel = 1e-3)
self.simulator.reset()
@@ -207,62 +209,68 @@ def test_get_used_initial_step(self):
self.simulator.simulate(1.0)
step = self.simulator.get_used_initial_step()
- nose.tools.assert_less(np.abs(step-1e-8), 1e-2)
+ assert np.abs(step-1e-8) < 1e-2
@testattr(stddist = True)
def test_get_local_errors(self):
- nose.tools.assert_raises(CVodeError, self.simulator.get_local_errors)
+ with pytest.raises(CVodeError):
+ self.simulator.get_local_errors()
self.simulator.simulate(1.0)
err = self.simulator.get_local_errors()
- nose.tools.assert_less(err[0], 1e-5)
+ assert err[0] < 1e-5
@testattr(stddist = True)
def test_get_last_order(self):
- nose.tools.assert_raises(CVodeError, self.simulator.get_last_order)
+ with pytest.raises(CVodeError):
+ self.simulator.get_last_order()
self.simulator.simulate(1.0)
qlast = self.simulator.get_last_order()
- nose.tools.assert_equal(qlast, 4)
+ assert qlast == 4
@testattr(stddist = True)
def test_max_convergence_failures(self):
- nose.tools.assert_equal(self.simulator.maxncf, self.simulator.options["maxncf"])
+ assert self.simulator.maxncf == self.simulator.options["maxncf"]
self.simulator.maxncf = 15
- nose.tools.assert_equal(self.simulator.maxncf, 15)
+ assert self.simulator.maxncf == 15
- nose.tools.assert_raises(AssimuloException, self.simulator._set_max_conv_fails, -1)
+ with pytest.raises(AssimuloException):
+ self.simulator._set_max_conv_fails(-1)
@testattr(stddist = True)
def test_max_error_tests_failures(self):
- nose.tools.assert_equal(self.simulator.maxnef, self.simulator.options["maxnef"])
+ assert self.simulator.maxnef == self.simulator.options["maxnef"]
self.simulator.maxnef = 15
- nose.tools.assert_equal(self.simulator.maxnef, 15)
- nose.tools.assert_equal(self.simulator.options["maxnef"], 15)
+ assert self.simulator.maxnef == 15
+ assert self.simulator.options["maxnef"] == 15
- nose.tools.assert_raises(AssimuloException, self.simulator._set_max_err_fails, -1)
+ with pytest.raises(AssimuloException):
+ self.simulator._set_max_err_fails(-1)
@testattr(stddist = True)
def test_max_nonlinear_iterations(self):
- nose.tools.assert_equal(self.simulator.maxcor, self.simulator.options["maxcor"])
+ assert self.simulator.maxcor == self.simulator.options["maxcor"]
self.simulator.maxcor = 15
- nose.tools.assert_equal(self.simulator.maxcor, 15)
- nose.tools.assert_equal(self.simulator.options["maxcor"], 15)
+ assert self.simulator.maxcor == 15
+ assert self.simulator.options["maxcor"] == 15
- #nose.tools.assert_raises(AssimuloException, self.simulator._set_max_err_fails, -1)
+ # with pytest.raises(AssimuloException):
+ # self.simulator._set_max_err_fails(-1)
@testattr(stddist = True)
def test_get_current_order(self):
- nose.tools.assert_raises(CVodeError, self.simulator.get_current_order)
+ with pytest.raises(CVodeError):
+ self.simulator.get_current_order()
self.simulator.simulate(1.0)
qcur = self.simulator.get_current_order()
- nose.tools.assert_equal(qcur, 4)
+ assert qcur == 4
@@ -271,15 +279,15 @@ def test_init(self):
"""
This tests the functionality of the method __init__.
"""
- # nose.tools.assert_equal(self.simulator.f, 'Test function')
- nose.tools.assert_equal(self.simulator.y, 1.0)
- nose.tools.assert_equal(self.simulator.discr, 'BDF')
- nose.tools.assert_equal(self.simulator.iter, 'Newton')
- nose.tools.assert_equal(self.simulator.maxord, 5)
+ # assert_equal(self.simulator.f, 'Test function')
+ assert self.simulator.y == 1.0
+ assert self.simulator.discr == 'BDF'
+ assert self.simulator.iter == 'Newton'
+ assert self.simulator.maxord == 5
self.simulator.discr = 'Adams'
- nose.tools.assert_equal(self.simulator.discr, 'Adams')
- nose.tools.assert_equal(self.simulator.maxord, 12)
+ assert self.simulator.discr == 'Adams'
+ assert self.simulator.maxord == 12
@testattr(stddist = True)
def test_time_event(self):
@@ -303,9 +311,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -315,7 +323,7 @@ def handle_event(solver, event_info):
exp_sim = CVode(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_clear_event_log(self):
@@ -339,9 +347,9 @@ def time_events(t,y,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Explicit_Problem(f,0.0)
exp_mod.time_events = time_events
@@ -352,16 +360,16 @@ def handle_event(solver, event_info):
exp_sim.verbosity = 10
exp_sim(5.,100)
- nose.tools.assert_equal(len(exp_sim.event_data), 4)
+ assert len(exp_sim.event_data) == 4
tnext = 0.0
nevent = 0
exp_sim.reset()
- nose.tools.assert_equal(len(exp_sim.event_data), 0)
+ assert len(exp_sim.event_data) == 0
exp_sim(5.,100)
- nose.tools.assert_equal(len(exp_sim.event_data), 4)
+ assert len(exp_sim.event_data) == 4
@testattr(stddist = True)
def test_time_limit(self):
@@ -374,7 +382,8 @@ def test_time_limit(self):
exp_sim.time_limit = 1 #One second
exp_sim.report_continuously = True
- nose.tools.assert_raises(TimeLimitExceeded, exp_sim.simulate, 1)
+ with pytest.raises(TimeLimitExceeded):
+ exp_sim.simulate(1)
@testattr(stddist = True)
def test_statistics_stored(self):
@@ -409,17 +418,23 @@ def test_discr_method(self):
This tests the functionality of the property discr.
"""
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, 'Test')
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, 1)
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, [1.0, 1])
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, {'Test':'case'})
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, 5.1)
- nose.tools.assert_raises(Exception, self.simulator._set_discr_method, ['Test'])
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method('Test')
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method(1)
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method([1.0, 1])
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method({'Test':'case'})
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method(5.1)
+ with pytest.raises(Exception):
+ self.simulator._set_discr_method(['Test'])
self.simulator.discr = 'BDF'
- nose.tools.assert_equal(self.simulator.discr, 'BDF')
+ assert self.simulator.discr == 'BDF'
self.simulator.discr = 'Adams'
- nose.tools.assert_equal(self.simulator.discr, 'Adams')
+ assert self.simulator.discr == 'Adams'
@testattr(stddist = True)
def test_change_discr(self):
@@ -434,20 +449,20 @@ def test_change_discr(self):
exp_sim.iter = "FixedPoint"
exp_sim.simulate(1)
- nose.tools.assert_equal(exp_sim.statistics["njacs"], 0)
+ assert exp_sim.statistics["njacs"] == 0
exp_sim.iter = "Newton"
exp_sim.simulate(2)
- nose.tools.assert_greater(exp_sim.statistics["njacs"], 0)
+ assert exp_sim.statistics["njacs"] > 0
@testattr(stddist = True)
def test_change_norm(self):
- nose.tools.assert_equal(self.simulator.options["norm"], "WRMS")
+ assert self.simulator.options["norm"] == "WRMS"
self.simulator.norm = 'WRMS'
- nose.tools.assert_equal(self.simulator.norm, 'WRMS')
+ assert self.simulator.norm == 'WRMS'
self.simulator.norm = 'EUCLIDEAN'
- nose.tools.assert_equal(self.simulator.options["norm"], "EUCLIDEAN")
- nose.tools.assert_equal(self.simulator.norm, 'EUCLIDEAN')
+ assert self.simulator.options["norm"] == "EUCLIDEAN"
+ assert self.simulator.norm == 'EUCLIDEAN'
f = lambda t,y: np.array([1.0])
y0 = 4.0 #Initial conditions
@@ -480,15 +495,15 @@ def test_usejac(self):
exp_sim.iter='Newton'
exp_sim.simulate(5.,100)
- nose.tools.assert_equal(exp_sim.statistics["nfcnjacs"], 0)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.75000143, 4)
+ assert exp_sim.statistics["nfcnjacs"] == 0
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4)
exp_sim.reset()
exp_sim.usejac=False
exp_sim.simulate(5.,100)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.75000143, 4)
- nose.tools.assert_greater(exp_sim.statistics["nfcnjacs"], 0)
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4)
+ assert exp_sim.statistics["nfcnjacs"] > 0
@testattr(stddist = True)
def test_usejac_csc_matrix(self):
@@ -506,15 +521,15 @@ def test_usejac_csc_matrix(self):
exp_sim.iter='Newton'
exp_sim.simulate(5.,100)
- nose.tools.assert_equal(exp_sim.statistics["nfcnjacs"], 0)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.75000143, 4)
+ assert exp_sim.statistics["nfcnjacs"] == 0
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4)
exp_sim.reset()
exp_sim.usejac=False
exp_sim.simulate(5.,100)
- nose.tools.assert_almost_equal(exp_sim.y_sol[-1][0], -121.75000143, 4)
- nose.tools.assert_greater(exp_sim.statistics["nfcnjacs"], 0)
+ assert exp_sim.y_sol[-1][0] == pytest.approx(-121.75000143, rel = 1e-4)
+ assert exp_sim.statistics["nfcnjacs"] > 0
@testattr(stddist = True)
def test_switches(self):
@@ -533,9 +548,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = CVode(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_iter_method(self):
@@ -543,17 +558,23 @@ def test_iter_method(self):
This tests the functionality of the property iter.
"""
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, 'Test')
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, 1)
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, 0)
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, ['Test'])
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, [1.0, 1])
- nose.tools.assert_raises(Exception, self.simulator._set_iter_method, 11.1)
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method('Test')
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method(1)
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method(0)
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method(['Test'])
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method([1.0, 1])
+ with pytest.raises(Exception):
+ self.simulator._set_iter_method(11.1)
self.simulator.iter = 'Newton'
- nose.tools.assert_equal(self.simulator.iter, 'Newton')
+ assert self.simulator.iter == 'Newton'
self.simulator.iter = 'FixedPoint'
- nose.tools.assert_equal(self.simulator.iter, 'FixedPoint')
+ assert self.simulator.iter == 'FixedPoint'
@testattr(stddist = True)
def test_initial_step(self):
@@ -561,14 +582,16 @@ def test_initial_step(self):
This tests the functionality of the property initstep.
"""
- nose.tools.assert_raises(Exception, self.simulator._set_initial_step, 'Test')
- nose.tools.assert_raises(Exception, self.simulator._set_initial_step, ['Test'])
+ with pytest.raises(Exception):
+ self.simulator._set_initial_step('Test')
+ with pytest.raises(Exception):
+ self.simulator._set_initial_step(['Test'])
- nose.tools.assert_equal(self.simulator.inith, 0.0)
+ assert self.simulator.inith == 0.0
self.simulator.inith = 10.0
- nose.tools.assert_equal(self.simulator.inith, 10.0)
+ assert self.simulator.inith == 10.0
self.simulator.inith = 1
- nose.tools.assert_equal(self.simulator.inith, 1.0)
+ assert self.simulator.inith == 1.0
@testattr(stddist = True)
def test_interpolate(self):
@@ -585,7 +608,7 @@ def test_interpolate(self):
t100 = sim.t_sol
sim.reset()
sim.simulate(10.)
- nose.tools.assert_almost_equal(float(y100[-2]), float(sim.interpolate(9.9,0)),5)
+ assert_almost_equal(float(y100[-2]), float(sim.interpolate(9.9,0)),5)
@testattr(stddist = True)
def test_ncp_list(self):
@@ -597,7 +620,7 @@ def test_ncp_list(self):
t, y = sim.simulate(7, ncp_list=np.arange(0, 7, 0.1)) #Simulate 5 seconds
- nose.tools.assert_almost_equal(float(y[-1]), 0.00364832, 4)
+ assert float(y[-1]) == pytest.approx(0.00364832, rel = 1e-4)
@testattr(stddist = True)
def test_handle_result(self):
@@ -606,7 +629,7 @@ def test_handle_result(self):
"""
f = lambda t,x: x**0.25
def handle_result(solver,t,y):
- nose.tools.assert_equal(solver.t, t)
+ assert solver.t == t
prob = Explicit_Problem(f, [1.0])
prob.handle_result = handle_result
@@ -622,27 +645,31 @@ def test_max_order(self):
"""
self.simulator.discr='Adams'
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, "Test")
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, [1,1])
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord("Test")
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord([1,1])
self.simulator.maxord = -1
- nose.tools.assert_equal(self.simulator.maxord, 1)
+ assert self.simulator.maxord == 1
self.simulator.maxord = 2
- nose.tools.assert_equal(self.simulator.maxord, 2)
+ assert self.simulator.maxord == 2
self.simulator.maxord = 13
- nose.tools.assert_equal(self.simulator.maxord, 12)
+ assert self.simulator.maxord == 12
self.simulator.discr='BDF'
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, "Test")
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, [1,1])
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord("Test")
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord([1,1])
self.simulator.maxord = -1
- nose.tools.assert_equal(self.simulator.maxord, 1)
+ assert self.simulator.maxord == 1
self.simulator.maxord = 2
- nose.tools.assert_equal(self.simulator.maxord, 2)
+ assert self.simulator.maxord == 2
self.simulator.maxord = 6
- nose.tools.assert_equal(self.simulator.maxord, 5)
+ assert self.simulator.maxord == 5
@testattr(stddist = True)
def test_spgmr(self):
@@ -664,8 +691,8 @@ def run_sim(exp_mod):
t, y = exp_sim.simulate(5, 1000) #Simulate 5 seconds with 1000 communication points
#Basic tests
- nose.tools.assert_almost_equal(y[-1][0],-121.75000000,4)
- nose.tools.assert_almost_equal(y[-1][1],-49.100000000)
+ assert_almost_equal(y[-1][0],-121.75000000,4)
+ assert_almost_equal(y[-1][1],-49.100000000)
exp_mod = Explicit_Problem(f,y0)
exp_mod.jacv = jacv #Sets the jacobian
@@ -683,11 +710,13 @@ def run_sim(exp_mod):
exp_mod = Explicit_Problem(f,y0)
exp_mod.jacv = jacvsw #Sets the jacobian
- nose.tools.assert_raises(CVodeError,run_sim,exp_mod)
+ with pytest.raises(CVodeError):
+ run_sim(exp_mod)
exp_mod = Explicit_Problem(fswp,y0,sw0=[True],p0=1.0)
exp_mod.jacv = jacvsw #Sets the jacobian
- nose.tools.assert_raises(CVodeError,run_sim,exp_mod)
+ with pytest.raises(CVodeError):
+ run_sim(exp_mod)
#Restore standard error
sys.stderr = stderr
@@ -711,64 +740,68 @@ def test_max_order_discr(self):
"""
self.simulator.discr = "Adams"
self.simulator.maxord = 7
- nose.tools.assert_equal(self.simulator.maxord, 7)
+ assert self.simulator.maxord == 7
self.simulator.discr = 'Adams'
- nose.tools.assert_equal(self.simulator.maxord, 12)
+ assert self.simulator.maxord == 12
self.simulator.discr = 'BDF'
- nose.tools.assert_equal(self.simulator.maxord, 5)
+ assert self.simulator.maxord == 5
self.simulator.discr = 'Adams'
- nose.tools.assert_equal(self.simulator.maxord, 12)
+ assert self.simulator.maxord == 12
self.simulator.maxord = 4
self.simulator.discr = 'BDF'
- nose.tools.assert_equal(self.simulator.maxord, 5)
+ assert self.simulator.maxord == 5
self.simulator.discr = 'Adams'
- nose.tools.assert_equal(self.simulator.maxord, 12)
+ assert self.simulator.maxord == 12
@testattr(stddist = True)
def test_pretype(self):
"""
This tests the precondition option.
"""
- nose.tools.assert_equal(self.simulator.precond, 'PREC_NONE')
+ assert self.simulator.precond == 'PREC_NONE'
self.simulator.precond = 'prec_none'
- nose.tools.assert_equal(self.simulator.precond, 'PREC_NONE')
+ assert self.simulator.precond == 'PREC_NONE'
- nose.tools.assert_raises(Exception, self.simulator._set_pre_cond, -1.0)
- nose.tools.assert_raises(Exception, self.simulator._set_pre_cond, 'PREC_BOTH1')
+ with pytest.raises(Exception):
+ self.simulator._set_pre_cond(-1.0)
+ with pytest.raises(Exception):
+ self.simulator._set_pre_cond('PREC_BOTH1')
@testattr(stddist = True)
def test_maxkrylov(self):
"""
This test the maximum number of krylov subspaces.
"""
- nose.tools.assert_equal(self.simulator.maxkrylov, 5)
+ assert self.simulator.maxkrylov == 5
self.simulator.maxkrylov = 3
- nose.tools.assert_equal(self.simulator.maxkrylov, 3)
+ assert self.simulator.maxkrylov == 3
self.simulator.maxkrylov = 4.5
- nose.tools.assert_equal(self.simulator.maxkrylov, 4)
+ assert self.simulator.maxkrylov == 4
- nose.tools.assert_raises(Exception, self.simulator._set_max_krylov, 'Test')
+ with pytest.raises(Exception):
+ self.simulator._set_max_krylov('Test')
@testattr(stddist = True)
def test_stablimit(self):
- nose.tools.assert_false(self.simulator.stablimit)
+ assert not self.simulator.stablimit
self.simulator.stablimit = True
- nose.tools.assert_true(self.simulator.stablimit)
- nose.tools.assert_true(self.simulator.options["stablimit"])
+ assert self.simulator.stablimit
+ assert self.simulator.options["stablimit"]
@testattr(stddist = True)
def test_linearsolver(self):
"""
This test the choice of the linear solver.
"""
- nose.tools.assert_equal(self.simulator.linear_solver, 'DENSE')
+ assert self.simulator.linear_solver == 'DENSE'
self.simulator.linear_solver = 'dense'
- nose.tools.assert_equal(self.simulator.linear_solver, 'DENSE')
+ assert self.simulator.linear_solver == 'DENSE'
self.simulator.linear_solver = 'spgmr'
- nose.tools.assert_equal(self.simulator.linear_solver, 'SPGMR')
+ assert self.simulator.linear_solver == 'SPGMR'
- nose.tools.assert_raises(Exception, self.simulator._set_linear_solver, 'Test')
+ with pytest.raises(Exception):
+ self.simulator._set_linear_solver('Test')
@testattr(stddist = True)
def test_terminate_simulation(self):
@@ -788,7 +821,7 @@ def handle_event(self, solver, event_info):
simulator = CVode(exp_mod)
simulator(3.)
- nose.tools.assert_almost_equal(simulator.t, 2.000000, 4)
+ assert simulator.t == pytest.approx(2.000000, rel = 1e-4)
@testattr(stddist = True)
def test_completed_step(self):
@@ -807,14 +840,14 @@ def completed_step(solver):
sim = CVode(mod)
sim.simulate(2., 100)
- nose.tools.assert_equal(len(sim.t_sol), 101)
- nose.tools.assert_equal(nsteps, sim.statistics["nsteps"])
+ assert len(sim.t_sol) == 101
+ assert nsteps == sim.statistics["nsteps"]
sim = CVode(mod)
nsteps = 0
sim.simulate(2.)
- nose.tools.assert_equal(len(sim.t_sol), sim.statistics["nsteps"]+1)
- nose.tools.assert_equal(nsteps, sim.statistics["nsteps"])
+ assert len(sim.t_sol) == sim.statistics["nsteps"]+1
+ assert nsteps == sim.statistics["nsteps"]
@testattr(stddist = True)
def test_rtol_vector(self):
@@ -824,17 +857,19 @@ def test_rtol_vector(self):
sim = CVode(prob)
sim.rtol = [1e-2, 1e-2] # reduces to scalar
- nose.tools.assert_equal(sim.rtol, 1e-2)
+ assert sim.rtol == 1e-2
if sim.supports['rtol_as_vector']:
sim.rtol = [1e-2, 1e-3]
- nose.tools.assert_equal(sim.rtol[0], 1e-2)
- nose.tools.assert_equal(sim.rtol[1], 1e-3)
+ assert sim.rtol[0] == 1e-2
+ assert sim.rtol[1] == 1e-3
sim.simulate(1.)
else:
- nose.tools.assert_raises(AssimuloException, sim._set_rtol, [1e-2, 1e-3])
- nose.tools.assert_raises(AssimuloException, sim._set_rtol, np.array([1e-2, 1e-3]))
+ with pytest.raises(AssimuloException):
+ sim._set_rtol([1e-2, 1e-3])
+ with pytest.raises(AssimuloException):
+ sim._set_rtol(np.array([1e-2, 1e-3]))
@testattr(stddist = True)
def test_rtol_zero(self):
@@ -844,7 +879,7 @@ def test_rtol_zero(self):
sim = CVode(prob)
sim.rtol = 0.
- nose.tools.assert_equal(sim.rtol, 0.)
+ assert sim.rtol == 0.
@testattr(stddist = True)
def test_rtol_vector_with_zeroes(self):
@@ -855,12 +890,13 @@ def test_rtol_vector_with_zeroes(self):
if sim.supports['rtol_as_vector']:
sim.rtol = [1., 0.]
- nose.tools.assert_equal(sim.rtol[0], 1.)
- nose.tools.assert_equal(sim.rtol[1], 0.)
+ assert sim.rtol[0] == 1.
+ assert sim.rtol[1] == 0.
sim.simulate(1.)
else:
- nose.tools.assert_raises(AssimuloException, sim._set_rtol, [1., 0.])
+ with pytest.raises(AssimuloException):
+ sim._set_rtol([1., 0.])
@testattr(stddist = True)
def test_rtol_vector_sense(self):
@@ -873,7 +909,8 @@ def test_rtol_vector_sense(self):
sim = CVode(prob)
# not supported
- nose.tools.assert_raises(AssimuloException, sim._set_rtol, [1., 0.])
+ with pytest.raises(AssimuloException):
+ sim._set_rtol([1., 0.])
# Ok
sim.rtol = 1e-6
sim.rtol = [1e-6]
@@ -881,7 +918,8 @@ def test_rtol_vector_sense(self):
class Test_IDA:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This function sets up the test case.
"""
@@ -889,8 +927,8 @@ def setUp(self):
y0 = [1.0]
yd0 = [1.0]
- self.problem = Implicit_Problem(f,y0,yd0)
- self.simulator = IDA(self.problem)
+ cls.problem = Implicit_Problem(f,y0,yd0)
+ cls.simulator = IDA(cls.problem)
@testattr(stddist = True)
def test_time_limit(self):
@@ -903,7 +941,8 @@ def test_time_limit(self):
exp_sim.time_limit = 1 #One second
exp_sim.report_continuously = True
- nose.tools.assert_raises(TimeLimitExceeded, exp_sim.simulate, 1)
+ with pytest.raises(TimeLimitExceeded):
+ exp_sim.simulate(1)
@testattr(stddist = True)
def test_simulate_explicit(self):
@@ -916,22 +955,22 @@ def test_simulate_explicit(self):
problem = Explicit_Problem(f,y0)
simulator = IDA(problem)
- nose.tools.assert_equal(simulator.yd0[0], -simulator.y0[0])
+ assert simulator.yd0[0] == -simulator.y0[0]
t,y = simulator.simulate(1.0)
- nose.tools.assert_almost_equal(float(y[-1]), float(np.exp(-1.0)),4)
+ assert float(y[-1]) == pytest.approx(float(np.exp(-1.0)),4)
@testattr(stddist = True)
def test_init(self):
"""
This tests the functionality of the method __init__.
"""
- nose.tools.assert_false(self.simulator.suppress_alg)
- nose.tools.assert_equal(self.simulator.algvar[0], 1.0)
- nose.tools.assert_equal(self.simulator.sw, None)
- nose.tools.assert_equal(self.simulator.maxsteps, 10000)
- nose.tools.assert_equal(self.simulator.y[0], 1.0)
+ assert not self.simulator.suppress_alg
+ assert self.simulator.algvar[0] == 1.0
+ assert self.simulator.sw == None
+ assert self.simulator.maxsteps == 10000
+ assert self.simulator.y[0] == 1.0
@testattr(stddist = True)
def test_interpolate(self):
@@ -948,7 +987,7 @@ def test_interpolate(self):
t100 = sim.t_sol
sim.reset()
sim.simulate(10.)
- nose.tools.assert_almost_equal(y100[-2], sim.interpolate(9.9,0),5)
+ assert_almost_equal(y100[-2], sim.interpolate(9.9,0),5)
@testattr(stddist = True)
def test_handle_result(self):
@@ -957,7 +996,7 @@ def test_handle_result(self):
"""
f = lambda t,x,xd: x**0.25-xd
def handle_result(solver, t ,y, yd):
- nose.tools.assert_equal(solver.t, t)
+ assert solver.t == t
prob = Implicit_Problem(f, [1.0],[1.0])
prob.handle_result = handle_result
@@ -973,42 +1012,47 @@ def test_max_order(self):
"""
This tests the functionality of the property maxord.
"""
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, "Test")
- nose.tools.assert_raises(Exception, self.simulator._set_max_ord, [1,1])
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord("Test")
+ with pytest.raises(Exception):
+ self.simulator._set_max_ord([1,1])
self.simulator.maxord = -1
- nose.tools.assert_equal(self.simulator.maxord, 1)
+ assert self.simulator.maxord == 1
self.simulator.maxord = 2
- nose.tools.assert_equal(self.simulator.maxord, 2)
+ assert self.simulator.maxord == 2
self.simulator.maxord = 6
- nose.tools.assert_equal(self.simulator.maxord, 5)
+ assert self.simulator.maxord == 5
@testattr(stddist = True)
def test_tout1(self):
"""
This tests the functionality of the property tout1.
"""
- nose.tools.assert_raises(Exception, self.simulator._set_tout1, 'Test')
- nose.tools.assert_raises(Exception, self.simulator._set_tout1, [1,1])
- nose.tools.assert_raises(Exception, self.simulator._set_tout1, 'Test')
+ with pytest.raises(Exception):
+ self.simulator._set_tout1('Test')
+ with pytest.raises(Exception):
+ self.simulator._set_tout1([1,1])
+ with pytest.raises(Exception):
+ self.simulator._set_tout1('Test')
- nose.tools.assert_equal(self.simulator.tout1, 0.0001)
+ assert self.simulator.tout1 == 0.0001
self.simulator.tout1 = -0.001
- nose.tools.assert_equal(self.simulator.tout1, -0.001)
+ assert self.simulator.tout1 == -0.001
self.simulator.tout1 = 1
- nose.tools.assert_equal(self.simulator.tout1, 1.0)
+ assert self.simulator.tout1 == 1.0
@testattr(stddist = True)
def test_lsoff(self):
"""
This tests the functionality of the property lsoff.
"""
- nose.tools.assert_false(self.simulator.lsoff)
+ assert not self.simulator.lsoff
self.simulator.lsoff = True
- nose.tools.assert_true(self.simulator.lsoff)
+ assert self.simulator.lsoff
self.simulator.lsoff = False
- nose.tools.assert_false(self.simulator.lsoff)
+ assert not self.simulator.lsoff
@testattr(stddist = True)
def test_initstep(self):
@@ -1027,13 +1071,13 @@ def f(t,y,yd):
sim = IDA(mod)
sim.simulate(2.0)
- nose.tools.assert_almost_equal(sim.y_sol[-1][0], -13.4746473811, places=7)
+ assert sim.y_sol[-1][0] == pytest.approx(-13.4746473811, rel = 1e-7)
sim.reset()
sim.inith = 1e-10
sim.simulate(2.0)
- nose.tools.assert_almost_equal(sim.y_sol[-1][0], -13.4746596311, places=7)
+ assert sim.y_sol[-1][0] == pytest.approx(-13.4746596311, rel = 1e-7)
@testattr(stddist = True)
def test_time_event(self):
@@ -1070,9 +1114,9 @@ def handle_event(solver, event_info):
sim.simulate(5.0)
- nose.tools.assert_almost_equal(sim.y_sol[38], 1.0000000, 5)
- nose.tools.assert_almost_equal(sim.y_sol[87], 1.0000000, 5)
- nose.tools.assert_almost_equal(sim.t_sol[-1], 5.0000000, 5)
+ assert sim.y_sol[38] == pytest.approx(1.0000000, rel = 1e-5)
+ assert sim.y_sol[87] == pytest.approx(1.0000000, rel = 1e-5)
+ assert sim.t_sol[-1] == pytest.approx(5.0000000, rel = 1e-5)
@testattr(stddist = True)
def test_clear_event_log(self):
@@ -1106,14 +1150,14 @@ def handle_event(solver, event_info):
sim = IDA(mod)
sim.verbosity = 10
- nose.tools.assert_equal(len(sim.event_data), 0)
+ assert len(sim.event_data) == 0
sim.simulate(5.0)
- nose.tools.assert_greater(len(sim.event_data), 0)
+ assert len(sim.event_data) > 0
sim.reset()
- nose.tools.assert_equal(len(sim.event_data), 0)
+ assert len(sim.event_data) == 0
sim.simulate(5.0)
- nose.tools.assert_greater(len(sim.event_data), 0)
+ assert len(sim.event_data) > 0
@testattr(stddist = True)
def test_usejac(self):
@@ -1130,15 +1174,15 @@ def test_usejac(self):
imp_sim.simulate(3,100)
- nose.tools.assert_equal(imp_sim.statistics["nfcnjacs"], 0)
- nose.tools.assert_almost_equal(imp_sim.y_sol[-1][0], 45.1900000, 4)
+ assert imp_sim.statistics["nfcnjacs"] == 0
+ assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, rel = 1e-4)
imp_sim.reset()
imp_sim.usejac=False
imp_sim.simulate(3.,100)
- nose.tools.assert_almost_equal(imp_sim.y_sol[-1][0], 45.1900000, 4)
- nose.tools.assert_greater(imp_sim.statistics["nfcnjacs"], 0)
+ assert imp_sim.y_sol[-1][0] == pytest.approx(45.1900000, rel = 1e-4)
+ assert imp_sim.statistics["nfcnjacs"] > 0
@testattr(stddist = True)
def test_terminate_simulation(self):
@@ -1160,7 +1204,7 @@ def handle_event(self,solver, event_info):
sim = IDA(prob)
sim.simulate(2.5)
- nose.tools.assert_almost_equal(sim.t, 2.000000, 4)
+ assert sim.t == pytest.approx(2.000000, rel = 1e-4)
@testattr(stddist = True)
def test_terminate_simulation_external_event(self):
@@ -1183,7 +1227,7 @@ def handle_event(self,solver, event_info):
sim.external_event_detection = True
sim.simulate(2.5)
- nose.tools.assert_almost_equal(sim.t, 2.000000, 4)
+ assert sim.t == pytest.approx(2.000000, rel = 1e-4)
@testattr(stddist = True)
def test_algvar(self):
@@ -1192,13 +1236,20 @@ def test_algvar(self):
"""
#self.simulator.Integrator.dim = 3
- #nose.tools.assert_raises(Exception, self.simulator._set_algvar, 1)
- #nose.tools.assert_raises(Exception, self.simulator._set_algvar, 1.0)
- nose.tools.assert_raises(Exception, self.simulator._set_algvar, [1,'hej',1])
- nose.tools.assert_raises(Exception, self.simulator._set_algvar, {'Test':'case'})
- nose.tools.assert_raises(Exception, self.simulator._set_algvar, [-1,0,1])
- nose.tools.assert_raises(Exception, self.simulator._set_algvar, [1.0,1.0])
- nose.tools.assert_raises(Exception, self.simulator._set_algvar, [3.0, 1.0, 1.0])
+ # with pytest.raises(Exception):
+ # self.simulator._set_algvar(1)
+ # with pytest.raises(Exception):
+ # self.simulator._set_algvar(1.0)
+ with pytest.raises(Exception):
+ self.simulator._set_algvar([1,'hej',1])
+ with pytest.raises(Exception):
+ self.simulator._set_algvar({'Test':'case'})
+ with pytest.raises(Exception):
+ self.simulator._set_algvar([-1,0,1])
+ with pytest.raises(Exception):
+ self.simulator._set_algvar([1.0,1.0])
+ with pytest.raises(Exception):
+ self.simulator._set_algvar([3.0, 1.0, 1.0])
#vector = [1.0,0.0,1.0]
#vectorb = [True,False,True]
@@ -1207,9 +1258,9 @@ def test_algvar(self):
#self.simulator.algvar = vectorb
#self.simulator.algvar = vectori
#self.simulator.algvar = vector
- #nose.tools.assert_equal(self.simulator.algvar[0], vector[0])
- #nose.tools.assert_equal(self.simulator.algvar[1], vector[1])
- #nose.tools.assert_equal(self.simulator.algvar[2], vector[2])
+ #assert_equal(self.simulator.algvar[0], vector[0])
+ #assert_equal(self.simulator.algvar[1], vector[1])
+ #assert_equal(self.simulator.algvar[2], vector[2])
@testattr(stddist = True)
def test_time_event_2(self):
@@ -1233,9 +1284,9 @@ def time_events(t,y,yd,sw):
def handle_event(solver, event_info):
solver.y+= 1.0
global tnext
- nose.tools.assert_almost_equal(solver.t, tnext)
- nose.tools.assert_equal(event_info[0], [])
- nose.tools.assert_true(event_info[1])
+ assert solver.t == pytest.approx(tnext)
+ assert event_info[0] == []
+ assert event_info[1]
exp_mod = Implicit_Problem(f,0.0,0.0)
exp_mod.time_events = time_events
@@ -1245,7 +1296,7 @@ def handle_event(solver, event_info):
exp_sim = IDA(exp_mod)
exp_sim(5.,100)
- nose.tools.assert_equal(nevent, 5)
+ assert nevent == 5
@testattr(stddist = True)
def test_suppress_alg(self):
@@ -1253,9 +1304,9 @@ def test_suppress_alg(self):
This tests the functionality of the property suppress_alg.
"""
self.simulator.suppress_alg = True
- nose.tools.assert_true(self.simulator.suppress_alg)
+ assert self.simulator.suppress_alg
self.simulator.suppress_alg = False
- nose.tools.assert_false(self.simulator.suppress_alg)
+ assert not self.simulator.suppress_alg
@testattr(stddist = True)
def test_make_consistency(self):
@@ -1276,10 +1327,10 @@ def f(t,y,yd):
[flag, y, yd] = simulator.make_consistent('IDA_Y_INIT')
- nose.tools.assert_almost_equal(y[1], 0.00000)
- nose.tools.assert_almost_equal(y[0], -1.0000)
- nose.tools.assert_almost_equal(yd[0], 1.0000)
- nose.tools.assert_almost_equal(yd[1], 0.0000)
+ assert y[1] == pytest.approx(0.00000)
+ assert y[0] == pytest.approx(-1.0000)
+ assert yd[0] == pytest.approx(1.0000)
+ assert yd[1] == pytest.approx(0.0000)
@testattr(stddist = True)
def test_switches(self):
@@ -1298,9 +1349,9 @@ def handle_event(solver, event_info):
mod.handle_event = handle_event
sim = IDA(mod)
- nose.tools.assert_true(sim.sw[0])
+ assert sim.sw[0]
sim.simulate(3)
- nose.tools.assert_false(sim.sw[0])
+ assert not sim.sw[0]
@testattr(stddist = True)
def test_completed_step(self):
@@ -1326,19 +1377,20 @@ def completed_step(solver):
sim = IDA(mod)
sim.simulate(2., 100)
- nose.tools.assert_equal(len(sim.t_sol), 101)
- nose.tools.assert_equal(nsteps, sim.statistics["nsteps"])
+ assert len(sim.t_sol) == 101
+ assert nsteps == sim.statistics["nsteps"]
sim = IDA(mod)
nsteps = 0
sim.simulate(2.)
- nose.tools.assert_equal(len(sim.t_sol), sim.statistics["nsteps"] + 1)
- nose.tools.assert_equal(nsteps, sim.statistics["nsteps"])
+ assert len(sim.t_sol) == sim.statistics["nsteps"] + 1
+ assert nsteps == sim.statistics["nsteps"]
class Test_Sundials:
- def setUp(self):
+ @classmethod
+ def setup_class(cls):
"""
This sets up the test case.
"""
@@ -1359,7 +1411,7 @@ class Prob_CVode(Explicit_Problem):
f = Prob_CVode()
- self.simulators = [IDA(res), CVode(f)]
+ cls.simulators = [IDA(res), CVode(f)]
f = lambda t,y,yd,p: np.array([0.0])
@@ -1368,42 +1420,47 @@ class Prob_CVode(Explicit_Problem):
p0 = [1.0]
mod = Implicit_Problem(f, y0,yd0,p0=p0)
- self.sim = IDA(mod)
+ cls.sim = IDA(mod)
@testattr(stddist = True)
def test_atol(self):
"""
This tests the functionality of the property atol.
"""
- nose.tools.assert_equal(self.simulators[1].atol, 1.0e-6)
- nose.tools.assert_equal(self.simulators[0].atol, 1.0e-6)
+ assert self.simulators[1].atol == 1.0e-6
+ assert self.simulators[0].atol == 1.0e-6
for i in range(len(self.simulators)):
- nose.tools.assert_raises(Exception, self.simulators[i]._set_atol, -1.0)
- nose.tools.assert_raises(Exception, self.simulators[i]._set_atol, [1.0, 1.0])
- nose.tools.assert_raises(Exception, self.simulators[i]._set_atol, "Test")
+ with pytest.raises(Exception):
+ self.simulators([i]._set_atol, -1.0)
+ with pytest.raises(Exception):
+ self.simulators([i]._set_atol, [1.0, 1.0])
+ with pytest.raises(Exception):
+ self.simulators([i]._set_atol, "Test")
self.simulators[i].atol = 1.0e-5
- nose.tools.assert_equal(self.simulators[i].atol, 1.0e-5)
+ assert self.simulators[i].atol == 1.0e-5
self.simulators[i].atol = 1.0
- nose.tools.assert_equal(self.simulators[i].atol, 1.0)
+ assert self.simulators[i].atol == 1.0
self.simulators[i].atol = 1
- nose.tools.assert_equal(self.simulators[i].atol, 1.0)
+ assert self.simulators[i].atol == 1.0
self.simulators[i].atol = 1001.0
- nose.tools.assert_equal(self.simulators[i].atol, 1001.0)
+ assert self.simulators[i].atol == 1001.0
self.simulators[i].atol = [np.array([1e-5])]
- nose.tools.assert_equal(len(self.simulators[i].atol.shape), 1)
- nose.tools.assert_equal(self.simulators[i].atol, 1e-5)
+ assert len(self.simulators[i].atol.shape) == 1
+ assert self.simulators[i].atol == 1e-5
"""
self.simulators[i].Integrator.dim = 3
- nose.tools.assert_raises(Exception, self.simulators[i]._set_atol, [1.0, 1.0])
- nose.tools.assert_raises(Exception, self.simulators[i]._set_atol, [1.0, 1.0, -1.0])
+ with pytest.raises(Exception):
+ self.simulators([i]._set_atol, [1.0, 1.0])
+ with pytest.raises(Exception):
+ self.simulators([i]._set_atol, [1.0, 1.0, -1.0])
self.simulators[i].atol = [1.0, 1.0, 1.0]
- nose.tools.assert_equal(self.simulators[i].atol, [1.0, 1.0, 1.0])
+ assert_equal(self.simulators[i].atol, [1.0, 1.0, 1.0])
self.simulators[i].atol = np.array([1.0, 1.0, 1.0])
- nose.tools.assert_equal(self.simulators[i].atol[0], 1.0)
+ assert_equal(self.simulators[i].atol[0], 1.0)
self.simulators[i].atol = np.array([1, 5, 1.0])
- nose.tools.assert_equal(self.simulators[i].atol[0], 1.0)
+ assert_equal(self.simulators[i].atol[0], 1.0)
"""
@@ -1413,18 +1470,21 @@ def test_rtol(self):
This tests the functionality of the property rtol.
"""
for sim in self.simulators:
- nose.tools.assert_raises(Exception, sim._set_rtol, -1.0)
- nose.tools.assert_raises(Exception, sim._set_rtol, [1.0, 2.0]) ## size mismatch
- nose.tools.assert_raises(Exception, sim._set_rtol, "Test")
+ with pytest.raises(Exception):
+ sim._set_rtol(-1.0)
+ with pytest.raises(Exception):
+ sim._set_rtol([1.0, 2.0]) ## size mismatch
+ with pytest.raises(Exception):
+ sim._set_rtol("Test")
sim.rtol = 1.0e-5
- nose.tools.assert_equal(sim.rtol, 1.0e-5)
+ assert sim.rtol == 1.0e-5
sim.rtol = 1.0
- nose.tools.assert_equal(sim.rtol, 1.0)
+ assert sim.rtol == 1.0
sim.rtol = 1001.0
- nose.tools.assert_equal(sim.rtol, 1001.0)
+ assert sim.rtol == 1001.0
sim.rtol = 1001
- nose.tools.assert_equal(sim.rtol, 1001.0)
+ assert sim.rtol == 1001.0
@testattr(stddist = True)
def test_maxh(self):
@@ -1432,15 +1492,17 @@ def test_maxh(self):
This tests the functionality of the property maxh.
"""
for i in range(len(self.simulators)):
- nose.tools.assert_raises(Exception, self.simulators[i]._set_max_h, [1.0, 1.0])
- nose.tools.assert_raises(Exception, self.simulators[i]._set_max_h, "Test")
+ with pytest.raises(Exception):
+ self.simulators([i]._set_max_h, [1.0, 1.0])
+ with pytest.raises(Exception):
+ self.simulators([i]._set_max_h, "Test")
self.simulators[i].maxh = 1.0e-5
- nose.tools.assert_equal(self.simulators[i].maxh, 1.0e-5)
+ assert self.simulators[i].maxh == 1.0e-5
self.simulators[i].maxh = 1.0
- nose.tools.assert_equal(self.simulators[i].maxh, 1.0)
+ assert self.simulators[i].maxh == 1.0
self.simulators[i].maxh = 1001.0
- nose.tools.assert_equal(self.simulators[i].maxh, 1001.0)
+ assert self.simulators[i].maxh == 1001.0
@testattr(stddist = True)
def test_dqtype(self):
@@ -1448,103 +1510,119 @@ def test_dqtype(self):
Tests the property of dqtype.
"""
- nose.tools.assert_equal(self.sim.dqtype, 'CENTERED') #Test the default value.
+ assert self.sim.dqtype == 'CENTERED' #Test the default value.
self.sim.dqtype = 'FORWARD'
- nose.tools.assert_equal(self.sim.dqtype, 'FORWARD')
+ assert self.sim.dqtype == 'FORWARD'
self.sim.dqtype = 'CENTERED'
- nose.tools.assert_equal(self.sim.dqtype, 'CENTERED')
+ assert self.sim.dqtype == 'CENTERED'
self.sim.dqtype = 'forward'
- nose.tools.assert_equal(self.sim.dqtype, 'FORWARD')
+ assert self.sim.dqtype == 'FORWARD'
self.sim.dqtype = 'centered'
- nose.tools.assert_equal(self.sim.dqtype, 'CENTERED')
-
- nose.tools.assert_raises(Exception,self.sim._set_dqtype, 1)
- nose.tools.assert_raises(Exception,self.sim._set_dqtype, 'IDA_CE')
- nose.tools.assert_raises(Exception,self.sim._set_dqtype, [1])
- nose.tools.assert_raises(Exception,self.sim._set_dqtype, -1)
+ assert self.sim.dqtype == 'CENTERED'
+
+ with pytest.raises(Exception):
+ self.sim._set_dqtype(1)
+ with pytest.raises(Exception):
+ self.sim._set_dqtype('IDA_CE')
+ with pytest.raises(Exception):
+ self.sim._set_dqtype([1])
+ with pytest.raises(Exception):
+ self.sim._set_dqtype(-1)
@testattr(stddist = True)
def test_dqrhomax(self):
"""
Tests the property of DQrhomax.
"""
- nose.tools.assert_equal(self.sim.dqrhomax, 0.0) #Test the default value.
+ assert self.sim.dqrhomax == 0.0 #Test the default value.
self.sim.dqrhomax = 1.0
- nose.tools.assert_equal(self.sim.dqrhomax, 1.0)
+ assert self.sim.dqrhomax == 1.0
self.sim.dqrhomax = 10
- nose.tools.assert_equal(self.sim.dqrhomax, 10)
-
- nose.tools.assert_raises(Exception,self.sim._set_dqrhomax, -1)
- nose.tools.assert_raises(Exception,self.sim._set_dqrhomax, 'str')
- nose.tools.assert_raises(Exception,self.sim._set_dqrhomax, [])
- nose.tools.assert_raises(Exception,self.sim._set_dqrhomax, -10)
+ assert self.sim.dqrhomax == 10
+
+ with pytest.raises(Exception):
+ self.sim._set_dqrhomax(-1)
+ with pytest.raises(Exception):
+ self.sim._set_dqrhomax('str')
+ with pytest.raises(Exception):
+ self.sim._set_dqrhomax([])
+ with pytest.raises(Exception):
+ self.sim._set_dqrhomax(-10)
@testattr(stddist = True)
def test_usesens(self):
"""
Tests the property of usesens.
"""
- nose.tools.assert_true(self.sim.usesens)#Test the default value.
+ assert self.sim.usesens#Test the default value.
self.sim.usesens = False
- nose.tools.assert_false(self.sim.usesens)
+ assert not self.sim.usesens
self.sim.usesens = 0
- nose.tools.assert_false(self.sim.usesens)
+ assert not self.sim.usesens
self.sim.usesens = 1
- nose.tools.assert_true(self.sim.usesens)
+ assert self.sim.usesens
@testattr(stddist = True)
def test_sensmethod(self):
"""
Tests the property of sensmethod.
"""
- nose.tools.assert_equal(self.sim.sensmethod, 'STAGGERED') #Test the default value
+ assert self.sim.sensmethod == 'STAGGERED' #Test the default value
self.sim.sensmethod = 'SIMULTANEOUS'
- nose.tools.assert_equal(self.sim.sensmethod, 'SIMULTANEOUS')
+ assert self.sim.sensmethod == 'SIMULTANEOUS'
self.sim.sensmethod = 'STAGGERED'
- nose.tools.assert_equal(self.sim.sensmethod, 'STAGGERED')
+ assert self.sim.sensmethod == 'STAGGERED'
self.sim.sensmethod = 'simultaneous'
- nose.tools.assert_equal(self.sim.sensmethod, 'SIMULTANEOUS')
+ assert self.sim.sensmethod == 'SIMULTANEOUS'
self.sim.sensmethod = 'staggered'
- nose.tools.assert_equal(self.sim.sensmethod, 'STAGGERED')
-
- nose.tools.assert_raises(Exception,self.sim._set_sensitivity_method, 1)
- nose.tools.assert_raises(Exception,self.sim._set_sensitivity_method, 'IDA_CE')
- nose.tools.assert_raises(Exception,self.sim._set_sensitivity_method, [1])
- nose.tools.assert_raises(Exception,self.sim._set_sensitivity_method, -1)
+ assert self.sim.sensmethod == 'STAGGERED'
+
+ with pytest.raises(Exception):
+ self.sim._set_sensitivity_method(1)
+ with pytest.raises(Exception):
+ self.sim._set_sensitivity_method('IDA_CE')
+ with pytest.raises(Exception):
+ self.sim._set_sensitivity_method([1])
+ with pytest.raises(Exception):
+ self.sim._set_sensitivity_method(-1)
@testattr(stddist = True)
def test_suppress_sens(self):
"""
Tests the property of suppress_sens.
"""
- nose.tools.assert_false(self.sim.suppress_sens)
+ assert not self.sim.suppress_sens
self.sim.suppress_sens = False
- nose.tools.assert_false(self.sim.suppress_sens)
+ assert not self.sim.suppress_sens
self.sim.suppress_sens = 0
- nose.tools.assert_false(self.sim.suppress_sens)
+ assert not self.sim.suppress_sens
self.sim.suppress_sens = 1
- nose.tools.assert_true(self.sim.suppress_sens)
+ assert self.sim.suppress_sens
@testattr(stddist = True)
def test_maxsensiter(self):
"""
Tests the property of maxsensiter.
"""
- nose.tools.assert_equal(self.sim.maxcorS, 3) #Test the default value
+ assert self.sim.maxcorS == 3 #Test the default value
self.sim.maxcorS = 1
- nose.tools.assert_equal(self.sim.maxcorS, 1)
+ assert self.sim.maxcorS == 1
self.sim.maxcorS = 10.5
- nose.tools.assert_equal(self.sim.maxcorS, 10)
-
- #nose.tools.assert_raises(Exception, self.sim._set_max_cor_S, 0)
- nose.tools.assert_raises(Exception, self.sim._set_max_cor_S, 'str')
- nose.tools.assert_raises(Exception, self.sim._set_max_cor_S, [])
- #nose.tools.assert_raises(Exception, self.sim._set_max_cor_S, -10)
+ assert self.sim.maxcorS == 10
+
+ # with pytest.raises(Exception):
+ # self.sim._set_max_cor_S(0)
+ with pytest.raises(Exception):
+ self.sim._set_max_cor_S('str')
+ with pytest.raises(Exception):
+ self.sim._set_max_cor_S([])
+ # with pytest.raises(Exception):
+ # self.sim._set_max_cor_S(-10)
@testattr(stddist = True)
def test_pbar(self):
@@ -1558,8 +1636,8 @@ def test_pbar(self):
exp_sim = CVode(exp_mod)
- nose.tools.assert_almost_equal(exp_sim.pbar[0], 1000.00000,4)
- nose.tools.assert_almost_equal(exp_sim.pbar[1], 100.000000,4)
+ assert exp_sim.pbar[0] == pytest.approx(1000.00000, rel = 1e-4)
+ assert exp_sim.pbar[1] == pytest.approx(100.000000, rel = 1e-4)
f = lambda t,y,yd,p: np.array([0.0]*len(y))
yd0 = [0.0]*2
@@ -1567,5 +1645,5 @@ def test_pbar(self):
imp_sim = IDA(imp_mod)
- nose.tools.assert_almost_equal(imp_sim.pbar[0], 1000.00000,4)
- nose.tools.assert_almost_equal(imp_sim.pbar[1], 100.000000,4)
+ assert imp_sim.pbar[0] == pytest.approx(1000.00000, rel = 1e-4)
+ assert imp_sim.pbar[1] == pytest.approx(100.000000, rel = 1e-4)
diff --git a/tests/test_explicit_ode.py b/tests/test_explicit_ode.py
index 2a5d650c..11210a7c 100644
--- a/tests/test_explicit_ode.py
+++ b/tests/test_explicit_ode.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.explicit_ode import Explicit_ODE
from assimulo.problem import Explicit_Problem
@@ -28,16 +28,16 @@ def test_elapsed_step_time(self):
prob = Explicit_Problem(rhs, 0.0)
solv = Explicit_ODE(prob)
- nose.tools.assert_equal(solv.get_elapsed_step_time(), -1.0)
+ assert solv.get_elapsed_step_time() == -1.0
@testattr(stddist = True)
def test_problem_name_attribute(self):
rhs = lambda t,y: y
prob = Explicit_Problem(rhs, 0.0)
- nose.tools.assert_equal(prob.name, "---")
+ assert prob.name == "---"
prob = Explicit_Problem(rhs, 0.0, name="Test")
- nose.tools.assert_equal(prob.name, "Test")
+ assert prob.name == "Test"
@testattr(stddist = True)
def test_re_init(self):
@@ -47,10 +47,10 @@ def test_re_init(self):
prob = Explicit_Problem(rhs, 0.0)
solv = Explicit_ODE(prob)
- nose.tools.assert_equal(solv.t, 0.0)
- nose.tools.assert_equal(solv.y[0], 0.0)
+ assert solv.t == 0.0
+ assert solv.y[0] == 0.0
solv.re_init(1.0, 2.0)
- nose.tools.assert_equal(solv.t, 1.0)
- nose.tools.assert_equal(solv.y[0], 2.0)
+ assert solv.t == 1.0
+ assert solv.y[0] == 2.0
diff --git a/tests/test_implicit_ode.py b/tests/test_implicit_ode.py
index aeb7ea4b..35ca7c2d 100644
--- a/tests/test_implicit_ode.py
+++ b/tests/test_implicit_ode.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.implicit_ode import Implicit_ODE
from assimulo.problem import Implicit_Problem
@@ -29,16 +29,16 @@ def test_elapsed_step_time(self):
prob = Implicit_Problem(res, 0.0, 0.0)
solv = Implicit_ODE(prob)
- nose.tools.assert_equal(solv.get_elapsed_step_time(), -1.0)
+ assert solv.get_elapsed_step_time() == -1.0
@testattr(stddist = True)
def test_problem_name_attribute(self):
res = lambda t,y,yd: y
prob = Implicit_Problem(res, 0.0, 0.0)
- nose.tools.assert_equal(prob.name, "---")
+ assert prob.name == "---"
prob = Implicit_Problem(res, 0.0, 0.0, name="Test")
- nose.tools.assert_equal(prob.name, "Test")
+ assert prob.name == "Test"
@testattr(stddist = True)
def test_re_init(self):
@@ -48,12 +48,12 @@ def test_re_init(self):
prob = Implicit_Problem(res, 0.0, 0.0)
solv = Implicit_ODE(prob)
- nose.tools.assert_equal(solv.t, 0.0)
- nose.tools.assert_equal(solv.y[0], 0.0)
- nose.tools.assert_equal(solv.yd[0], 0.0)
+ assert solv.t == 0.0
+ assert solv.y[0] == 0.0
+ assert solv.yd[0] == 0.0
solv.re_init(1.0, 2.0, 3.0)
- nose.tools.assert_equal(solv.t, 1.0)
- nose.tools.assert_equal(solv.y[0], 2.0)
- nose.tools.assert_equal(solv.yd[0], 3.0)
+ assert solv.t == 1.0
+ assert solv.y[0] == 2.0
+ assert solv.yd[0] == 3.0
diff --git a/tests/test_ode.py b/tests/test_ode.py
index b3fa0919..f67a808a 100644
--- a/tests/test_ode.py
+++ b/tests/test_ode.py
@@ -15,52 +15,56 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
from assimulo import testattr
from assimulo.ode import ODE, NORMAL
from assimulo.problem import Explicit_Problem
from assimulo.exception import AssimuloException
class Test_ODE:
-
- def setUp(self):
- self.problem = Explicit_Problem(y0=4.0)
- self.simulator = ODE(self.problem)
+ @classmethod
+ def setup_class(cls):
+ cls.problem = Explicit_Problem(y0=4.0)
+ cls.simulator = ODE(cls.problem)
@testattr(stddist = True)
def test_init(self):
"""
This tests the functionality of the method __init__.
"""
- nose.tools.assert_equal(self.simulator.verbosity, NORMAL)
- nose.tools.assert_false(self.simulator.report_continuously)
+ assert self.simulator.verbosity == NORMAL
+ assert not self.simulator.report_continuously
@testattr(stddist = True)
def test_verbosity(self):
"""
This tests the functionality of the property verbosity.
"""
- nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, 'Test')
- nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, [1, 31])
- nose.tools.assert_raises(AssimuloException, self.simulator._set_verbosity, [1])
-
+
+ with pytest.raises(AssimuloException):
+ self.simulator._set_verbosity('Test')
+ with pytest.raises(AssimuloException):
+ self.simulator._set_verbosity([1, 31])
+ with pytest.raises(AssimuloException):
+ self.simulator._set_verbosity([1])
+
self.simulator.verbosity=1
- nose.tools.assert_equal(self.simulator.verbosity, 1)
- nose.tools.assert_equal(self.simulator.options["verbosity"], 1)
+ assert self.simulator.verbosity == 1
+ assert self.simulator.options["verbosity"] == 1
self.simulator.verbosity=4
- nose.tools.assert_equal(self.simulator.verbosity, 4)
- nose.tools.assert_equal(self.simulator.options["verbosity"], 4)
+ assert self.simulator.verbosity == 4
+ assert self.simulator.options["verbosity"] == 4
@testattr(stddist = True)
def test_report_continuously(self):
"""
This tests the functionality of the property report_continuously.
"""
- nose.tools.assert_false(self.simulator.report_continuously) #Test the default value
+ assert not self.simulator.report_continuously #Test the default value
self.simulator.report_continuously = True
- nose.tools.assert_true(self.simulator.report_continuously)
- nose.tools.assert_true(self.simulator.options["report_continuously"])
+ assert self.simulator.report_continuously
+ assert self.simulator.options["report_continuously"]
def test_step_events_report_continuously(self):
"""
This test tests if report_continuously is set correctly, when step_events are present.
@@ -70,4 +74,4 @@ def test_step_events_report_continuously(self):
self.simulator.problem_info["step_events"] = True
self.simulator.problem=self.problem
self.simulator(10.,ncp=10) # output points and step events should set report_continuously to True
- nose.tools.assert_true(self.simulator.report_continuously)
+ assert self.simulator.report_continuously
diff --git a/tests/test_solvers.py b/tests/test_solvers.py
index 58543c82..88777fca 100644
--- a/tests/test_solvers.py
+++ b/tests/test_solvers.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
-import nose
+import pytest
import numpy as np
from assimulo import testattr
from assimulo.problem import Explicit_Problem, Implicit_Problem
@@ -33,14 +33,15 @@ def handle_event(solver, event_info):
pass
class Test_Solvers:
- def setUp(self):
- self.problem = Implicit_Problem(res, [1.0], [-1.0])
- self.problem.state_events = state_events
- self.problem.handle_event = handle_event
+ @classmethod
+ def setup_class(cls):
+ cls.problem = Implicit_Problem(res, [1.0], [-1.0])
+ cls.problem.state_events = state_events
+ cls.problem.handle_event = handle_event
- self.eproblem = Explicit_Problem(rhs, [1.0])
- self.eproblem.state_events = estate_events
- self.eproblem.handle_event = handle_event
+ cls.eproblem = Explicit_Problem(rhs, [1.0])
+ cls.eproblem.state_events = estate_events
+ cls.eproblem.handle_event = handle_event
@testattr(stddist = True)
def test_radau5dae_state_events(self):
@@ -48,7 +49,7 @@ def test_radau5dae_state_events(self):
t,y,yd = solver.simulate(2,33)
- nose.tools.assert_almost_equal(float(y[-1]), 0.135, 3)
+ assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3)
@testattr(stddist = True)
def test_dopri5_state_events(self):
@@ -56,7 +57,7 @@ def test_dopri5_state_events(self):
t,y = solver.simulate(2,33)
- nose.tools.assert_almost_equal(float(y[-1]), 0.135, 3)
+ assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3)
@testattr(stddist = True)
def test_rodasode_state_events(self):
@@ -64,4 +65,4 @@ def test_rodasode_state_events(self):
t,y = solver.simulate(2,33)
- nose.tools.assert_almost_equal(float(y[-1]), 0.135, 3)
+ assert float(y[-1]) == pytest.approx(0.135, rel = 1e-3)