[Numpy-svn] r5405 - trunk/numpy/testing

numpy-svn@scip... numpy-svn@scip...
Sun Jul 13 17:06:17 CDT 2008


Author: alan.mcintyre
Date: 2008-07-13 17:06:13 -0500 (Sun, 13 Jul 2008)
New Revision: 5405

Modified:
   trunk/numpy/testing/nosetester.py
   trunk/numpy/testing/utils.py
Log:
Replaced utils.raises implementation with the nose function.
Added utils.assert_raises (uses the function from nose).
Wrapped text for test() deprecation warning.


Modified: trunk/numpy/testing/nosetester.py
===================================================================
--- trunk/numpy/testing/nosetester.py	2008-07-13 21:47:43 UTC (rev 5404)
+++ trunk/numpy/testing/nosetester.py	2008-07-13 22:06:13 UTC (rev 5405)
@@ -294,7 +294,10 @@
         # issue a deprecation warning if any of the pre-1.2 arguments to 
         # test are given
         if old_args.intersection(kwargs.keys()):
-            warnings.warn("This method's signature will change in the next release; the level, verbosity, all, sys_argv, and testcase_pattern keyword arguments will be removed. Please update your code.", 
+            warnings.warn("This method's signature will change in the next " \
+                          "release; the level, verbosity, all, sys_argv, " \
+                          "and testcase_pattern keyword arguments will be " \
+                          "removed. Please update your code.", 
                           DeprecationWarning, stacklevel=2)
         
         # Use old arguments if given (where it makes sense)

Modified: trunk/numpy/testing/utils.py
===================================================================
--- trunk/numpy/testing/utils.py	2008-07-13 21:47:43 UTC (rev 5404)
+++ trunk/numpy/testing/utils.py	2008-07-13 22:06:13 UTC (rev 5405)
@@ -7,11 +7,12 @@
 import re
 import difflib
 import operator
+from nosetester import import_nose
 
 __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
            'assert_array_equal', 'assert_array_less', 'assert_string_equal',
-           'assert_array_almost_equal', 'build_err_msg', 'jiffies', 'memusage',
-           'raises', 'rand', 'rundocs', 'runstring']
+           'assert_array_almost_equal', 'assert_raises', 'build_err_msg', 
+           'jiffies', 'memusage', 'raises', 'rand', 'rundocs', 'runstring']
 
 def rand(*args):
     """Returns an array of random numbers with the given shape.
@@ -319,32 +320,10 @@
     return
 
 
-def raises(*exceptions):
-    """ Assert that a test function raises one of the specified exceptions to
-    pass.
-    """
-    # FIXME: when we transition to nose, just use its implementation. It's
-    # better.
-    def deco(function):
-        def f2(*args, **kwds):
-            try:
-                function(*args, **kwds)
-            except exceptions:
-                pass
-            except:
-                # Anything else.
-                raise
-            else:
-                raise AssertionError('%s() did not raise one of (%s)' %
-                    (function.__name__, ', '.join([e.__name__ for e in exceptions])))
-        try:
-            f2.__name__ = function.__name__
-        except TypeError:
-            # Python 2.3 does not permit this.
-            pass
-        f2.__dict__ = function.__dict__
-        f2.__doc__ = function.__doc__
-        f2.__module__ = function.__module__
-        return f2
+def raises(*args,**kwargs):
+    nose = import_nose()
+    return nose.tools.raises(*args,**kwargs)
 
-    return deco
+def assert_raises(*args,**kwargs):
+    nose = import_nose()
+    return nose.tools.assert_raises(*args,**kwargs)



More information about the Numpy-svn mailing list