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

numpy-svn@scip... numpy-svn@scip...
Mon Jul 21 01:55:54 CDT 2008


Author: alan.mcintyre
Date: 2008-07-21 01:55:48 -0500 (Mon, 21 Jul 2008)
New Revision: 5486

Modified:
   trunk/numpy/testing/nosetester.py
   trunk/numpy/testing/utils.py
Log:
Added numpy.testing.verbose, to allow tests to vary output accordingly.
Added numpy.testing.print_assert_equal, to allow removing the multiple 
identical implementations of this function in SciPy tests.
Display version info for NumPy, Python, and nose (and SciPy when running SciPy 
tests), in a manner similar to the original test framework.


Modified: trunk/numpy/testing/nosetester.py
===================================================================
--- trunk/numpy/testing/nosetester.py	2008-07-21 06:29:58 UTC (rev 5485)
+++ trunk/numpy/testing/nosetester.py	2008-07-21 06:55:48 UTC (rev 5486)
@@ -183,6 +183,9 @@
             # cap verbosity at 3 because nose becomes *very* verbose beyond that
             verbose = min(verbose, 3)
 
+        import utils
+        utils.verbose = verbose
+
         # if all evaluates as True, omit attribute filter and run doctests
         if kwargs.get('all'):
             label = ''
@@ -215,6 +218,21 @@
 
         nose = import_nose()
 
+        import numpy
+        print "NumPy version %s" % numpy.__version__
+        npdir = os.path.dirname(numpy.__file__)
+        print "NumPy is installed in %s" % npdir
+        
+        if 'scipy' in self.package_name:
+            import scipy
+            print "SciPy version %s" % scipy.__version__
+            spdir = os.path.dirname(scipy.__file__)
+            print "SciPy is installed in %s" % spdir
+            
+        pyversion = sys.version.replace('\n','')
+        print "Python version %s" % pyversion
+        print "nose version %d.%d.%d" % nose.__versioninfo__
+
         # Because nose currently discards the test result object, but we need 
         # to return it to the user, override TestProgram.runTests to retain 
         # the result

Modified: trunk/numpy/testing/utils.py
===================================================================
--- trunk/numpy/testing/utils.py	2008-07-21 06:29:58 UTC (rev 5485)
+++ trunk/numpy/testing/utils.py	2008-07-21 06:55:48 UTC (rev 5486)
@@ -13,9 +13,11 @@
 __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
            'assert_array_equal', 'assert_array_less', 'assert_string_equal',
            'assert_array_almost_equal', 'assert_raises', 'build_err_msg', 
-           'decorate_methods', 'jiffies', 'memusage', 'raises', 'rand', 
-           'rundocs', 'runstring']
+           'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal',
+           'raises', 'rand', 'rundocs', 'runstring', 'verbose']
 
+verbose = 0
+
 def rand(*args):
     """Returns an array of random numbers with the given shape.
 
@@ -147,6 +149,20 @@
     msg = build_err_msg([actual, desired], err_msg, verbose=verbose)
     assert desired == actual, msg
 
+def print_assert_equal(test_string,actual,desired):
+    import pprint
+    try:
+        assert(actual == desired)
+    except AssertionError:
+        import cStringIO
+        msg = cStringIO.StringIO()
+        msg.write(test_string)
+        msg.write(' failed\nACTUAL: \n')
+        pprint.pprint(actual,msg)
+        msg.write('DESIRED: \n')
+        pprint.pprint(desired,msg)
+        raise AssertionError, msg.getvalue()
+
 def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
     """ Raise an assertion if two items are not equal.
 



More information about the Numpy-svn mailing list