[Numpy-svn] r3370 - in trunk/numpy/core: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 19 13:26:04 CDT 2006


Author: tim_hochberg
Date: 2006-10-19 13:26:00 -0500 (Thu, 19 Oct 2006)
New Revision: 3370

Modified:
   trunk/numpy/core/numeric.py
   trunk/numpy/core/tests/test_errstate.py
Log:
Added tests for errstate(call=x). Made minor change to errstate so that an existing call can be suppressed using None during a block as well replaced.

Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py	2006-10-19 17:27:55 UTC (rev 3369)
+++ trunk/numpy/core/numeric.py	2006-10-19 18:26:00 UTC (rev 3370)
@@ -753,6 +753,10 @@
     """
     return umath.geterrobj()[2]
 
+class _unspecified(object): 
+    pass
+_Unspecified = _unspecified()
+
 class errstate(object):
     """with errstate(**state): --> operations in following block use given state.
     
@@ -781,15 +785,15 @@
     # Note that we don't want to run the above doctests because they will fail
     # without a from __future__ import with_statement
     def __init__(self, **kwargs):
-        self.call = kwargs.pop('call',None)
+        self.call = kwargs.pop('call',_Unspecified)
         self.kwargs = kwargs
     def __enter__(self):
         self.oldstate = seterr(**self.kwargs)
-        if self.call:
+        if self.call is not _Unspecified:
             self.oldcall = seterrcall(self.call)
     def __exit__(self, *exc_info):
         seterr(**self.oldstate)
-        if self.call:
+        if self.call is not _Unspecified:
             seterrcall(self.oldcall)
 
 def _setdef():

Modified: trunk/numpy/core/tests/test_errstate.py
===================================================================
--- trunk/numpy/core/tests/test_errstate.py	2006-10-19 17:27:55 UTC (rev 3369)
+++ trunk/numpy/core/tests/test_errstate.py	2006-10-19 18:26:00 UTC (rev 3370)
@@ -45,6 +45,17 @@
                 pass
             else:
                 self.fail()
+                
+    def test_errcall(self):
+        def foo(*args):
+            print args
+        olderrcall = geterrcall()
+        with errstate(call=foo):
+            assert(geterrcall() is foo), 'call is not foo'
+            with errstate(call=None):
+                assert(geterrcall() is None), 'call is not None'
+        assert(geterrcall() is olderrcall), 'call is not olderrcall'
+
 """
 
 if __name__ == '__main__':



More information about the Numpy-svn mailing list