From d664f5fea4ff30f960c858915872c49d793b8d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Justus=20Sagem=C3=BCller?= Date: Mon, 12 Aug 2024 16:44:19 +0200 Subject: [PATCH] NumPy changed what exception is raised for ufunc-call with wrong number of arguments. The ODL tests checked against the previously raised `ValueError`, but in newer versions `TypeError` is raised instead, which these tests could not handle. --- odl/test/discr/discr_space_test.py | 6 ++++-- odl/test/space/tensors_test.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/odl/test/discr/discr_space_test.py b/odl/test/discr/discr_space_test.py index 8c8a89820ba..69c6ac7fee7 100644 --- a/odl/test/discr/discr_space_test.py +++ b/odl/test/discr/discr_space_test.py @@ -907,7 +907,9 @@ def test_ufunc_corner_cases(odl_tspace_impl): # --- UFuncs with nin = 1, nout = 1 --- # - with pytest.raises(ValueError): + wrong_argcount_error = ValueError if np.__version__<"1.21" else TypeError + + with pytest.raises(wrong_argcount_error): # Too many arguments x.__array_ufunc__(np.sin, '__call__', x, np.ones((2, 3))) @@ -938,7 +940,7 @@ def test_ufunc_corner_cases(odl_tspace_impl): # --- UFuncs with nin = 2, nout = 1 --- # - with pytest.raises(ValueError): + with pytest.raises(wrong_argcount_error): # Too few arguments x.__array_ufunc__(np.add, '__call__', x) diff --git a/odl/test/space/tensors_test.py b/odl/test/space/tensors_test.py index 2e1d751ff97..21cbf5e14bc 100644 --- a/odl/test/space/tensors_test.py +++ b/odl/test/space/tensors_test.py @@ -1542,7 +1542,9 @@ def test_ufunc_corner_cases(odl_tspace_impl): # --- Ufuncs with nin = 1, nout = 1 --- # - with pytest.raises(ValueError): + wrong_argcount_error = ValueError if np.__version__<"1.21" else TypeError + + with pytest.raises(wrong_argcount_error): # Too many arguments x.__array_ufunc__(np.sin, '__call__', x, np.ones((2, 3))) @@ -1573,7 +1575,7 @@ def test_ufunc_corner_cases(odl_tspace_impl): # --- Ufuncs with nin = 2, nout = 1 --- # - with pytest.raises(ValueError): + with pytest.raises(wrong_argcount_error): # Too few arguments x.__array_ufunc__(np.add, '__call__', x)