diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2016-06-19 14:18:35 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2016-09-02 10:10:55 +0200 |
commit | 308161c80f4450f05f8399343034308bd18b4e1e (patch) | |
tree | ba3778d778e1222e93246ca7842e8f060e411173 /numpy/random/tests/test_random.py | |
parent | c1ddf841f6a48248b946a990ae750505b8b91686 (diff) | |
download | numpy-308161c80f4450f05f8399343034308bd18b4e1e.tar.gz |
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.
Diffstat (limited to 'numpy/random/tests/test_random.py')
-rw-r--r-- | numpy/random/tests/test_random.py | 26 |
1 files changed, 15 insertions, 11 deletions
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(): |