@@ -78,105 +78,3 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
7878 else :
7979 assert results is not None
8080 assert results ['rms' ] == approx (expect_rms , abs = 1e-4 )
81-
82-
83- # The following tests are used by test_nose_image_comparison to ensure that the
84- # image_comparison decorator continues to work with nose. They should not be
85- # prefixed by test_ so they don't run with pytest.
86-
87-
88- def nosetest_empty ():
89- pass
90-
91-
92- def nosetest_simple_figure ():
93- import matplotlib .pyplot as plt
94- fig , ax = plt .subplots (figsize = (6.4 , 4 ), dpi = 100 )
95- ax .plot ([1 , 2 , 3 ], [3 , 4 , 5 ])
96- return fig
97-
98-
99- @pytest .mark .parametrize (
100- 'func, kwargs, errors, failures, dots' ,
101- [
102- (nosetest_empty , {'baseline_images' : []}, [], [], '' ),
103- (nosetest_empty , {'baseline_images' : ['foo' ]},
104- [(AssertionError ,
105- 'Test generated 0 images but there are 1 baseline images' )],
106- [],
107- 'E' ),
108- (nosetest_simple_figure ,
109- {'baseline_images' : ['basn3p02' ], 'extensions' : ['png' ],
110- 'remove_text' : True },
111- [],
112- [(ImageComparisonFailure , 'Image sizes do not match expected size:' )],
113- 'F' ),
114- (nosetest_simple_figure ,
115- {'baseline_images' : ['simple' ]},
116- [],
117- [(ImageComparisonFailure , 'images not close' )] * 3 ,
118- 'FFF' ),
119- (nosetest_simple_figure ,
120- {'baseline_images' : ['simple' ], 'remove_text' : True },
121- [],
122- [],
123- '...' ),
124- ],
125- ids = [
126- 'empty' ,
127- 'extra baselines' ,
128- 'incorrect shape' ,
129- 'failing figure' ,
130- 'passing figure' ,
131- ])
132- def test_nose_image_comparison (func , kwargs , errors , failures , dots ,
133- monkeypatch ):
134- nose = pytest .importorskip ('nose' )
135- monkeypatch .setattr ('matplotlib._called_from_pytest' , False )
136-
137- class TestResultVerifier (nose .result .TextTestResult ):
138- def __init__ (self , * args , ** kwargs ):
139- super ().__init__ (* args , ** kwargs )
140- self .error_count = 0
141- self .failure_count = 0
142-
143- def addError (self , test , err ):
144- super ().addError (test , err )
145-
146- if self .error_count < len (errors ):
147- assert err [0 ] is errors [self .error_count ][0 ]
148- assert errors [self .error_count ][1 ] in str (err [1 ])
149- else :
150- raise err [1 ]
151- self .error_count += 1
152-
153- def addFailure (self , test , err ):
154- super ().addFailure (test , err )
155-
156- assert self .failure_count < len (failures ), err [1 ]
157- assert err [0 ] is failures [self .failure_count ][0 ]
158- assert failures [self .failure_count ][1 ] in str (err [1 ])
159- self .failure_count += 1
160-
161- # Make sure that multiple extensions work, but don't require LaTeX or
162- # Inkscape to do so.
163- kwargs .setdefault ('extensions' , ['png' , 'png' , 'png' ])
164-
165- func = image_comparison (** kwargs )(func )
166- loader = nose .loader .TestLoader ()
167- suite = loader .loadTestsFromGenerator (
168- func ,
169- 'matplotlib.tests.test_compare_images' )
170- if six .PY2 :
171- output = io .BytesIO ()
172- else :
173- output = io .StringIO ()
174- result = TestResultVerifier (stream = output , descriptions = True , verbosity = 1 )
175- with warnings .catch_warnings ():
176- # Nose uses deprecated stuff; we don't care about it.
177- warnings .simplefilter ('ignore' , DeprecationWarning )
178- suite .run (result = result )
179-
180- assert output .getvalue () == dots
181- assert result .error_count == len (errors )
182- assert result .failure_count == len (failures )
0 commit comments