From d09e192f05fae7d2e13735c82714b0bc140a0d9f Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 2 Sep 2020 16:43:40 +0300 Subject: MAINT: Remove old sys.version_info code --- numpy/testing/tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 6a6cc664a..c3b9e04b6 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1240,7 +1240,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None): if sys.version_info[:2] >= (3, 7): if py37 is not None: n_in_context = py37 - elif sys.version_info[:2] >= (3, 4): + else: if py34 is not None: n_in_context = py34 assert_equal(num_warns, n_in_context) -- cgit v1.2.1 From bcb168a56d1c47b877568ce51ce90a1ced89f007 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 4 Feb 2021 14:16:52 -0600 Subject: BUG: Allow unmodified use of isclose, allclose, etc. with timedelta Disallowing timedelta64+float promotion (to timedelta64) in all cases (previously it was assymetric and "half allowed") meant that isclose, allclose, np.ma.allclose, and assert_arrays_almost_equal (which uses isclose), would stop work for timedelta64. Hardcoding that timedelta64 is passed on unmodified retains the old behaviour. It may make sense to deprecate or change this behaviour in the future, but for the 1.20 release, the behaviour should be as much unmodified as possible. Closes gh-18286 --- numpy/testing/tests/test_utils.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index c3b9e04b6..261ed9705 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -904,6 +904,11 @@ class TestAssertAllclose: msg = str(exc_info.value) assert_('Max relative difference: 0.5' in msg) + def test_timedelta(self): + # see gh-18286 + a = np.array([[1, 2, 3, "NaT"]], dtype="m8[ns]") + assert_allclose(a, a) + class TestArrayAlmostEqualNulp: -- cgit v1.2.1 From c1aa1af62f6e9fcdda92d6d0991b15051a565814 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 19 Mar 2021 22:03:06 +1300 Subject: MAINT: use super() as described by PEP 3135 --- numpy/testing/tests/test_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 261ed9705..31d2cdc76 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -434,10 +434,10 @@ class TestArrayAlmostEqual(_GenericTest): # (which, e.g., astropy Quantity cannot usefully do). See gh-8452. class MyArray(np.ndarray): def __eq__(self, other): - return super(MyArray, self).__eq__(other).view(np.ndarray) + return super().__eq__(other).view(np.ndarray) def __lt__(self, other): - return super(MyArray, self).__lt__(other).view(np.ndarray) + return super().__lt__(other).view(np.ndarray) def all(self, *args, **kwargs): raise NotImplementedError @@ -585,10 +585,10 @@ class TestAlmostEqual(_GenericTest): # (which, e.g., astropy Quantity cannot usefully do). See gh-8452. class MyArray(np.ndarray): def __eq__(self, other): - return super(MyArray, self).__eq__(other).view(np.ndarray) + return super().__eq__(other).view(np.ndarray) def __lt__(self, other): - return super(MyArray, self).__lt__(other).view(np.ndarray) + return super().__lt__(other).view(np.ndarray) def all(self, *args, **kwargs): raise NotImplementedError -- cgit v1.2.1 From f69ddd7111048111a7e486a2d7d008bd231af33d Mon Sep 17 00:00:00 2001 From: Simon Surland Andersen Date: Tue, 8 Feb 2022 14:43:36 +0100 Subject: ENH: Suppress over-/underflow RuntimeWarning in assert_array_equal (#21003) * TST: Test suppression of asset_array_equal RuntimeWarning See #18992 * ENH: Suppress over-/underflow warnings on asset_array_equal - Closes #18992 * MAINT: Resolve linting issues of prior commit * MAINT: Simplified ignore and test case of asset_array_equal * MAINT: Removed unused import in test_utils.py --- numpy/testing/tests/test_utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 31d2cdc76..919ca751f 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -207,6 +207,14 @@ class TestArrayEqual(_GenericTest): self._test_not_equal(a, b) self._test_not_equal(b, a) + def test_suppress_overflow_warnings(self): + # Based on issue #18992 + with pytest.raises(AssertionError): + with np.errstate(all="raise"): + np.testing.assert_array_equal( + np.array([1, 2, 3], np.float32), + np.array([1, 1e-40, 3], np.float32)) + class TestBuildErrorMessage: -- cgit v1.2.1 From a0c2e826738daa0cbd83aba85852405b73878f5b Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Fri, 11 Jun 2021 18:21:54 -0500 Subject: API: Fix structured dtype cast-safety, promotion, and comparison This PR replaces the old gh-15509 implementing proper type promotion for structured voids. It further fixes the casting safety to consider casts with equivalent field number and matching order as "safe" and if the names, titles, and offsets match as "equiv". The change perculates into the void comparison, and since it fixes the order, it removes the current FutureWarning there as well. This addresses https://github.com/liberfa/pyerfa/issues/77 and replaces gh-15509 (the implementation has changed too much). Fixes gh-15494 (and probably a few more) Co-authored-by: Allan Haldane --- numpy/testing/tests/test_utils.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 919ca751f..bbc04124f 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -151,14 +151,13 @@ class TestArrayEqual(_GenericTest): self._test_equal(a, b) - c = np.empty(2, [('floupipi', float), ('floupa', float)]) + c = np.empty(2, [('floupipi', float), + ('floupi', float), ('floupa', float)]) c['floupipi'] = a['floupi'].copy() c['floupa'] = a['floupa'].copy() - with suppress_warnings() as sup: - l = sup.record(FutureWarning, message="elementwise == ") + with pytest.raises(TypeError): self._test_not_equal(c, b) - assert_equal(len(l), 1) def test_masked_nan_inf(self): # Regression test for gh-11121 -- cgit v1.2.1 From 497dc9402d04754b512e344c8039caafd55351da Mon Sep 17 00:00:00 2001 From: Brigitta Sipocz Date: Sun, 12 Jul 2020 13:50:02 -0700 Subject: Remove python <3.6 related things --- numpy/testing/tests/test_utils.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 919ca751f..1aaa8f559 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -212,7 +212,7 @@ class TestArrayEqual(_GenericTest): with pytest.raises(AssertionError): with np.errstate(all="raise"): np.testing.assert_array_equal( - np.array([1, 2, 3], np.float32), + np.array([1, 2, 3], np.float32), np.array([1, 1e-40, 3], np.float32)) @@ -1224,7 +1224,7 @@ class TestStringEqual: lambda: assert_string_equal("aaa", "a+b")) -def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None): +def assert_warn_len_equal(mod, n_in_context, py37=None): try: mod_warns = mod.__warningregistry__ except AttributeError: @@ -1238,10 +1238,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None): mod_warns = {} num_warns = len(mod_warns) - # Python 3.4 appears to clear any pre-existing warnings of the same type, - # when raising warnings inside a catch_warnings block. So, there is a - # warning generated by the tests within the context manager, but no - # previous warnings. + if 'version' in mod_warns: # Python 3 adds a 'version' entry to the registry, # do not count it. @@ -1253,9 +1250,7 @@ def assert_warn_len_equal(mod, n_in_context, py34=None, py37=None): if sys.version_info[:2] >= (3, 7): if py37 is not None: n_in_context = py37 - else: - if py34 is not None: - n_in_context = py34 + assert_equal(num_warns, n_in_context) def test_warn_len_equal_call_scenarios(): @@ -1318,12 +1313,11 @@ def test_clear_and_catch_warnings(): warnings.warn('Another warning') assert_warn_len_equal(my_mod, 1, py37=0) # Another warning, no module spec does add to warnings dict, except on - # Python 3.4 (see comments in `assert_warn_len_equal`) # Python 3.7 catch_warnings doesn't make an entry for 'ignore'. with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Another warning') - assert_warn_len_equal(my_mod, 2, py34=1, py37=0) + assert_warn_len_equal(my_mod, 2, py37=0) def test_suppress_warnings_module(): -- cgit v1.2.1 From 53379cd353fb7ab5840c3ee370c735fe61d6419c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sipo=CC=8Bcz?= Date: Fri, 20 May 2022 18:32:55 -0700 Subject: MAINT: Python <3.7 related cleanups --- numpy/testing/tests/test_utils.py | 7 ------- 1 file changed, 7 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 4026a7a14..2af0467f1 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1243,13 +1243,6 @@ def assert_warn_len_equal(mod, n_in_context, py37=None): # do not count it. num_warns -= 1 - # Behavior of warnings is Python version dependent. Adjust the - # expected result to compensate. In particular, Python 3.7 does - # not make an entry for ignored warnings. - if sys.version_info[:2] >= (3, 7): - if py37 is not None: - n_in_context = py37 - assert_equal(num_warns, n_in_context) def test_warn_len_equal_call_scenarios(): -- cgit v1.2.1 From d4d5771e17c14ce8cdeaf2922d537006dd3fcebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Fri, 20 May 2022 18:34:06 -0700 Subject: MAINT: Python <3.8 related cleanups --- numpy/testing/tests/test_utils.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 2af0467f1..7b326365d 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1223,7 +1223,7 @@ class TestStringEqual: lambda: assert_string_equal("aaa", "a+b")) -def assert_warn_len_equal(mod, n_in_context, py37=None): +def assert_warn_len_equal(mod, n_in_context): try: mod_warns = mod.__warningregistry__ except AttributeError: @@ -1245,6 +1245,7 @@ def assert_warn_len_equal(mod, n_in_context, py37=None): assert_equal(num_warns, n_in_context) + def test_warn_len_equal_call_scenarios(): # assert_warn_len_equal is called under # varying circumstances depending on serial @@ -1294,22 +1295,20 @@ def test_clear_and_catch_warnings(): warnings.warn('Some warning') assert_equal(my_mod.__warningregistry__, {}) # Without specified modules, don't clear warnings during context - # Python 3.7 catch_warnings doesn't make an entry for 'ignore'. with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1, py37=0) + assert_warn_len_equal(my_mod, 1) # Confirm that specifying module keeps old warning, does not add new with clear_and_catch_warnings(modules=[my_mod]): warnings.simplefilter('ignore') warnings.warn('Another warning') - assert_warn_len_equal(my_mod, 1, py37=0) + assert_warn_len_equal(my_mod, 1) # Another warning, no module spec does add to warnings dict, except on - # Python 3.7 catch_warnings doesn't make an entry for 'ignore'. with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Another warning') - assert_warn_len_equal(my_mod, 2, py37=0) + assert_warn_len_equal(my_mod, 2) def test_suppress_warnings_module(): @@ -1338,7 +1337,7 @@ def test_suppress_warnings_module(): # got filtered) assert_equal(len(sup.log), 1) assert_equal(sup.log[0].message.args[0], "Some warning") - assert_warn_len_equal(my_mod, 0, py37=0) + assert_warn_len_equal(my_mod, 0) sup = suppress_warnings() # Will have to be changed if apply_along_axis is moved: sup.filter(module=my_mod) @@ -1352,11 +1351,11 @@ def test_suppress_warnings_module(): assert_warn_len_equal(my_mod, 0) # Without specified modules, don't clear warnings during context - # Python 3.7 does not add ignored warnings. with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1, py37=0) + assert_warn_len_equal(my_mod, 1) + def test_suppress_warnings_type(): # Initial state of module, no warnings @@ -1380,11 +1379,10 @@ def test_suppress_warnings_type(): assert_warn_len_equal(my_mod, 0) # Without specified modules, don't clear warnings during context - # Python 3.7 does not add ignored warnings. with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1, py37=0) + assert_warn_len_equal(my_mod, 1) def test_suppress_warnings_decorate_no_record(): -- cgit v1.2.1 From e8dda96dd2a50d2e23134d924cbcabd545af54a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Fri, 20 May 2022 19:47:26 -0700 Subject: MAINT: Fix warningc context tests, uncover bug? --- numpy/testing/tests/test_utils.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 7b326365d..6fa51454f 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1294,17 +1294,23 @@ def test_clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') assert_equal(my_mod.__warningregistry__, {}) - # Without specified modules, don't clear warnings during context + # Without specified modules, don't clear warnings during context. + # catch_warnings doesn't make an entry for 'ignore'. with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1) + assert_warn_len_equal(my_mod, 0) + + # Manually adding two warnings to the registry: + my_mod.__warningregistry__ = {'warning1': 1, + 'warning2': 2} + # Confirm that specifying module keeps old warning, does not add new with clear_and_catch_warnings(modules=[my_mod]): warnings.simplefilter('ignore') warnings.warn('Another warning') - assert_warn_len_equal(my_mod, 1) - # Another warning, no module spec does add to warnings dict, except on + assert_warn_len_equal(my_mod, 2) + # Another warning, no module spec does add to warnings dict with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Another warning') @@ -1350,11 +1356,15 @@ def test_suppress_warnings_module(): warnings.warn('Some warning') assert_warn_len_equal(my_mod, 0) + # Manually adding two warnings to the registry: + my_mod.__warningregistry__ = {'warning1': 1, + 'warning2': 2} + # Without specified modules, don't clear warnings during context with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1) + assert_warn_len_equal(my_mod, 2) def test_suppress_warnings_type(): @@ -1378,11 +1388,15 @@ def test_suppress_warnings_type(): warnings.warn('Some warning') assert_warn_len_equal(my_mod, 0) + # Manually adding two warnings to the registry: + my_mod.__warningregistry__ = {'warning1': 1, + 'warning2': 2} + # Without specified modules, don't clear warnings during context with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 1) + assert_warn_len_equal(my_mod, 2) def test_suppress_warnings_decorate_no_record(): -- cgit v1.2.1 From ac40c2ea38021ee57a8c6261cfc9b792bc51970b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brigitta=20Sip=C5=91cz?= Date: Fri, 20 May 2022 20:45:54 -0700 Subject: MAINT: revert changes, so all tests pass for warning contexts --- numpy/testing/tests/test_utils.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 6fa51454f..49eeecc8e 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -1310,11 +1310,12 @@ def test_clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Another warning') assert_warn_len_equal(my_mod, 2) - # Another warning, no module spec does add to warnings dict + + # Another warning, no module spec it clears up registry with clear_and_catch_warnings(): warnings.simplefilter('ignore') warnings.warn('Another warning') - assert_warn_len_equal(my_mod, 2) + assert_warn_len_equal(my_mod, 0) def test_suppress_warnings_module(): @@ -1356,15 +1357,11 @@ def test_suppress_warnings_module(): warnings.warn('Some warning') assert_warn_len_equal(my_mod, 0) - # Manually adding two warnings to the registry: - my_mod.__warningregistry__ = {'warning1': 1, - 'warning2': 2} - - # Without specified modules, don't clear warnings during context + # Without specified modules with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 2) + assert_warn_len_equal(my_mod, 0) def test_suppress_warnings_type(): @@ -1388,15 +1385,11 @@ def test_suppress_warnings_type(): warnings.warn('Some warning') assert_warn_len_equal(my_mod, 0) - # Manually adding two warnings to the registry: - my_mod.__warningregistry__ = {'warning1': 1, - 'warning2': 2} - - # Without specified modules, don't clear warnings during context + # Without specified modules with suppress_warnings(): warnings.simplefilter('ignore') warnings.warn('Some warning') - assert_warn_len_equal(my_mod, 2) + assert_warn_len_equal(my_mod, 0) def test_suppress_warnings_decorate_no_record(): -- cgit v1.2.1 From cafec60a5e28af98fb8798049edd7942720d2d74 Mon Sep 17 00:00:00 2001 From: Jon Morris Date: Fri, 24 Jun 2022 16:51:36 +0100 Subject: ENH: Add strict parameter to assert_array_equal. (#21595) Fixes #9542 Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com> --- numpy/testing/tests/test_utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 49eeecc8e..c82343f0c 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -214,6 +214,43 @@ class TestArrayEqual(_GenericTest): np.array([1, 2, 3], np.float32), np.array([1, 1e-40, 3], np.float32)) + def test_array_vs_scalar_is_equal(self): + """Test comparing an array with a scalar when all values are equal.""" + a = np.array([1., 1., 1.]) + b = 1. + + self._test_equal(a, b) + + def test_array_vs_scalar_not_equal(self): + """Test comparing an array with a scalar when not all values equal.""" + a = np.array([1., 2., 3.]) + b = 1. + + self._test_not_equal(a, b) + + def test_array_vs_scalar_strict(self): + """Test comparing an array with a scalar with strict option.""" + a = np.array([1., 1., 1.]) + b = 1. + + with pytest.raises(AssertionError): + assert_array_equal(a, b, strict=True) + + def test_array_vs_array_strict(self): + """Test comparing two arrays with strict option.""" + a = np.array([1., 1., 1.]) + b = np.array([1., 1., 1.]) + + assert_array_equal(a, b, strict=True) + + def test_array_vs_float_array_strict(self): + """Test comparing two arrays with strict option.""" + a = np.array([1, 1, 1]) + b = np.array([1., 1., 1.]) + + with pytest.raises(AssertionError): + assert_array_equal(a, b, strict=True) + class TestBuildErrorMessage: -- cgit v1.2.1 From 57d04d883e874c611091933c4c36e1cd43ea0e04 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Wed, 29 Jun 2022 20:05:19 -0400 Subject: TST: Add a failing test case to demonstrate the bug gh2176 --- numpy/testing/tests/test_utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 49eeecc8e..da3c4f80b 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -916,6 +916,20 @@ class TestAssertAllclose: a = np.array([[1, 2, 3, "NaT"]], dtype="m8[ns]") assert_allclose(a, a) + def test_error_message_unsigned(self): + """Check the the message is formatted correctly when overflow can occur + (gh21768)""" + # Ensure to test for potential overflow in the case of: + # x - y + # and + # y - x + x = np.asarray([0, 1, 8], dtype='uint8') + y = np.asarray([4, 4, 4], dtype='uint8') + with pytest.raises(AssertionError) as exc_info: + assert_allclose(x, y, atol=3) + msgs = str(exc_info.value).split('\n') + assert_equal(msgs[4], 'Max absolute difference: 4') + class TestArrayAlmostEqualNulp: -- cgit v1.2.1 From 67841947b458f6bdc6c40d014512da9bc4717a3e Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 27 Oct 2022 14:57:14 +0200 Subject: TST,MAINT: Replace most `setup` with `setup_method` (also teardown) In some cases, the replacement is clearly not what is intended, in those (where setup was called explicitly), I mostly renamed `setup` to `_setup`. The `test_ccompile_opt` is a bit confusing, so left it right now (this will probably fail) --- numpy/testing/tests/test_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 377f570bd..052cc3aa1 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -65,7 +65,7 @@ class _GenericTest: class TestArrayEqual(_GenericTest): - def setup(self): + def setup_method(self): self._assert_func = assert_array_equal def test_generic_rank1(self): @@ -299,7 +299,7 @@ class TestBuildErrorMessage: class TestEqual(TestArrayEqual): - def setup(self): + def setup_method(self): self._assert_func = assert_equal def test_nan_items(self): @@ -394,7 +394,7 @@ class TestEqual(TestArrayEqual): class TestArrayAlmostEqual(_GenericTest): - def setup(self): + def setup_method(self): self._assert_func = assert_array_almost_equal def test_closeness(self): @@ -492,7 +492,7 @@ class TestArrayAlmostEqual(_GenericTest): class TestAlmostEqual(_GenericTest): - def setup(self): + def setup_method(self): self._assert_func = assert_almost_equal def test_closeness(self): @@ -643,7 +643,7 @@ class TestAlmostEqual(_GenericTest): class TestApproxEqual: - def setup(self): + def setup_method(self): self._assert_func = assert_approx_equal def test_simple_0d_arrays(self): @@ -686,7 +686,7 @@ class TestApproxEqual: class TestArrayAssertLess: - def setup(self): + def setup_method(self): self._assert_func = assert_array_less def test_simple_arrays(self): @@ -796,7 +796,7 @@ class TestArrayAssertLess: @pytest.mark.skip(reason="The raises decorator depends on Nose") class TestRaises: - def setup(self): + def setup_method(self): class MyException(Exception): pass -- cgit v1.2.1 From f75bb0edb0e6eec2564de4bf798242984860a19b Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 18 Jan 2023 17:04:13 -0700 Subject: MAINT: Remove all nose testing support. NumPy switched to using pytest in 2018 and nose has been unmaintained for many years. We have kept NumPy's nose support to avoid breaking downstream projects who might have been using it and not yet switched to pytest or some other testing framework. With the arrival of Python 3.12, unpatched nose will raise an error. It it time to move on. Decorators removed - raises - slow - setastest - skipif - knownfailif - deprecated - parametrize - _needs_refcount These are not to be confused with pytest versions with similar names, e.g., pytest.mark.slow, pytest.mark.skipif, pytest.mark.parametrize. Functions removed - Tester - import_nose - run_module_suite --- numpy/testing/tests/test_utils.py | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 052cc3aa1..8f4912fab 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -8,7 +8,7 @@ import weakref import numpy as np from numpy.testing import ( assert_equal, assert_array_equal, assert_almost_equal, - assert_array_almost_equal, assert_array_less, build_err_msg, raises, + assert_array_almost_equal, assert_array_less, build_err_msg, assert_raises, assert_warns, assert_no_warnings, assert_allclose, assert_approx_equal, assert_array_almost_equal_nulp, assert_array_max_ulp, clear_and_catch_warnings, suppress_warnings, assert_string_equal, assert_, @@ -793,41 +793,6 @@ class TestArrayAssertLess: self._assert_func(-ainf, x) -@pytest.mark.skip(reason="The raises decorator depends on Nose") -class TestRaises: - - def setup_method(self): - class MyException(Exception): - pass - - self.e = MyException - - def raises_exception(self, e): - raise e - - def does_not_raise_exception(self): - pass - - def test_correct_catch(self): - raises(self.e)(self.raises_exception)(self.e) # raises? - - def test_wrong_exception(self): - try: - raises(self.e)(self.raises_exception)(RuntimeError) # raises? - except RuntimeError: - return - else: - raise AssertionError("should have caught RuntimeError") - - def test_catch_no_raise(self): - try: - raises(self.e)(self.does_not_raise_exception)() # raises? - except AssertionError: - return - else: - raise AssertionError("should have raised an AssertionError") - - class TestWarns: def test_warn(self): -- cgit v1.2.1 From 1da1663196c95b3811ca84d9e335f32cfeb05e32 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Sun, 12 Mar 2023 22:01:22 +0000 Subject: MAINT: remove `NUMPY_EXPERIMENTAL_ARRAY_FUNCTION` env var As discussed in https://mail.python.org/archives/list/numpy-discussion@python.org/thread/UKZJACAP5FUG7KP2AQDPE4P5ADNWLOHZ/ This flag was always meant to be temporary, and cleaning it up is long overdue. --- numpy/testing/tests/test_utils.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'numpy/testing/tests/test_utils.py') diff --git a/numpy/testing/tests/test_utils.py b/numpy/testing/tests/test_utils.py index 8f4912fab..0aaa508ee 100644 --- a/numpy/testing/tests/test_utils.py +++ b/numpy/testing/tests/test_utils.py @@ -14,7 +14,6 @@ from numpy.testing import ( clear_and_catch_warnings, suppress_warnings, assert_string_equal, assert_, tempdir, temppath, assert_no_gc_cycles, HAS_REFCOUNT ) -from numpy.core.overrides import ARRAY_FUNCTION_ENABLED class _GenericTest: @@ -191,8 +190,6 @@ class TestArrayEqual(_GenericTest): self._test_not_equal(a, b) self._test_not_equal(b, a) - @pytest.mark.skipif( - not ARRAY_FUNCTION_ENABLED, reason='requires __array_function__') def test_subclass_that_does_not_implement_npall(self): class MyArray(np.ndarray): def __array_function__(self, *args, **kwargs): -- cgit v1.2.1