[Numpy-svn] r4673 - in trunk/numpy: lib/tests testing

numpy-svn@scip... numpy-svn@scip...
Wed Jan 2 11:04:17 CST 2008


Author: oliphant
Date: 2008-01-02 11:04:15 -0600 (Wed, 02 Jan 2008)
New Revision: 4673

Modified:
   trunk/numpy/lib/tests/test_format.py
   trunk/numpy/testing/utils.py
Log:
Removed dependency on nose.tools.  Ripped nose.tools.raise and placed it in numpy.testing

Modified: trunk/numpy/lib/tests/test_format.py
===================================================================
--- trunk/numpy/lib/tests/test_format.py	2007-12-30 17:57:53 UTC (rev 4672)
+++ trunk/numpy/lib/tests/test_format.py	2008-01-02 17:04:15 UTC (rev 4673)
@@ -280,10 +280,8 @@
 import shutil
 import tempfile
 
-from nose.tools import raises
-
 import numpy as np
-from numpy.testing import assert_array_equal
+from numpy.testing import assert_array_equal, raises
 
 from numpy.lib import format
 

Modified: trunk/numpy/testing/utils.py
===================================================================
--- trunk/numpy/testing/utils.py	2007-12-30 17:57:53 UTC (rev 4672)
+++ trunk/numpy/testing/utils.py	2008-01-02 17:04:15 UTC (rev 4673)
@@ -11,7 +11,7 @@
 __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
            'assert_array_equal', 'assert_array_less', 'assert_string_equal',
            'assert_array_almost_equal', 'jiffies', 'memusage', 'rand',
-           'runstring']
+           'runstring', 'raises']
 
 def rand(*args):
     """Returns an array of random numbers with the given shape.
@@ -270,3 +270,37 @@
     if not diff_list: return
     msg = 'Differences in strings:\n%s' % (''.join(diff_list)).rstrip()
     assert actual==desired, msg
+
+# Ripped from nose.tools
+def raises(*exceptions):
+    """Test must raise one of expected exceptions to pass.
+
+    Example use::
+
+      @raises(TypeError, ValueError)
+      def test_raises_type_error():
+          raise TypeError("This test passes")
+
+      @raises(Exception):
+      def test_that_fails_by_passing():
+          pass
+
+    If you want to test many assertions about exceptions in a single test,
+    you may want to use `assert_raises` instead.
+    """
+    valid = ' or '.join([e.__name__ for e in exceptions])
+    def decorate(func):
+        name = func.__name__
+        def newfunc(*arg, **kw):
+            try:
+                func(*arg, **kw)
+            except exceptions:
+                pass
+            except:
+                raise
+            else:
+                message = "%s() did not raise %s" % (name, valid)
+                raise AssertionError(message)
+        newfunc = make_decorator(func)(newfunc)
+        return newfunc
+    return decorate



More information about the Numpy-svn mailing list