[Scipy-svn] r3857 - in trunk/scipy: testing weave/tests

scipy-svn@scip... scipy-svn@scip...
Wed Jan 23 13:55:59 CST 2008


Author: matthew.brett@gmail.com
Date: 2008-01-23 13:55:50 -0600 (Wed, 23 Jan 2008)
New Revision: 3857

Modified:
   trunk/scipy/testing/decorators.py
   trunk/scipy/testing/nosetester.py
   trunk/scipy/weave/tests/test_scxx_dict.py
Log:
Some testing package doctrings, removed willfail decorator in favor of skipknownfailure decorator

Modified: trunk/scipy/testing/decorators.py
===================================================================
--- trunk/scipy/testing/decorators.py	2008-01-23 03:57:05 UTC (rev 3856)
+++ trunk/scipy/testing/decorators.py	2008-01-23 19:55:50 UTC (rev 3857)
@@ -1,5 +1,15 @@
-"""Decorators for labeling test objects."""
+"""Decorators for labeling test objects
 
+Decorators that merely return a modified version of the original
+function object are straightforward.  Decorators that return a new
+function object need to use
+nose.tools.make_decorator(original_function)(decorator) in returning
+the decorator, in order to preserve metadata such as function name,
+setup and teardown functions and so on - see nose.tools for more
+information.
+
+"""
+
 try:
     import nose
 except ImportError:
@@ -16,24 +26,24 @@
     t.slow = True
     return t
 
-def willfail(t):
-    ''' Labels test as known failure
+def setastest(tf=True):
+    ''' Signals to nose that this function is or is not a test
 
-    This label allows the tester to deselect the test in standard cases '''
-    t.willfail = True
-    return t
+    Parameters
+    ----------
+    tf : bool
+        If True specifies this is a test, not a test otherwise
 
-def setastest(tf=True):
-    ''' Signals to nose that this function is or is not a test
-    
     e.g
     >>> @setastest(False)
     >>> def func_with_test_in_name(arg1, arg2): pass
     ...
     >>>
     
-    Note that this decorator cannot use the nose namespace, because it
-    can be called from a non-test.
+    This decorator cannot use the nose namespace, because it can be
+    called from a non-test module. See also istest and nottest in
+    nose.tools
+
     '''
     def set_test(t):
         t.__test__ = tf
@@ -49,9 +59,22 @@
         Flag to determine whether to skip test (True) or not (False)
     msg : string
         Message to give on raising a SkipTest 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.
     '''
     if msg is None:
-        msg = 'Test skipped due to test condition (see code)'
+        msg = 'Test skipped due to test condition'
     def skip_decorator(f):
         def skipper(*args, **kwargs):
             if skip_condition:
@@ -60,3 +83,10 @@
                 return f(*args, **kwargs)
         return nose.tools.make_decorator(f)(skipper)
     return skip_decorator
+
+def skipknownfailure(f):
+    ''' Decorator to raise SkipTest for test known to fail
+    '''
+    def skipper(*args, **kwargs):
+        raise nose.SkipTest, 'This test is known to fail'
+    return nose.tools.make_decorator(f)(skipper)

Modified: trunk/scipy/testing/nosetester.py
===================================================================
--- trunk/scipy/testing/nosetester.py	2008-01-23 03:57:05 UTC (rev 3856)
+++ trunk/scipy/testing/nosetester.py	2008-01-23 19:55:50 UTC (rev 3857)
@@ -70,9 +70,9 @@
             Special values are:
             'fast' - the default - which corresponds to
                 nosetests -A option of
-                'not slow and not willfail'.
+                'not slow'.
             'full' - fast (as above) and slow %(testtype)s as in
-                nosetests -A option of 'not willfail'. 
+                no -A option to nosetests - same as ''
             None or '' - run all %(testtype)ss 
             attribute_identifier - string passed directly to
                 nosetests as '-A' 
@@ -93,13 +93,11 @@
         %(test_header)s
         '''
         argv = [__file__, self.package_path, '-s']
-        if label:
+        if label and label != 'full':
             if not isinstance(label, basestring):
                 raise TypeError, 'Selection label should be a string'
             if label == 'fast':
-                label = 'not slow and not willfail'
-            elif label == 'full':
-                label = 'not willfail'
+                label = 'not slow'
             argv += ['-A', label]
         argv += ['--verbosity', str(verbose)]
         if extra_argv:

Modified: trunk/scipy/weave/tests/test_scxx_dict.py
===================================================================
--- trunk/scipy/weave/tests/test_scxx_dict.py	2008-01-23 03:57:05 UTC (rev 3856)
+++ trunk/scipy/weave/tests/test_scxx_dict.py	2008-01-23 19:55:50 UTC (rev 3857)
@@ -111,8 +111,8 @@
     def test_char(self):
         self.generic_get('return_val = a["b"];')
 
+    @dec.skipknownfailure
     @dec.slow
-    @dec.willfail
     def test_char_fail(self):
         # We can't through a KeyError for dicts on RHS of
         # = but not on LHS.  Not sure how to deal with this.
@@ -134,8 +134,8 @@
                """
         self.generic_get(code,['a'])
 
+    @dec.skipknownfailure
     @dec.slow
-    @dec.willfail
     def test_obj_fail(self):
         # We can't through a KeyError for dicts on RHS of
         # = but not on LHS.  Not sure how to deal with this.



More information about the Scipy-svn mailing list