Skip to content

Commit 0d03620

Browse files
authored
Prettify array assertion failure messages (#3117)
1 parent 33241c7 commit 0d03620

4 files changed

Lines changed: 18 additions & 14 deletions

File tree

python/tests/adapters/test_fiddy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from fiddy import MethodId, Type, get_derivative
1616
from fiddy.derivative_check import NumpyIsCloseDerivativeCheck
1717
from fiddy.success import Consistency
18+
from numpy.testing import assert_allclose
1819
from petab import v1
1920

2021
# Absolute and relative tolerances for finite difference gradient checks.
@@ -85,13 +86,13 @@ def test_run_amici_simulation_to_functions(problem_generator):
8586
test_derivative = derivative.value
8687

8788
# The test derivative is close to the expected derivative.
88-
assert np.isclose(
89+
assert_allclose(
8990
test_derivative,
9091
expected_derivative,
9192
rtol=1e-1,
9293
atol=1e-1,
9394
equal_nan=True,
94-
).all()
95+
)
9596

9697
# Same as above assert.
9798
check = NumpyIsCloseDerivativeCheck(

python/tests/test_bngl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from amici.importers.bngl import bngl2amici
1212
from amici.sim.sundials import run_simulation
1313
from amici.testing import TemporaryDirectoryWinSafe, skip_on_valgrind
14+
from numpy.testing import assert_allclose
1415
from pysb.importers.bngl import model_from_bngl
1516
from pysb.simulator import ScipyOdeSimulator
1617

@@ -113,4 +114,4 @@ def test_compare_to_pysb_simulation(example):
113114
rdata = run_simulation(model_amici, solver)
114115

115116
# check agreement of species simulation
116-
assert np.isclose(rdata.x, pysb_simres.species, 1e-4, 1e-4).all()
117+
assert_allclose(rdata.x, pysb_simres.species, 1e-4, 1e-4)

python/tests/test_edata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
run_simulation,
1111
)
1212
from amici.testing import skip_on_valgrind
13+
from numpy.testing import assert_allclose
1314

1415

1516
@skip_on_valgrind
@@ -51,5 +52,5 @@ def test_edata_sensi_unscaling(model_units_module): # noqa: F811
5152
rdata1 = run_simulation(model, solver, edata1)
5253

5354
# The initial state sensitivities are as specified.
54-
assert np.isclose(rdata0.sx0.flatten(), sx0).all()
55-
assert np.isclose(rdata1.sx0.flatten(), sx0).all()
55+
assert_allclose(rdata0.sx0.flatten(), sx0)
56+
assert_allclose(rdata1.sx0.flatten(), sx0)

python/tests/test_pysb.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,32 @@ def test_compare_to_sbml_import(
5757
[rdata_sbml, rdata_pysb], [model_sbml, model_pysb], ["sbml", "pysb"]
5858
):
5959
# check equilibrium fixed parameters
60-
assert np.isclose(
60+
assert_allclose(
6161
[sum(rdata["x_ss"][[1, 3]]), sum(rdata["x_ss"][[2, 4]])],
6262
edata.fixed_parameters_pre_equilibration,
6363
atol=1e-6,
6464
rtol=1e-6,
65-
).all(), f"{importer} preequilibration"
65+
err_msg=f"{importer} preequilibration",
66+
)
6667

6768
# check equilibrium initial parameters
68-
assert np.isclose(
69+
assert_allclose(
6970
sum(rdata["x_ss"][[0, 3, 4, 5]]),
7071
model.get_free_parameter_by_name("PROT_0"),
7172
atol=1e-6,
7273
rtol=1e-6,
73-
), f"{importer} preequilibration"
74+
err_msg=f"{importer} preequilibration",
75+
)
7476

7577
# check reinitialization with fixed parameter after
7678
# presimulation
77-
assert np.isclose(
79+
assert_allclose(
7880
[rdata["x0"][1], rdata["x0"][2]],
7981
edata.fixed_parameters,
8082
atol=1e-6,
8183
rtol=1e-6,
82-
).all(), f"{importer} presimulation"
84+
err_msg=f"{importer} presimulation",
85+
)
8386

8487
skip_attrs = [
8588
"ptr",
@@ -216,9 +219,7 @@ def test_compare_to_pysb_simulation(example):
216219
rdata = run_simulation(model_pysb, solver)
217220

218221
# check agreement of species simulations
219-
assert np.isclose(
220-
rdata["x"], pysb_simres.species, 1e-4, 1e-4
221-
).all()
222+
assert_allclose(rdata["x"], pysb_simres.species, 1e-4, 1e-4)
222223

223224
if example not in [
224225
"fricker_2010_apoptosis",

0 commit comments

Comments
 (0)