From b40b609c6f805827bff4ed83c4ee7af588c32f50 Mon Sep 17 00:00:00 2001 From: Peter Meisrimel Date: Wed, 2 Oct 2024 15:27:16 +0200 Subject: [PATCH] more fixes Cleanup removed pytest as requirement from examples Removing tests from the Assimulo installation Adding pytest config; adjusted instructions simplified workflow file Changed if in test to skipif Added missing reason in skipif --- .github/workflows/build.yml | 2 +- CHANGELOG | 4 +++- INSTALL | 2 +- doc/sphinx/source/installation.rst | 4 ++-- examples/cvode_basic.py | 5 ++--- examples/cvode_basic_backward.py | 3 +-- examples/cvode_gyro.py | 5 ++--- examples/cvode_stability.py | 1 - examples/cvode_with_disc.py | 7 +++---- examples/cvode_with_initial_sensitivity.py | 9 ++++----- examples/cvode_with_jac.py | 5 ++--- examples/cvode_with_jac_sparse.py | 3 +-- examples/cvode_with_jac_spgmr.py | 5 ++--- examples/cvode_with_parameters.py | 14 +++++++------- examples/cvode_with_parameters_fcn.py | 14 +++++++------- examples/cvode_with_parameters_modified.py | 12 ++++++------ examples/cvode_with_preconditioning.py | 5 ++--- examples/dasp3_basic.py | 3 +-- examples/dopri5_basic.py | 3 +-- examples/dopri5_with_disc.py | 7 +++---- examples/euler_basic.py | 3 +-- examples/euler_vanderpol.py | 1 - examples/euler_with_disc.py | 7 +++---- examples/glimda_vanderpol.py | 3 +-- examples/ida_basic_backward.py | 3 +-- examples/ida_with_disc.py | 7 +++---- examples/ida_with_initial_sensitivity.py | 9 ++++----- examples/ida_with_jac.py | 9 ++++----- examples/ida_with_jac_spgmr.py | 5 ++--- examples/ida_with_parameters.py | 14 +++++++------- examples/ida_with_user_defined_handle_result.py | 11 +++++------ examples/kinsol_basic.py | 3 +-- examples/kinsol_ors.py | 3 +-- examples/kinsol_with_jac.py | 5 ++--- examples/lsodar_vanderpol.py | 1 - examples/lsodar_with_disc.py | 7 +++---- examples/mech_system_pendulum.py | 1 - examples/radau5dae_time_events.py | 1 - examples/radau5dae_vanderpol.py | 1 - examples/radau5ode_vanderpol.py | 1 - examples/radau5ode_with_disc.py | 7 +++---- examples/radau5ode_with_disc_sparse.py | 7 +++---- examples/radau5ode_with_jac_sparse.py | 3 +-- examples/rodasode_vanderpol.py | 1 - examples/rungekutta34_basic.py | 3 +-- examples/rungekutta34_with_disc.py | 7 +++---- examples/rungekutta4_basic.py | 3 +-- pytest.ini | 3 +++ setup.cfg | 4 +++- setup.py | 17 +++++------------ tests/solvers/test_sundials.py | 3 +-- tests/test_examples.py | 5 +++-- 52 files changed, 116 insertions(+), 155 deletions(-) create mode 100644 pytest.ini diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 15054a2f..7af778fb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,4 +44,4 @@ jobs: - name: Build run: python3 setup.py install --user --sundials-home=/usr --blas-home=/usr/lib/x86_64-linux-gnu/ --lapack-home=/usr/lib/x86_64-linux-gnu/ --superlu-home=/usr - name: Test - run: pytest --verbose tests/ + run: pytest diff --git a/CHANGELOG b/CHANGELOG index a4cfb596..965358b6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,8 +1,10 @@ --- CHANGELOG --- ---- Assimulo-3.5.x --- +--- Assimulo-FUTURE--- * Added get_sundials_version function (import from assimulo.solvers.sundials). * Fixed bug that Radau5ODE would not count state events in statistics. + * Removed tests from the Assimulo installation. + * Changed testing framework from `nose` to `pytest`. --- Assimulo-3.5.2 --- * Allow to build without distutils for Python>=3.12 support diff --git a/INSTALL b/INSTALL index 73cefad1..ba1c985e 100644 --- a/INSTALL +++ b/INSTALL @@ -20,7 +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, run "pytest tests/". +To test the installation, run "pytest". 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 b50a0d9a..09a59e22 100644 --- a/doc/sphinx/source/installation.rst +++ b/doc/sphinx/source/installation.rst @@ -60,9 +60,9 @@ the section troubleshooting see :ref:`instTrouble` should be consulted before in .. note:: - To test Assimulo, go into the tests folder and type:: + To test Assimulo, type:: - pytest . + pytest Which requires pytest. diff --git a/examples/cvode_basic.py b/examples/cvode_basic.py index 35aeebf6..7019f5cd 100644 --- a/examples/cvode_basic.py +++ b/examples/cvode_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -66,8 +65,8 @@ def f(t,y): pl.show() #Basic test - assert y2[-1][0] == pytest.approx(0.00347746, abs = 1e-5) - assert exp_sim.get_last_step() == pytest.approx(0.0222169642893, abs = 1e-3) + assert abs(y2[-1][0] - 0.00347746) < 1e-5 + assert abs(exp_sim.get_last_step() - 0.0222169642893) < 1e-3 return exp_mod, exp_sim diff --git a/examples/cvode_basic_backward.py b/examples/cvode_basic_backward.py index fc076636..da9ce2c8 100644 --- a/examples/cvode_basic_backward.py +++ b/examples/cvode_basic_backward.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -62,7 +61,7 @@ def f(t,y): pl.show() #Basic test - assert y[-1][0] == pytest.approx(4.00000000, abs = 1e-3) + assert abs(y[-1][0] - 4.0) < 1e-3 return exp_mod, exp_sim diff --git a/examples/cvode_gyro.py b/examples/cvode_gyro.py index 5684d38d..f0f776f1 100644 --- a/examples/cvode_gyro.py +++ b/examples/cvode_gyro.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.problem import Explicit_Problem from assimulo.solvers import CVode @@ -83,8 +82,8 @@ def f(t, u): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(692.800241862) - assert y[-1][8] == pytest.approx(7.08468221e-1) + assert abs(y[-1][0] - 692.800241862) < 1e-6 + assert abs(y[-1][8] - 7.08468221e-1) < 1e-6 return exp_mod, exp_sim diff --git a/examples/cvode_stability.py b/examples/cvode_stability.py index 346e9745..95501473 100644 --- a/examples/cvode_stability.py +++ b/examples/cvode_stability.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem diff --git a/examples/cvode_with_disc.py b/examples/cvode_with_disc.py index fec9d8e0..6e17678c 100644 --- a/examples/cvode_with_disc.py +++ b/examples/cvode_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -156,9 +155,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 return exp_mod, exp_sim diff --git a/examples/cvode_with_initial_sensitivity.py b/examples/cvode_with_initial_sensitivity.py index ed1707e3..afca1bea 100644 --- a/examples/cvode_with_initial_sensitivity.py +++ b/examples/cvode_with_initial_sensitivity.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -123,10 +122,10 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(1577.6552477, abs = 1e-5) - assert y[-1][1] == pytest.approx(611.9574565, abs = 1e-5) - assert y[-1][2] == pytest.approx(2215.88563217, abs = 1e-5) - assert exp_sim.p_sol[0][1][0] == pytest.approx(1.0) + assert abs(y[-1][0] - 1577.6552477) < 1e-5 + assert abs(y[-1][1] - 611.9574565) < 1e-5 + assert abs(y[-1][2] - 2215.88563217) < 1e-5 + assert abs(exp_sim.p_sol[0][1][0] - 1.0) < 1e-6 return exp_mod, exp_sim diff --git a/examples/cvode_with_jac.py b/examples/cvode_with_jac.py index d5b02e74..e43d950f 100644 --- a/examples/cvode_with_jac.py +++ b/examples/cvode_with_jac.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -78,8 +77,8 @@ def jac(t,y): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) - assert y[-1][1] == pytest.approx(-49.100000000) + assert abs(y[-1][0] + 121.75000000) < 1e-4 + assert abs(y[-1][1] + 49.100000000) < 1e-6 return exp_mod, exp_sim diff --git a/examples/cvode_with_jac_sparse.py b/examples/cvode_with_jac_sparse.py index 7ee70260..4ec75bf9 100644 --- a/examples/cvode_with_jac_sparse.py +++ b/examples/cvode_with_jac_sparse.py @@ -17,7 +17,6 @@ import numpy as np import scipy.sparse as sps -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -93,7 +92,7 @@ def jac(t,y): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(0.9851, abs = 1e-3) + assert abs(y[-1][0] - 0.9851) < 1e-3 return exp_mod, exp_sim diff --git a/examples/cvode_with_jac_spgmr.py b/examples/cvode_with_jac_spgmr.py index d1ace07b..3eecd656 100644 --- a/examples/cvode_with_jac_spgmr.py +++ b/examples/cvode_with_jac_spgmr.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -85,8 +84,8 @@ def jacv(t,y,fy,v): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) - assert y[-1][1] == pytest.approx(-49.100000000) + assert abs(y[-1][0] + 121.75000000) < 1e-4 + assert abs(y[-1][1] + 49.100000000) < 1e-6 return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters.py b/examples/cvode_with_parameters.py index c7906c9c..bab8ac37 100644 --- a/examples/cvode_with_parameters.py +++ b/examples/cvode_with_parameters.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -87,12 +86,13 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) - assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) + assert abs(y[-1][0] - 9.05518032e-01) < 1e-4 + assert abs(y[-1][1] - 2.24046805e-05) < 1e-4 + assert abs(y[-1][2] - 9.44595637e-02) < 1e-4 + # Values taken from the example in Sundials + assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2 + assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8 + assert abs(exp_sim.p_sol[2][-1][0] + 4.9334e-10) < 1e-12 return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters_fcn.py b/examples/cvode_with_parameters_fcn.py index 646ee55e..35b84b0b 100644 --- a/examples/cvode_with_parameters_fcn.py +++ b/examples/cvode_with_parameters_fcn.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -104,12 +103,13 @@ def fsens(t, y, s, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) - assert exp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) + assert abs(y[-1][0] - 9.05518032e-01) < 1e-4 + assert abs(y[-1][1] - 2.24046805e-05) < 1e-4 + assert abs(y[-1][2] - 9.44595637e-02) < 1e-4 + #Values taken from the example in Sundials + assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2 + assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8 + assert abs(exp_sim.p_sol[2][-1][0] + 4.9334e-10) < 1e-12 return exp_mod, exp_sim diff --git a/examples/cvode_with_parameters_modified.py b/examples/cvode_with_parameters_modified.py index 892ac376..667608be 100644 --- a/examples/cvode_with_parameters_modified.py +++ b/examples/cvode_with_parameters_modified.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -85,11 +84,12 @@ def f(t, y, p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) - assert exp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials - assert exp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) + assert abs(y[-1][0] - 9.05518032e-01) < 1e-4 + assert abs(y[-1][1] - 2.24046805e-05) < 1e-4 + assert abs(y[-1][2] - 9.44595637e-02) < 1e-4 + # Values taken from the example in Sundials + assert abs(exp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2 + assert abs(exp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8 return exp_mod, exp_sim diff --git a/examples/cvode_with_preconditioning.py b/examples/cvode_with_preconditioning.py index 84e34291..bde5ac2a 100644 --- a/examples/cvode_with_preconditioning.py +++ b/examples/cvode_with_preconditioning.py @@ -20,7 +20,6 @@ """ import numpy as np -import pytest from assimulo.solvers import CVode from assimulo.problem import Explicit_Problem @@ -107,8 +106,8 @@ def prec_solve(t, y, fy, r, gamma, delta, data): exp_sim.plot() #Basic verification - assert y[-1,0] == pytest.approx(3.11178295, abs = 1e-4) - assert y[-1,1] == pytest.approx(3.19318992, abs = 1e-4) + assert abs(y[-1,0] - 3.11178295) < 1e-4 + assert abs(y[-1,1] - 3.19318992) < 1e-4 return exp_mod, exp_sim diff --git a/examples/dasp3_basic.py b/examples/dasp3_basic.py index ef78c244..6cf4944b 100644 --- a/examples/dasp3_basic.py +++ b/examples/dasp3_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest try: from assimulo.solvers import DASP3ODE @@ -100,7 +99,7 @@ def dzdt(t,y,z): pl.show() #Basic test - assert y[-1,0] == pytest.approx( 10.860063849896818, abs = 1e-3) + assert abs(y[-1,0] - 10.860063849896818) < 1e-3 return exp_mod, exp_sim diff --git a/examples/dopri5_basic.py b/examples/dopri5_basic.py index fcf76247..fc14d075 100644 --- a/examples/dopri5_basic.py +++ b/examples/dopri5_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Dopri5 from assimulo.problem import Explicit_Problem @@ -56,7 +55,7 @@ def f(t,y): pl.show() #Basic test - assert y[-1][0] == pytest.approx(0.02695199, abs = 1e-5) + assert abs(y[-1][0] - 0.02695199) < 1e-5 return exp_mod, exp_sim diff --git a/examples/dopri5_with_disc.py b/examples/dopri5_with_disc.py index 92aa2002..8b5cac65 100644 --- a/examples/dopri5_with_disc.py +++ b/examples/dopri5_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Dopri5 from assimulo.problem import Explicit_Problem @@ -155,9 +154,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 return exp_mod, exp_sim diff --git a/examples/euler_basic.py b/examples/euler_basic.py index 86b86602..719541e5 100644 --- a/examples/euler_basic.py +++ b/examples/euler_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import ExplicitEuler from assimulo.problem import Explicit_Problem @@ -61,7 +60,7 @@ def f(t,y): pl.show() #Basic test - assert y2[-1][0] == pytest.approx(0.02628193) + assert abs(y2[-1][0] - 0.02628193) < 1e-6 return exp_mod, exp_sim diff --git a/examples/euler_vanderpol.py b/examples/euler_vanderpol.py index 84e0d488..8821ce77 100644 --- a/examples/euler_vanderpol.py +++ b/examples/euler_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import ImplicitEuler from assimulo.problem import Explicit_Problem diff --git a/examples/euler_with_disc.py b/examples/euler_with_disc.py index 3fcdb3c3..d611053c 100644 --- a/examples/euler_with_disc.py +++ b/examples/euler_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import ExplicitEuler from assimulo.problem import Explicit_Problem @@ -152,9 +151,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 return exp_mod, exp_sim diff --git a/examples/glimda_vanderpol.py b/examples/glimda_vanderpol.py index 4679af00..d3c26822 100644 --- a/examples/glimda_vanderpol.py +++ b/examples/glimda_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import GLIMDA from assimulo.problem import Implicit_Problem @@ -86,7 +85,7 @@ def f(t,y,yd): #Basic test x1 = y[:,0] - assert x1[-1] == pytest.approx(1.706168035, abs = 1e-3) + assert abs(x1[-1] - 1.706168035) < 1e-3 return imp_mod, imp_sim diff --git a/examples/ida_basic_backward.py b/examples/ida_basic_backward.py index 2c438f03..7b187318 100644 --- a/examples/ida_basic_backward.py +++ b/examples/ida_basic_backward.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem @@ -62,7 +61,7 @@ def f(t,y,yd): pl.show() #Basic test - assert y[-1][0] == pytest.approx(4.00000000, abs = 1e-3) + assert abs(y[-1][0] - 4.00000000) < 1e-3 return imp_mod, imp_sim diff --git a/examples/ida_with_disc.py b/examples/ida_with_disc.py index 1b2ce144..68134a9f 100644 --- a/examples/ida_with_disc.py +++ b/examples/ida_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem @@ -158,9 +157,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 return imp_mod, imp_sim diff --git a/examples/ida_with_initial_sensitivity.py b/examples/ida_with_initial_sensitivity.py index 7233202c..b3fecafb 100644 --- a/examples/ida_with_initial_sensitivity.py +++ b/examples/ida_with_initial_sensitivity.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem @@ -114,10 +113,10 @@ def f(t, y, yd,p): pl.show() #Basic test - assert y[-1][0] == pytest.approx(1577.6552477, abs = 1e-3) - assert y[-1][1] == pytest.approx(611.9574565, abs = 1e-3) - assert y[-1][2] == pytest.approx(2215.88563217, abs = 1e-3) - assert imp_sim.p_sol[0][1][0] == pytest.approx(1.0) + assert abs(y[-1][0] - 1577.6552477) < 1e-3 + assert abs(y[-1][1] - 611.9574565) < 1e-3 + assert abs(y[-1][2] - 2215.88563217) < 1e-3 + assert abs(imp_sim.p_sol[0][1][0] - 1.0) < 1e-6 return imp_mod, imp_sim diff --git a/examples/ida_with_jac.py b/examples/ida_with_jac.py index ac26d6a5..30521392 100644 --- a/examples/ida_with_jac.py +++ b/examples/ida_with_jac.py @@ -18,7 +18,6 @@ import numpy as np from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem -import pytest def run_example(with_plots=True): r""" @@ -107,10 +106,10 @@ def jac(c,t,y,yd): t, y, yd = imp_sim.simulate(5,1000) #Simulate 5 seconds with 1000 communication points #Basic tests - assert y[-1][0] == pytest.approx(0.9401995, abs = 1e-4) - assert y[-1][1] == pytest.approx(-0.34095124, abs = 1e-4) - assert yd[-1][0] == pytest.approx(-0.88198927, abs = 1e-4) - assert yd[-1][1] == pytest.approx(-2.43227069, abs = 1e-4) + assert abs(y[-1][0] - 0.9401995) < 1e-4 + assert abs(y[-1][1] + 0.34095124) < 1e-4 + assert abs(yd[-1][0] + 0.88198927) < 1e-4 + assert abs(yd[-1][1] - -2.43227069) < 1e-4 #Plot if with_plots: diff --git a/examples/ida_with_jac_spgmr.py b/examples/ida_with_jac_spgmr.py index fd759e56..0db02c63 100644 --- a/examples/ida_with_jac_spgmr.py +++ b/examples/ida_with_jac_spgmr.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem @@ -77,8 +76,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 - assert y[-1][0] == pytest.approx(-121.75000000, abs = 1e-4) - assert y[-1][1] == pytest.approx(-49.100000000) + assert abs(y[-1][0] + 121.75000000) < 1e-4 + assert abs(y[-1][1] + 49.100000000) < 1e-6 #Plot if with_plots: diff --git a/examples/ida_with_parameters.py b/examples/ida_with_parameters.py index 15a12e9b..87338871 100644 --- a/examples/ida_with_parameters.py +++ b/examples/ida_with_parameters.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem @@ -78,12 +77,13 @@ def f(t, y, yd, p): t, y, yd = imp_sim.simulate(4,400) #Simulate 4 seconds with 400 communication points #Basic test - assert y[-1][0] == pytest.approx(9.05518032e-01, abs = 1e-4) - assert y[-1][1] == pytest.approx(2.24046805e-05, abs = 1e-4) - assert y[-1][2] == pytest.approx(9.44595637e-02, abs = 1e-4) - assert imp_sim.p_sol[0][-1][0] == pytest.approx(-1.8761, abs = 1e-2) #Values taken from the example in Sundials - assert imp_sim.p_sol[1][-1][0] == pytest.approx(2.9614e-06, abs = 1e-8) - assert imp_sim.p_sol[2][-1][0] == pytest.approx(-4.9334e-10, abs = 1e-12) + assert abs(y[-1][0] - 9.05518032e-01) < 1e-4 + assert abs(y[-1][1] - 2.24046805e-05) < 1e-4 + assert abs(y[-1][2] - 9.44595637e-02) < 1e-4 + # Values taken from the example in Sundials + assert abs(imp_sim.p_sol[0][-1][0] + 1.8761) < 1e-2 + assert abs(imp_sim.p_sol[1][-1][0] - 2.9614e-06) < 1e-8 + assert abs(imp_sim.p_sol[2][-1][0] + 4.9334e-10) < 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 9414c412..53e567d9 100644 --- a/examples/ida_with_user_defined_handle_result.py +++ b/examples/ida_with_user_defined_handle_result.py @@ -18,7 +18,6 @@ import numpy as np from assimulo.solvers import IDA from assimulo.problem import Implicit_Problem -import pytest def run_example(with_plots=True): r""" @@ -107,11 +106,11 @@ def handle_result(solver, t ,y, yd): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(0.9401995, abs = 1e-4) - assert y[-1][1] == pytest.approx(-0.34095124, abs = 1e-4) - assert yd[-1][0] == pytest.approx(-0.88198927, abs = 1e-4) - assert yd[-1][1] == pytest.approx(-2.43227069, abs = 1e-4) - assert order[-1] == pytest.approx(5, abs = 1e-4) + assert abs(y[-1][0] - 0.9401995) < 1e-4 + assert abs(y[-1][1] + 0.34095124) < 1e-4 + assert abs(yd[-1][0] + 0.88198927) < 1e-4 + assert abs(yd[-1][1] + 2.43227069) < 1e-4 + assert abs(order[-1] - 5) < 1e-4 return imp_mod, imp_sim diff --git a/examples/kinsol_basic.py b/examples/kinsol_basic.py index d4af5d37..843797db 100644 --- a/examples/kinsol_basic.py +++ b/examples/kinsol_basic.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import pytest from assimulo.solvers import KINSOL from assimulo.problem import Algebraic_Problem @@ -46,7 +45,7 @@ def res(y): y = alg_solver.solve() #Basic test - assert y == pytest.approx(1.0, abs = 1e-5) + assert abs(y - 1.0) < 1e-5 return alg_mod, alg_solver diff --git a/examples/kinsol_ors.py b/examples/kinsol_ors.py index 3f1af66d..c7a53c1b 100644 --- a/examples/kinsol_ors.py +++ b/examples/kinsol_ors.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import os -import pytest import numpy as np import scipy.sparse as sps import scipy.sparse.linalg as spsl @@ -127,7 +126,7 @@ def setup_param(solver): #Basic test for j in range(len(y)): - assert y[j] == pytest.approx(1.0, abs = 1e-4) + assert abs(y[j] - 1.0) < 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 235de43c..f23fd54e 100644 --- a/examples/kinsol_with_jac.py +++ b/examples/kinsol_with_jac.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import KINSOL from assimulo.problem import Algebraic_Problem @@ -51,8 +50,8 @@ def jac(y): y = alg_solver.solve() #Basic test - assert y[0] == pytest.approx(1.5, abs = 1e-5) - assert y[1] == pytest.approx(1.0, abs = 1e-5) + assert abs(y[0] - 1.5) < 1e-5 + assert abs(y[1] - 1.0) < 1e-5 return alg_mod, alg_solver diff --git a/examples/lsodar_vanderpol.py b/examples/lsodar_vanderpol.py index 916a351f..d9d4bac7 100644 --- a/examples/lsodar_vanderpol.py +++ b/examples/lsodar_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import LSODAR from assimulo.problem import Explicit_Problem diff --git a/examples/lsodar_with_disc.py b/examples/lsodar_with_disc.py index 902f0463..3f46f723 100644 --- a/examples/lsodar_with_disc.py +++ b/examples/lsodar_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import LSODAR from assimulo.problem import Explicit_Problem @@ -152,9 +151,9 @@ def run_example(with_plots=True): pl.show() #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 return exp_mod, exp_sim diff --git a/examples/mech_system_pendulum.py b/examples/mech_system_pendulum.py index 19805285..afe86ddc 100644 --- a/examples/mech_system_pendulum.py +++ b/examples/mech_system_pendulum.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import pytest import numpy as np from assimulo.special_systems import Mechanical_System from assimulo.solvers import IDA, ODASSL diff --git a/examples/radau5dae_time_events.py b/examples/radau5dae_time_events.py index 0780e34b..25e339fb 100644 --- a/examples/radau5dae_time_events.py +++ b/examples/radau5dae_time_events.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Radau5DAE from assimulo.problem import Implicit_Problem diff --git a/examples/radau5dae_vanderpol.py b/examples/radau5dae_vanderpol.py index 6dec4d00..b1e2c192 100644 --- a/examples/radau5dae_vanderpol.py +++ b/examples/radau5dae_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Radau5DAE from assimulo.problem import Implicit_Problem diff --git a/examples/radau5ode_vanderpol.py b/examples/radau5ode_vanderpol.py index 577b856a..53a53c30 100644 --- a/examples/radau5ode_vanderpol.py +++ b/examples/radau5ode_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Radau5ODE from assimulo.problem import Explicit_Problem diff --git a/examples/radau5ode_with_disc.py b/examples/radau5ode_with_disc.py index 8311d413..c2e1fc50 100644 --- a/examples/radau5ode_with_disc.py +++ b/examples/radau5ode_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import Radau5ODE from assimulo.problem import Explicit_Problem @@ -134,9 +133,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 #Plot if with_plots: diff --git a/examples/radau5ode_with_disc_sparse.py b/examples/radau5ode_with_disc_sparse.py index c7b796cc..4c078f88 100644 --- a/examples/radau5ode_with_disc_sparse.py +++ b/examples/radau5ode_with_disc_sparse.py @@ -17,7 +17,6 @@ import numpy as np import scipy.sparse as sps -import pytest from assimulo.solvers import Radau5ODE from assimulo.problem import Explicit_Problem @@ -142,9 +141,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 #Plot if with_plots: diff --git a/examples/radau5ode_with_jac_sparse.py b/examples/radau5ode_with_jac_sparse.py index 00b99521..0e7c9027 100644 --- a/examples/radau5ode_with_jac_sparse.py +++ b/examples/radau5ode_with_jac_sparse.py @@ -15,7 +15,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -import pytest import numpy as np import scipy.sparse as sps from assimulo.solvers import Radau5ODE @@ -89,7 +88,7 @@ def jac(t,y): pl.show() #Basic tests - assert y[-1][0] == pytest.approx(0.9851, abs = 1e-3) + assert abs(y[-1][0] - 0.9851) < 1e-3 return exp_mod, exp_sim diff --git a/examples/rodasode_vanderpol.py b/examples/rodasode_vanderpol.py index d1ec8777..21ceb6df 100644 --- a/examples/rodasode_vanderpol.py +++ b/examples/rodasode_vanderpol.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import RodasODE from assimulo.problem import Explicit_Problem diff --git a/examples/rungekutta34_basic.py b/examples/rungekutta34_basic.py index 390368d0..c5b78929 100644 --- a/examples/rungekutta34_basic.py +++ b/examples/rungekutta34_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import RungeKutta34 from assimulo.problem import Explicit_Problem @@ -49,7 +48,7 @@ def f(t,y): t, y = exp_sim.simulate(5) #Simulate 5 seconds #Basic test - assert y[-1][0] == pytest.approx(0.02695199, abs = 1e-5) + assert abs(y[-1][0] - 0.02695199) < 1e-5 #Plot if with_plots: diff --git a/examples/rungekutta34_with_disc.py b/examples/rungekutta34_with_disc.py index 9df65b2b..d55f0b2e 100644 --- a/examples/rungekutta34_with_disc.py +++ b/examples/rungekutta34_with_disc.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import RungeKutta34 from assimulo.problem import Explicit_Problem @@ -136,9 +135,9 @@ def run_example(with_plots=True): t, y = exp_sim.simulate(10.0,1000) #Simulate 10 seconds with 1000 communications points #Basic test - assert y[-1][0] == pytest.approx(8.0) - assert y[-1][1] == pytest.approx(3.0) - assert y[-1][2] == pytest.approx(2.0) + assert abs(y[-1][0] - 8.0) < 1e-6 + assert abs(y[-1][1] - 3.0) < 1e-6 + assert abs(y[-1][2] - 2.0) < 1e-6 #Plot if with_plots: diff --git a/examples/rungekutta4_basic.py b/examples/rungekutta4_basic.py index a8e2a645..c2edcce0 100644 --- a/examples/rungekutta4_basic.py +++ b/examples/rungekutta4_basic.py @@ -16,7 +16,6 @@ # along with this program. If not, see . import numpy as np -import pytest from assimulo.solvers import RungeKutta4 from assimulo.problem import Explicit_Problem @@ -49,7 +48,7 @@ def f(t,y): t, y = exp_sim.simulate(5, 100) #Simulate 5 seconds #Basic test - assert y[-1][0] == pytest.approx(0.02695179) + assert abs(y[-1][0] - 0.02695179) < 1e-6 #Plot if with_plots: diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..316f4fd7 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = + tests diff --git a/setup.cfg b/setup.cfg index b4e39f65..cc8a2a52 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,5 +10,7 @@ install_requires = numpy >= 1.19.5 scipy >= 1.10.1 cython >= 3.0.7 - pytest >= 7.4.4 matplotlib > 3 + +tests_require = + pytest >= 7.4.4 diff --git a/setup.py b/setup.py index faccfecd..80e7a21e 100644 --- a/setup.py +++ b/setup.py @@ -186,47 +186,40 @@ def _set_directories(self): # directory paths self.curdir = os.path.dirname(os.path.abspath(__file__)) # build directories - self.build_assimulo = os.path.join("build","assimulo") - self.build_assimulo_thirdparty = os.path.join(self.build_assimulo,'thirdparty') + self.build_assimulo = os.path.join("build", "assimulo") + self.build_assimulo_thirdparty = os.path.join(self.build_assimulo, 'thirdparty') # destination directories self.desSrc = os.path.join(self.curdir,self.build_assimulo) self.desLib = os.path.join(self.desSrc,"lib") self.desSolvers = os.path.join(self.desSrc,"solvers") self.desExamples = os.path.join(self.desSrc,"examples") self.desMain = os.path.join(self.curdir,"build") - self.desTests = os.path.join(self.desSrc,"tests") - self.desTestsSolvers = os.path.join(self.desTests,"solvers") self.desThirdParty=dict([(thp,os.path.join(self.curdir,self.build_assimulo_thirdparty,thp)) for thp in self.thirdparty_methods]) - # filelists + # file lists self.fileSrc = os.listdir("src") self.fileLib = os.listdir(os.path.join("src","lib")) self.fileSolvers = os.listdir(os.path.join("src","solvers")) self.fileExamples= os.listdir("examples") self.fileMain = ["setup.py","README.md","INSTALL","CHANGELOG","MANIFEST.in"] self.fileMainIncludes = ["README.md","CHANGELOG", "LICENSE"] - self.fileTests = os.listdir("tests") self.filelist_thirdparty=dict([(thp,os.listdir(os.path.join("thirdparty",thp))) for thp in self.thirdparty_methods]) - self.fileTestsSolvers = os.listdir(os.path.join("tests","solvers")) def create_assimulo_dirs_and_populate(self): self._set_directories() for subdir in ["lib", "solvers", "examples"]: self.create_dir(os.path.join(self.build_assimulo,subdir)) - self.create_dir(os.path.join(self.build_assimulo, "tests", "solvers")) for pck in self.thirdparty_methods: self.create_dir(os.path.join(self.build_assimulo_thirdparty, pck)) self.copy_all_files(self.fileSrc, "src", self.desSrc) self.copy_all_files(self.fileLib, "src/lib", self.desLib) - self.copy_all_files(self.fileSolvers, os.path.join("src","solvers"), self.desSolvers) + self.copy_all_files(self.fileSolvers, os.path.join("src", "solvers"), self.desSolvers) self.copy_all_files(self.fileExamples, "examples", self.desExamples) self.copy_all_files(self.fileMain, None, self.desMain) self.copy_all_files(self.fileMainIncludes, None, self.desSrc) - self.copy_all_files(self.fileTests, "tests", self.desTests) - self.copy_all_files(self.fileTestsSolvers, os.path.join("tests","solvers"), self.desTestsSolvers) for f in self.filelist_thirdparty.items(): logging.debug('Thirdparty method {} file {} copied'.format(f[0],f[1])) @@ -720,7 +713,7 @@ def fortran_extensionlists(self): platforms=PLATFORMS, classifiers=CLASSIFIERS, package_dir = {'assimulo':'assimulo'}, - packages=['assimulo', 'assimulo.lib','assimulo.solvers','assimulo.examples','assimulo.tests','assimulo.tests.solvers'], + packages=['assimulo', 'assimulo.lib', 'assimulo.solvers', 'assimulo.examples'], #cmdclass = {'build_ext': build_ext}, ext_modules = ext_list, package_data={'assimulo': ['*.pxd', 'version.txt', 'CHANGELOG', 'README.md', 'LICENSE']+license_info+['examples'+os.sep+'kinsol_ors_matrix.mtx', diff --git a/tests/solvers/test_sundials.py b/tests/solvers/test_sundials.py index 2334b7b5..f5b956ed 100644 --- a/tests/solvers/test_sundials.py +++ b/tests/solvers/test_sundials.py @@ -187,8 +187,7 @@ def test_get_error_weights(self): with pytest.raises(CVodeError): self.simulator.get_error_weights() - # self.simulator.simulate(1.0) - + self.simulator.simulate(1.0) weights = self.simulator.get_error_weights() assert weights[0] < 1e6 diff --git a/tests/test_examples.py b/tests/test_examples.py index f1e266db..1a7b0f21 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -152,12 +152,13 @@ def test_mech_system_pendulum2(self): """ mech_system_pendulum.run_example('ind2',with_plots=False,with_test=True) + @pytest.mark.skipif(get_sundials_version() >= (4,), + reason = "Needs fixing for modern SUNDIALS versions") def test_mech_system_pendulum3(self): """ This tests the class Mechanical_system together with ind3 and ida """ - if get_sundials_version() < (4,): - mech_system_pendulum.run_example('ind3',with_plots=False,with_test=True) + mech_system_pendulum.run_example('ind3',with_plots=False,with_test=True) def test_mech_system_pendulum_ggl2(self): """