Revision: 7595
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7595&view=rev
Author:   astraw
Date:     2009-08-30 04:44:28 +0000 (Sun, 30 Aug 2009)

Log Message:
-----------
testing: add support for KnownFailures

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/setup.py
    trunk/matplotlib/test/mplTest/MplNosePlugin.py
    trunk/matplotlib/test/run-mpl-test.py
    trunk/matplotlib/test/test_matplotlib/TestAxes.py

Added Paths:
-----------
    trunk/matplotlib/lib/matplotlib/testing/
    trunk/matplotlib/lib/matplotlib/testing/__init__.py
    trunk/matplotlib/lib/matplotlib/testing/decorators.py
    trunk/matplotlib/lib/matplotlib/testing/noseclasses.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2009-08-30 04:44:11 UTC (rev 7594)
+++ trunk/matplotlib/CHANGELOG  2009-08-30 04:44:28 UTC (rev 7595)
@@ -1,3 +1,7 @@
+2009-08-29 Added matplotlib.testing package, which contains a Nose
+           plugin and a decorator that lets tests be marked as
+           KnownFailures - ADS
+
 2009-08-20 Added scaled dict to AutoDateFormatter for customized
            scales - JDH
 

Added: trunk/matplotlib/lib/matplotlib/testing/decorators.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/testing/decorators.py                       
        (rev 0)
+++ trunk/matplotlib/lib/matplotlib/testing/decorators.py       2009-08-30 
04:44:28 UTC (rev 7595)
@@ -0,0 +1,24 @@
+from matplotlib.testing.noseclasses import KnownFailureTest
+import sys
+
+def knownfailureif(fail_condition, msg=None):
+    # based on numpy.testing.dec.knownfailureif
+    if msg is None:
+        msg = 'Test known to fail'
+    def known_fail_decorator(f):
+        # Local import to avoid a hard nose dependency and only incur the
+        # import time overhead at actual test-time.
+        import nose
+        def failer(*args, **kwargs):
+            try:
+                # Always run the test (to generate images).
+                result = f(*args, **kwargs)
+            except:
+                if fail_condition:
+                    raise KnownFailureTest(msg)
+                else:
+                    raise
+            # Fixme: Should raise KnownFailureDidNotFail if 
fail_condition==True?
+            return result
+        return nose.tools.make_decorator(f)(failer)
+    return known_fail_decorator

Added: trunk/matplotlib/lib/matplotlib/testing/noseclasses.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/testing/noseclasses.py                      
        (rev 0)
+++ trunk/matplotlib/lib/matplotlib/testing/noseclasses.py      2009-08-30 
04:44:28 UTC (rev 7595)
@@ -0,0 +1,41 @@
+import os
+from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
+
+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.
+
+    This is based on numpy.testing.noseclasses.KnownFailure.
+    '''
+    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
+
+    def addError( self, test, err ):
+        # Fixme (Really weird): if I don't leave empty method here,
+        # nose gets confused and KnownFails become testing errors when
+        # using the MplNosePlugin and MplTestCase.
+        pass

Modified: trunk/matplotlib/setup.py
===================================================================
--- trunk/matplotlib/setup.py   2009-08-30 04:44:11 UTC (rev 7594)
+++ trunk/matplotlib/setup.py   2009-08-30 04:44:28 UTC (rev 7595)
@@ -50,6 +50,7 @@
     'matplotlib',
     'matplotlib.backends',
     'matplotlib.projections',
+    'matplotlib.testing',
 #   'matplotlib.toolkits',
     'mpl_toolkits',
     'mpl_toolkits.mplot3d',

Modified: trunk/matplotlib/test/mplTest/MplNosePlugin.py
===================================================================
--- trunk/matplotlib/test/mplTest/MplNosePlugin.py      2009-08-30 04:44:11 UTC 
(rev 7594)
+++ trunk/matplotlib/test/mplTest/MplNosePlugin.py      2009-08-30 04:44:28 UTC 
(rev 7595)
@@ -12,6 +12,7 @@
 from path_utils import *
 import directories as dirs
 from MplTestCase import MplTestCase
+from matplotlib.testing.noseclasses import KnownFailureTest
 
 #=======================================================================
 
@@ -48,7 +49,8 @@
 
    TEST_ERRORED = -1
    TEST_FAILED = 0
-   TEST_PASSED = 1
+   TEST_KNOWN_FAILED = 1
+   TEST_PASSED = 2
 
    #--------------------------------------------------------------------
    # Some 'property' functions
@@ -148,7 +150,11 @@
          err : 3-tuple
                sys.exc_info() tuple
       """
-      self.testResults.append( (test, self.TEST_ERRORED, err) )
+      (type, value, traceback) = err
+      if isinstance(value,KnownFailureTest):
+         self.testResults.append( (test, self.TEST_KNOWN_FAILED, err) )
+      else:
+         self.testResults.append( (test, self.TEST_ERRORED, err) )
 
    #--------------------------------------------------------------------
    def addFailure( self, test, err ):

Modified: trunk/matplotlib/test/run-mpl-test.py
===================================================================
--- trunk/matplotlib/test/run-mpl-test.py       2009-08-30 04:44:11 UTC (rev 
7594)
+++ trunk/matplotlib/test/run-mpl-test.py       2009-08-30 04:44:28 UTC (rev 
7595)
@@ -44,6 +44,7 @@
 
 import nose
 from mplTest import MplNosePlugin, path_utils
+from matplotlib.testing.noseclasses import KnownFailure
 
 if '--clean' in args:
    # perform the cleaning process and exit
@@ -90,7 +91,7 @@
 
 ### Run nose
 success = nose.run( argv = args,
-                    plugins = [ MplNosePlugin() ] )
+                    plugins = [ MplNosePlugin(), KnownFailure() ] )
 
 ### do other stuff here
 

Modified: trunk/matplotlib/test/test_matplotlib/TestAxes.py
===================================================================
--- trunk/matplotlib/test/test_matplotlib/TestAxes.py   2009-08-30 04:44:11 UTC 
(rev 7594)
+++ trunk/matplotlib/test/test_matplotlib/TestAxes.py   2009-08-30 04:44:28 UTC 
(rev 7595)
@@ -3,6 +3,7 @@
 #=======================================================================
 
 from mplTest import MplTestCase, units
+from matplotlib.testing.decorators import knownfailureif
 
 #=======================================================================
 # Add import modules below.
@@ -57,6 +58,7 @@
       self.checkImage( fname )
 
    #--------------------------------------------------------------------
+   @knownfailureif(True, "Fails due to SF bug 2846058")
    def test_formatter_ticker( self ):
       """Test Some formatter and ticker issues."""
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to