From 308161c80f4450f05f8399343034308bd18b4e1e Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Sun, 19 Jun 2016 14:18:35 +0200 Subject: TST: Use new warnings context manager in all tests In some places, just remove aparently unnecessary filters. After this, all cases of ignore filters should be removed from the tests, making testing (even multiple runs) normally fully predictable. --- numpy/random/tests/test_random.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'numpy/random') diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index a06de58e3..012bf4826 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -3,7 +3,8 @@ from __future__ import division, absolute_import, print_function import numpy as np from numpy.testing import ( TestCase, run_module_suite, assert_, assert_raises, assert_equal, - assert_warns, assert_array_equal, assert_array_almost_equal) + assert_warns, assert_array_equal, assert_array_almost_equal, + suppress_warnings) from numpy import random from numpy.compat import asbytes import sys @@ -260,13 +261,14 @@ class TestRandomDist(TestCase): def test_random_integers(self): np.random.seed(self.seed) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) + with suppress_warnings() as sup: + w = sup.record(DeprecationWarning) actual = np.random.random_integers(-99, 99, size=(3, 2)) - desired = np.array([[31, 3], - [-52, 41], - [-48, -66]]) - assert_array_equal(actual, desired) + assert_(len(w) == 1) + desired = np.array([[31, 3], + [-52, 41], + [-48, -66]]) + assert_array_equal(actual, desired) def test_random_integers_max_int(self): # Tests whether random_integers can generate the @@ -274,12 +276,14 @@ class TestRandomDist(TestCase): # into a C long. Previous implementations of this # method have thrown an OverflowError when attempting # to generate this integer. - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) + with suppress_warnings() as sup: + w = sup.record(DeprecationWarning) actual = np.random.random_integers(np.iinfo('l').max, np.iinfo('l').max) - desired = np.iinfo('l').max - assert_equal(actual, desired) + assert_(len(w) == 1) + + desired = np.iinfo('l').max + assert_equal(actual, desired) def test_random_integers_deprecated(self): with warnings.catch_warnings(): -- cgit v1.2.1