@@ -78,124 +78,3 @@ def test_image_comparison_expect_rms(im1, im2, tol, expect_rms):
78
78
else :
79
79
assert results is not None
80
80
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
- def nosetest_manual_text_removal ():
100
- from matplotlib .testing .decorators import ImageComparisonTest
101
-
102
- fig = nosetest_simple_figure ()
103
- with warnings .catch_warnings (record = True ) as w :
104
- warnings .simplefilter ('always' )
105
- # Make sure this removes text like it should.
106
- ImageComparisonTest .remove_text (fig )
107
-
108
- assert len (w ) == 1
109
- assert 'remove_text function was deprecated in version 2.1.' in str (w [0 ])
110
-
111
-
112
- @pytest .mark .parametrize (
113
- 'func, kwargs, errors, failures, dots' ,
114
- [
115
- (nosetest_empty , {'baseline_images' : []}, [], [], '' ),
116
- (nosetest_empty , {'baseline_images' : ['foo' ]},
117
- [(AssertionError ,
118
- 'Test generated 0 images but there are 1 baseline images' )],
119
- [],
120
- 'E' ),
121
- (nosetest_simple_figure ,
122
- {'baseline_images' : ['basn3p02' ], 'extensions' : ['png' ],
123
- 'remove_text' : True },
124
- [],
125
- [(ImageComparisonFailure , 'Image sizes do not match expected size:' )],
126
- 'F' ),
127
- (nosetest_simple_figure ,
128
- {'baseline_images' : ['simple' ]},
129
- [],
130
- [(ImageComparisonFailure , 'images not close' )] * 3 ,
131
- 'FFF' ),
132
- (nosetest_simple_figure ,
133
- {'baseline_images' : ['simple' ], 'remove_text' : True },
134
- [],
135
- [],
136
- '...' ),
137
- (nosetest_manual_text_removal ,
138
- {'baseline_images' : ['simple' ]},
139
- [],
140
- [],
141
- '...' ),
142
- ],
143
- ids = [
144
- 'empty' ,
145
- 'extra baselines' ,
146
- 'incorrect shape' ,
147
- 'failing figure' ,
148
- 'passing figure' ,
149
- 'manual text removal' ,
150
- ])
151
- def test_nose_image_comparison (func , kwargs , errors , failures , dots ,
152
- monkeypatch ):
153
- nose = pytest .importorskip ('nose' )
154
- monkeypatch .setattr ('matplotlib._called_from_pytest' , False )
155
-
156
- class TestResultVerifier (nose .result .TextTestResult ):
157
- def __init__ (self , * args , ** kwargs ):
158
- super ().__init__ (* args , ** kwargs )
159
- self .error_count = 0
160
- self .failure_count = 0
161
-
162
- def addError (self , test , err ):
163
- super ().addError (test , err )
164
-
165
- if self .error_count < len (errors ):
166
- assert err [0 ] is errors [self .error_count ][0 ]
167
- assert errors [self .error_count ][1 ] in str (err [1 ])
168
- else :
169
- raise err [1 ]
170
- self .error_count += 1
171
-
172
- def addFailure (self , test , err ):
173
- super ().addFailure (test , err )
174
-
175
- assert self .failure_count < len (failures ), err [1 ]
176
- assert err [0 ] is failures [self .failure_count ][0 ]
177
- assert failures [self .failure_count ][1 ] in str (err [1 ])
178
- self .failure_count += 1
179
-
180
- # Make sure that multiple extensions work, but don't require LaTeX or
181
- # Inkscape to do so.
182
- kwargs .setdefault ('extensions' , ['png' , 'png' , 'png' ])
183
-
184
- func = image_comparison (** kwargs )(func )
185
- loader = nose .loader .TestLoader ()
186
- suite = loader .loadTestsFromGenerator (
187
- func ,
188
- 'matplotlib.tests.test_compare_images' )
189
- if six .PY2 :
190
- output = io .BytesIO ()
191
- else :
192
- output = io .StringIO ()
193
- result = TestResultVerifier (stream = output , descriptions = True , verbosity = 1 )
194
- with warnings .catch_warnings ():
195
- # Nose uses deprecated stuff; we don't care about it.
196
- warnings .simplefilter ('ignore' , DeprecationWarning )
197
- suite .run (result = result )
198
-
199
- assert output .getvalue () == dots
200
- assert result .error_count == len (errors )
201
- assert result .failure_count == len (failures )
0 commit comments