summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2012-02-08 19:51:45 -0800
committerMark Wiebe <mwwiebe@gmail.com>2012-02-08 19:51:45 -0800
commita2bb1cc9b6fc37583494d9a3e14b0ace59d210a5 (patch)
tree105ce1da1f9e24933d86bcd5cbf5a05cbc445f17 /numpy/ma
parentc8c2082755457f4c16b0af7e1ca091dbb690341d (diff)
downloadnumpy-a2bb1cc9b6fc37583494d9a3e14b0ace59d210a5.tar.gz
BUG: Fix improper usage of warning filters in the tests
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/tests/test_core.py11
-rw-r--r--numpy/ma/tests/test_mrecords.py17
2 files changed, 20 insertions, 8 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 95219beb1..f4ec54dc4 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -18,6 +18,7 @@ import numpy.ma.core
from numpy.ma.core import *
from numpy.compat import asbytes, asbytes_nested
+from numpy.testing.utils import WarningManager
pi = np.pi
@@ -426,9 +427,13 @@ class TestMaskedArray(TestCase):
assert_equal(1.0, float(array([[1]])))
self.assertRaises(TypeError, float, array([1, 1]))
#
- warnings.simplefilter('ignore', UserWarning)
- assert_(np.isnan(float(array([1], mask=[1]))))
- warnings.simplefilter('default', UserWarning)
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
+ try:
+ warnings.simplefilter('ignore', UserWarning)
+ assert_(np.isnan(float(array([1], mask=[1]))))
+ finally:
+ warn_ctx.__exit__()
#
a = array([1, 2, 3], mask=[1, 0, 0])
self.assertRaises(TypeError, lambda:float(a))
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index a6ee33b72..1e14042b0 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -22,6 +22,9 @@ from numpy.ma.testutils import *
import numpy.ma as ma
from numpy.ma import masked, nomask
+import warnings
+from numpy.testing.utils import WarningManager
+
from numpy.ma.mrecords import MaskedRecords, mrecarray, fromarrays, \
fromtextfile, fromrecords, addfield
@@ -136,11 +139,15 @@ class TestMRecords(TestCase):
rdata = data.view(MaskedRecords)
val = ma.array([10,20,30], mask=[1,0,0])
#
- import warnings
- warnings.simplefilter("ignore")
- rdata['num'] = val
- assert_equal(rdata.num, val)
- assert_equal(rdata.num.mask, [1,0,0])
+ warn_ctx = WarningManager()
+ warn_ctx.__enter__()
+ try:
+ warnings.simplefilter("ignore")
+ rdata['num'] = val
+ assert_equal(rdata.num, val)
+ assert_equal(rdata.num.mask, [1,0,0])
+ finally:
+ warn_ctx.__exit__()
def test_set_fields_mask(self):
"Tests setting the mask of a field."