[Numpy-svn] r8246 - trunk/numpy/lib/tests

numpy-svn@scip... numpy-svn@scip...
Sun Feb 21 12:31:55 CST 2010


Author: charris
Date: 2010-02-21 12:31:55 -0600 (Sun, 21 Feb 2010)
New Revision: 8246

Modified:
   trunk/numpy/lib/tests/test_type_check.py
Log:
BUG: Fix possibly unbalanced seterr pairs. Fixes change in state of invalid
after running test().

Modified: trunk/numpy/lib/tests/test_type_check.py
===================================================================
--- trunk/numpy/lib/tests/test_type_check.py	2010-02-21 16:16:40 UTC (rev 8245)
+++ trunk/numpy/lib/tests/test_type_check.py	2010-02-21 18:31:55 UTC (rev 8246)
@@ -69,7 +69,9 @@
         #assert_equal(mintypecode('idF',savespace=1),'F')
         assert_equal(mintypecode('idD'),'D')
 
+
 class TestIsscalar(TestCase):
+
     def test_basic(self):
         assert(isscalar(3))
         assert(not isscalar([3]))
@@ -78,7 +80,9 @@
         assert(isscalar(10L))
         assert(isscalar(4.0))
 
+
 class TestReal(TestCase):
+
     def test_real(self):
         y = rand(10,)
         assert_array_equal(y,real(y))
@@ -87,7 +91,9 @@
         y = rand(10,)+1j*rand(10,)
         assert_array_equal(y.real,real(y))
 
+
 class TestImag(TestCase):
+
     def test_real(self):
         y = rand(10,)
         assert_array_equal(0,imag(y))
@@ -96,7 +102,9 @@
         y = rand(10,)+1j*rand(10,)
         assert_array_equal(y.imag,imag(y))
 
+
 class TestIscomplex(TestCase):
+
     def test_fail(self):
         z = array([-1,0,1])
         res = iscomplex(z)
@@ -106,7 +114,9 @@
         res = iscomplex(z)
         assert_array_equal(res,[1,0,0])
 
+
 class TestIsreal(TestCase):
+
     def test_pass(self):
         z = array([-1,0,1j])
         res = isreal(z)
@@ -116,13 +126,17 @@
         res = isreal(z)
         assert_array_equal(res,[0,1,1])
 
+
 class TestIscomplexobj(TestCase):
+
     def test_basic(self):
         z = array([-1,0,1])
         assert(not iscomplexobj(z))
         z = array([-1j,0,-1])
         assert(iscomplexobj(z))
 
+
+
 class TestIsrealobj(TestCase):
     def test_basic(self):
         z = array([-1,0,1])
@@ -130,136 +144,207 @@
         z = array([-1j,0,-1])
         assert(not isrealobj(z))
 
+
 class TestIsnan(TestCase):
+
     def test_goodvalues(self):
         z = array((-1.,0.,1.))
         res = isnan(z) == 0
         assert_all(alltrue(res,axis=0))
+
     def test_posinf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isnan(array((1.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isnan(array((1.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     def test_neginf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isnan(array((-1.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isnan(array((-1.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     def test_ind(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        assert_all(isnan(array((0.,))/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isnan(array((0.,))/0.) == 1)
+        finally:
+            seterr(**olderr)
+
     #def test_qnan(self):             log(-1) return pi*j now
     #    assert_all(isnan(log(-1.)) == 1)
+
     def test_integer(self):
         assert_all(isnan(1) == 0)
+
     def test_complex(self):
         assert_all(isnan(1+1j) == 0)
+
     def test_complex1(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        assert_all(isnan(array(0+0j)/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isnan(array(0+0j)/0.) == 1)
+        finally:
+            seterr(**olderr)
 
+
 class TestIsfinite(TestCase):
+
     def test_goodvalues(self):
         z = array((-1.,0.,1.))
         res = isfinite(z) == 1
         assert_all(alltrue(res,axis=0))
+
     def test_posinf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isfinite(array((1.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isfinite(array((1.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     def test_neginf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isfinite(array((-1.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isfinite(array((-1.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     def test_ind(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        assert_all(isfinite(array((0.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isfinite(array((0.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     #def test_qnan(self):
     #    assert_all(isfinite(log(-1.)) == 0)
+
     def test_integer(self):
         assert_all(isfinite(1) == 1)
+
     def test_complex(self):
         assert_all(isfinite(1+1j) == 1)
+
     def test_complex1(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        assert_all(isfinite(array(1+1j)/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isfinite(array(1+1j)/0.) == 0)
+        finally:
+            seterr(**olderr)
 
+
 class TestIsinf(TestCase):
+
     def test_goodvalues(self):
         z = array((-1.,0.,1.))
         res = isinf(z) == 0
         assert_all(alltrue(res,axis=0))
+
     def test_posinf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isinf(array((1.,))/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isinf(array((1.,))/0.) == 1)
+        finally:
+            seterr(**olderr)
+
     def test_posinf_scalar(self):
         olderr = seterr(divide='ignore')
-        assert_all(isinf(array(1.,)/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isinf(array(1.,)/0.) == 1)
+        finally:
+            seterr(**olderr)
+
     def test_neginf(self):
         olderr = seterr(divide='ignore')
-        assert_all(isinf(array((-1.,))/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isinf(array((-1.,))/0.) == 1)
+        finally:
+            seterr(**olderr)
+
     def test_neginf_scalar(self):
         olderr = seterr(divide='ignore')
-        assert_all(isinf(array(-1.)/0.) == 1)
-        seterr(**olderr)
+        try:
+            assert_all(isinf(array(-1.)/0.) == 1)
+        finally:
+            seterr(**olderr)
+
     def test_ind(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        assert_all(isinf(array((0.,))/0.) == 0)
-        seterr(**olderr)
+        try:
+            assert_all(isinf(array((0.,))/0.) == 0)
+        finally:
+            seterr(**olderr)
+
     #def test_qnan(self):
     #    assert_all(isinf(log(-1.)) == 0)
     #    assert_all(isnan(log(-1.)) == 1)
 
+
 class TestIsposinf(TestCase):
+
     def test_generic(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        vals = isposinf(array((-1.,0,1))/0.)
-        seterr(**olderr)
+        try:
+            vals = isposinf(array((-1.,0,1))/0.)
+        finally:
+            seterr(**olderr)
         assert(vals[0] == 0)
         assert(vals[1] == 0)
         assert(vals[2] == 1)
 
+
 class TestIsneginf(TestCase):
     def test_generic(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        vals = isneginf(array((-1.,0,1))/0.)
-        seterr(**olderr)
+        try:
+            vals = isneginf(array((-1.,0,1))/0.)
+        finally:
+            seterr(**olderr)
         assert(vals[0] == 1)
         assert(vals[1] == 0)
         assert(vals[2] == 0)
 
+
 class TestNanToNum(TestCase):
+
     def test_generic(self):
         olderr = seterr(divide='ignore', invalid='ignore')
-        vals = nan_to_num(array((-1.,0,1))/0.)
-        seterr(**olderr)
+        try:
+            vals = nan_to_num(array((-1.,0,1))/0.)
+        finally:
+            seterr(**olderr)
         assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0]))
         assert(vals[1] == 0)
         assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2]))
+
     def test_integer(self):
         vals = nan_to_num(1)
         assert_all(vals == 1)
+
     def test_complex_good(self):
         vals = nan_to_num(1+1j)
         assert_all(vals == 1+1j)
+
     def test_complex_bad(self):
         v = 1+1j
         olderr = seterr(divide='ignore', invalid='ignore')
-        v += array(0+1.j)/0.
-        seterr(**olderr)
+        try:
+            v += array(0+1.j)/0.
+        finally:
+            seterr(**olderr)
         vals = nan_to_num(v)
         # !! This is actually (unexpectedly) zero
         assert_all(isfinite(vals))
+
     def test_complex_bad2(self):
         v = 1+1j
         olderr = seterr(divide='ignore', invalid='ignore')
-        v += array(-1+1.j)/0.
-        seterr(**olderr)
+        try:
+            v += array(-1+1.j)/0.
+        finally:
+            seterr(**olderr)
         vals = nan_to_num(v)
         assert_all(isfinite(vals))
         #assert_all(vals.imag > 1e10)  and assert_all(isfinite(vals))
@@ -270,6 +355,7 @@
 
 
 class TestRealIfClose(TestCase):
+
     def test_basic(self):
         a = rand(10)
         b = real_if_close(a+1e-15j)
@@ -280,7 +366,9 @@
         b = real_if_close(a+1e-7j,tol=1e-6)
         assert_all(isrealobj(b))
 
+
 class TestArrayConversion(TestCase):
+
     def test_asfarray(self):
         a = asfarray(array([1,2,3]))
         assert_equal(a.__class__,ndarray)



More information about the Numpy-svn mailing list