Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4379165

Browse files
committed
testing: add support for KnownFailures
svn path=/trunk/matplotlib/; revision=7595
1 parent c9dfccd commit 4379165

8 files changed

Lines changed: 82 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2009-08-29 Added matplotlib.testing package, which contains a Nose
2+
plugin and a decorator that lets tests be marked as
3+
KnownFailures - ADS
4+
15
2009-08-20 Added scaled dict to AutoDateFormatter for customized
26
scales - JDH
37

lib/matplotlib/testing/__init__.py

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from matplotlib.testing.noseclasses import KnownFailureTest
2+
import sys
3+
4+
def knownfailureif(fail_condition, msg=None):
5+
# based on numpy.testing.dec.knownfailureif
6+
if msg is None:
7+
msg = 'Test known to fail'
8+
def known_fail_decorator(f):
9+
# Local import to avoid a hard nose dependency and only incur the
10+
# import time overhead at actual test-time.
11+
import nose
12+
def failer(*args, **kwargs):
13+
try:
14+
# Always run the test (to generate images).
15+
result = f(*args, **kwargs)
16+
except:
17+
if fail_condition:
18+
raise KnownFailureTest(msg)
19+
else:
20+
raise
21+
# Fixme: Should raise KnownFailureDidNotFail if fail_condition==True?
22+
return result
23+
return nose.tools.make_decorator(f)(failer)
24+
return known_fail_decorator
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
from nose.plugins.errorclass import ErrorClass, ErrorClassPlugin
3+
4+
class KnownFailureTest(Exception):
5+
'''Raise this exception to mark a test as a known failing test.'''
6+
pass
7+
8+
class KnownFailure(ErrorClassPlugin):
9+
'''Plugin that installs a KNOWNFAIL error class for the
10+
KnownFailureClass exception. When KnownFailureTest is raised,
11+
the exception will be logged in the knownfail attribute of the
12+
result, 'K' or 'KNOWNFAIL' (verbose) will be output, and the
13+
exception will not be counted as an error or failure.
14+
15+
This is based on numpy.testing.noseclasses.KnownFailure.
16+
'''
17+
enabled = True
18+
knownfail = ErrorClass(KnownFailureTest,
19+
label='KNOWNFAIL',
20+
isfailure=False)
21+
22+
def options(self, parser, env=os.environ):
23+
env_opt = 'NOSE_WITHOUT_KNOWNFAIL'
24+
parser.add_option('--no-knownfail', action='store_true',
25+
dest='noKnownFail', default=env.get(env_opt, False),
26+
help='Disable special handling of KnownFailureTest '
27+
'exceptions')
28+
29+
def configure(self, options, conf):
30+
if not self.can_configure:
31+
return
32+
self.conf = conf
33+
disable = getattr(options, 'noKnownFail', False)
34+
if disable:
35+
self.enabled = False
36+
37+
def addError( self, test, err ):
38+
# Fixme (Really weird): if I don't leave empty method here,
39+
# nose gets confused and KnownFails become testing errors when
40+
# using the MplNosePlugin and MplTestCase.
41+
pass

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'matplotlib',
5151
'matplotlib.backends',
5252
'matplotlib.projections',
53+
'matplotlib.testing',
5354
# 'matplotlib.toolkits',
5455
'mpl_toolkits',
5556
'mpl_toolkits.mplot3d',

test/mplTest/MplNosePlugin.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from path_utils import *
1313
import directories as dirs
1414
from MplTestCase import MplTestCase
15+
from matplotlib.testing.noseclasses import KnownFailureTest
1516

1617
#=======================================================================
1718

@@ -48,7 +49,8 @@ class MplNosePlugin( Plugin ):
4849

4950
TEST_ERRORED = -1
5051
TEST_FAILED = 0
51-
TEST_PASSED = 1
52+
TEST_KNOWN_FAILED = 1
53+
TEST_PASSED = 2
5254

5355
#--------------------------------------------------------------------
5456
# Some 'property' functions
@@ -148,7 +150,11 @@ def addError( self, test, err ):
148150
err : 3-tuple
149151
sys.exc_info() tuple
150152
"""
151-
self.testResults.append( (test, self.TEST_ERRORED, err) )
153+
(type, value, traceback) = err
154+
if isinstance(value,KnownFailureTest):
155+
self.testResults.append( (test, self.TEST_KNOWN_FAILED, err) )
156+
else:
157+
self.testResults.append( (test, self.TEST_ERRORED, err) )
152158

153159
#--------------------------------------------------------------------
154160
def addFailure( self, test, err ):

test/run-mpl-test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import nose
4646
from mplTest import MplNosePlugin, path_utils
47+
from matplotlib.testing.noseclasses import KnownFailure
4748

4849
if '--clean' in args:
4950
# perform the cleaning process and exit
@@ -90,7 +91,7 @@
9091

9192
### Run nose
9293
success = nose.run( argv = args,
93-
plugins = [ MplNosePlugin() ] )
94+
plugins = [ MplNosePlugin(), KnownFailure() ] )
9495

9596
### do other stuff here
9697

test/test_matplotlib/TestAxes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#=======================================================================
44

55
from mplTest import MplTestCase, units
6+
from matplotlib.testing.decorators import knownfailureif
67

78
#=======================================================================
89
# Add import modules below.
@@ -57,6 +58,7 @@ def test_empty_datetime( self ):
5758
self.checkImage( fname )
5859

5960
#--------------------------------------------------------------------
61+
@knownfailureif(True, "Fails due to SF bug 2846058")
6062
def test_formatter_ticker( self ):
6163
"""Test Some formatter and ticker issues."""
6264

0 commit comments

Comments
 (0)