[Numpy-svn] r5769 - in trunk/numpy: core/tests testing

numpy-svn@scip... numpy-svn@scip...
Thu Sep 4 13:23:59 CDT 2008


Author: alan.mcintyre
Date: 2008-09-04 13:23:48 -0500 (Thu, 04 Sep 2008)
New Revision: 5769

Modified:
   trunk/numpy/core/tests/test_umath.py
   trunk/numpy/testing/decorators.py
   trunk/numpy/testing/noseclasses.py
   trunk/numpy/testing/nosetester.py
Log:
Replaced numpy.testing.decorators.skipknownfailure with knownfailureif, 
which allows flagging tests as known failures rather than skips.
Updated test_umath to use knownfailureif.


Modified: trunk/numpy/core/tests/test_umath.py
===================================================================
--- trunk/numpy/core/tests/test_umath.py	2008-09-04 18:04:35 UTC (rev 5768)
+++ trunk/numpy/core/tests/test_umath.py	2008-09-04 18:23:48 UTC (rev 5769)
@@ -229,6 +229,7 @@
         yield _check_branch_cut, np.arccosh, [-2j, 2j, 2], [1,  1,  1j], 1, 1
         yield _check_branch_cut, np.arctanh, [-2j, 2j, 0], [1,  1,  1j], 1, 1
 
+    @dec.knownfailureif(True, "These branch cuts are known to fail")
     def test_branch_cuts_failing(self):
         # XXX: signed zeros are not OK for sqrt or for the arc* functions
         yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True
@@ -238,7 +239,6 @@
         yield _check_branch_cut, np.arcsinh, [-2j,  2j], [-1,   1], -1, 1, True
         yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
         yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, -1j], 1, -1, True
-    test_branch_cuts_failing = dec.skipknownfailure(test_branch_cuts_failing)
 
     def test_against_cmath(self):
         import cmath, sys

Modified: trunk/numpy/testing/decorators.py
===================================================================
--- trunk/numpy/testing/decorators.py	2008-09-04 18:04:35 UTC (rev 5768)
+++ trunk/numpy/testing/decorators.py	2008-09-04 18:23:48 UTC (rev 5769)
@@ -83,12 +83,41 @@
         return nose.tools.make_decorator(f)(skipper)
     return skip_decorator
 
-def skipknownfailure(f):
-    ''' Decorator to raise SkipTest for test known to fail
+def knownfailureif(skip_condition, msg=None):
+    ''' Make function raise KnownFailureTest exception if skip_condition is true
+
+    Parameters
+    ---------
+    skip_condition : bool
+        Flag to determine whether to mark test as known failure (True) 
+        or not (False)
+    msg : string
+        Message to give on raising a KnownFailureTest exception
+
+   Returns
+   -------
+   decorator : function
+       Decorator, which, when applied to a function, causes SkipTest
+       to be raised when the skip_condition was True, and the function
+       to be called normally otherwise.
+
+    Notes
+    -----
+    You will see from the code that we had to further decorate the
+    decorator with the nose.tools.make_decorator function in order to
+    transmit function name, and various other metadata.
     '''
-    # Local import to avoid a hard nose dependency and only incur the
-    # import time overhead at actual test-time.
-    import nose
-    def skipper(*args, **kwargs):
-        raise nose.SkipTest, 'This test is known to fail'
-    return nose.tools.make_decorator(f)(skipper)
+    if msg is None:
+        msg = 'Test skipped due to known failure'
+    def skip_decorator(f):
+        # Local import to avoid a hard nose dependency and only incur the
+        # import time overhead at actual test-time.
+        import nose
+        from noseclasses import KnownFailureTest
+        def skipper(*args, **kwargs):
+            if skip_condition:
+                raise KnownFailureTest, msg
+            else:
+                return f(*args, **kwargs)
+        return nose.tools.make_decorator(f)(skipper)
+    return skip_decorator

Modified: trunk/numpy/testing/noseclasses.py
===================================================================
--- trunk/numpy/testing/noseclasses.py	2008-09-04 18:04:35 UTC (rev 5768)
+++ trunk/numpy/testing/noseclasses.py	2008-09-04 18:23:48 UTC (rev 5769)
@@ -7,6 +7,7 @@
 import doctest
 
 from nose.plugins import doctests as npd
+from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
 from nose.plugins.base import Plugin
 from nose.util import src, tolist
 import numpy
@@ -16,8 +17,8 @@
 _doctest_ignore = ['generate_numpy_api.py', 'scons_support.py',
                    'setupscons.py', 'setup.py']
 
-# All the classes in this module begin with 'numpy' to clearly distinguish them
-# from the plethora of very similar names from nose/unittest/doctest
+# Some of the classes in this module begin with 'numpy' to clearly distinguish
+# them from the plethora of very similar names from nose/unittest/doctest
 
 
 #-----------------------------------------------------------------------------
@@ -246,3 +247,35 @@
         if bn in _doctest_ignore:
             return False
         return npd.Doctest.wantFile(self, file)
+
+
+class KnownFailureTest(Exception):
+    '''Raise this exception to mark a test as a known failing test.'''
+    pass
+
+
+class KnownFailure(ErrorClassPlugin):
+    '''Plugin that installs a KNOWNFAIL error class for the 
+    KnownFailureClass exception.  When KnownFailureTest is raised,
+    the exception will be logged in the knownfail attribute of the
+    result, 'K' or 'KNOWNFAIL' (verbose) will be output, and the
+    exception will not be counted as an error or failure.'''
+    enabled = True
+    knownfail = ErrorClass(KnownFailureTest,
+                           label='KNOWNFAIL',
+                           isfailure=False)
+
+    def options(self, parser, env=os.environ):
+        env_opt = 'NOSE_WITHOUT_KNOWNFAIL'
+        parser.add_option('--no-knownfail', action='store_true',
+                          dest='noKnownFail', default=env.get(env_opt, False),
+                          help='Disable special handling of KnownFailureTest '
+                               'exceptions')
+
+    def configure(self, options, conf):
+        if not self.can_configure:
+            return
+        self.conf = conf
+        disable = getattr(options, 'noKnownFail', False)
+        if disable:
+            self.enabled = False

Modified: trunk/numpy/testing/nosetester.py
===================================================================
--- trunk/numpy/testing/nosetester.py	2008-09-04 18:04:35 UTC (rev 5768)
+++ trunk/numpy/testing/nosetester.py	2008-09-04 18:23:48 UTC (rev 5769)
@@ -266,8 +266,8 @@
 
         # construct list of plugins, omitting the existing doctest plugin
         import nose.plugins.builtin
-        from noseclasses import numpyDoctest
-        plugins = [numpyDoctest()]
+        from noseclasses import numpyDoctest, KnownFailure
+        plugins = [numpyDoctest(), KnownFailure()]
         for p in nose.plugins.builtin.plugins:
             plug = p()
             if plug.name == 'doctest':



More information about the Numpy-svn mailing list