@@ -97,10 +97,10 @@ def _collect_new_figures():
97
97
new_figs [:]= [manager .canvas .figure for manager in new_managers ]
98
98
99
99
100
- def _raise_on_image_difference (expected ,actual ,tol ):
100
+ def _raise_on_image_difference (expected ,actual ,tol , * , deadband ):
101
101
__tracebackhide__ = True
102
102
103
- err = compare_images (expected ,actual ,tol ,in_decorator = True )
103
+ err = compare_images (expected ,actual ,tol ,in_decorator = True , deadband = deadband )
104
104
if err :
105
105
for key in ["actual" ,"expected" ,"diff" ]:
106
106
err [key ]= os .path .relpath (err [key ])
@@ -117,12 +117,13 @@ class _ImageComparisonBase:
117
117
any code that would be specific to any testing framework.
118
118
"""
119
119
120
- def __init__ (self ,func ,tol ,remove_text ,savefig_kwargs ):
120
+ def __init__ (self ,func ,tol ,remove_text ,savefig_kwargs , * , deadband = 0 ):
121
121
self .func = func
122
122
self .baseline_dir ,self .result_dir = _image_directories (func )
123
123
self .tol = tol
124
124
self .remove_text = remove_text
125
125
self .savefig_kwargs = savefig_kwargs
126
+ self .deadband = deadband
126
127
127
128
def copy_baseline (self ,baseline ,extension ):
128
129
baseline_path = self .baseline_dir / baseline
@@ -171,12 +172,14 @@ def compare(self, fig, baseline, extension, *, _lock=False):
171
172
# makes things more convenient for third-party users.
172
173
plt .close (fig )
173
174
expected_path = self .copy_baseline (baseline ,extension )
174
- _raise_on_image_difference (expected_path ,actual_path ,self .tol )
175
+ _raise_on_image_difference (
176
+ expected_path ,actual_path ,self .tol ,deadband = self .deadband
177
+ )
175
178
176
179
177
180
def _pytest_image_comparison (baseline_images ,extensions ,tol ,
178
181
freetype_version ,remove_text ,savefig_kwargs ,
179
- style ):
182
+ style , * , deadband = 0 ):
180
183
"""
181
184
Decorate function with image comparison for pytest.
182
185
@@ -260,7 +263,9 @@ def image_comparison(baseline_images, extensions=None, tol=0,
260
263
freetype_version = None ,remove_text = False ,
261
264
savefig_kwarg = None ,
262
265
# Default of mpl_test_settings fixture and cleanup too.
263
- style = ("classic" ,"_classic_test_patch" )):
266
+ style = ("classic" ,"_classic_test_patch" ),
267
+ * ,
268
+ deadband = 0 ):
264
269
"""
265
270
Compare images generated by the test with those specified in
266
271
*baseline_images*, which must correspond, else an `.ImageComparisonFailure`
@@ -315,6 +320,19 @@ def image_comparison(baseline_images, extensions=None, tol=0,
315
320
The optional style(s) to apply to the image test. The test itself
316
321
can also apply additional styles if desired. Defaults to ``["classic",
317
322
"_classic_test_patch"]``.
323
+
324
+ deadband : int, default 0
325
+
326
+ Like *tol* this provides a way to allow slight changes in the images to
327
+ pass.
328
+
329
+ The most common change between architectures is that float math or
330
+ float-to-int may have slight differences in rounding that results in the
331
+ value in an 8bit color channel to change by +/- 1.
332
+
333
+ The per-channel differences must be greater than deadband to contribute
334
+ to the computed RMS.
335
+
318
336
"""
319
337
320
338
if baseline_images is not None :
@@ -346,7 +364,7 @@ def image_comparison(baseline_images, extensions=None, tol=0,
346
364
savefig_kwargs = savefig_kwarg ,style = style )
347
365
348
366
349
- def check_figures_equal (* ,extensions = ("png" ,"pdf" ,"svg" ),tol = 0 ):
367
+ def check_figures_equal (* ,extensions = ("png" ,"pdf" ,"svg" ),tol = 0 , deadband = 0 ):
350
368
"""
351
369
Decorator for test cases that generate and compare two figures.
352
370
@@ -420,7 +438,7 @@ def wrapper(*args, ext, request, **kwargs):
420
438
fig_test .savefig (test_image_path )
421
439
fig_ref .savefig (ref_image_path )
422
440
_raise_on_image_difference (
423
- ref_image_path ,test_image_path ,tol = tol
441
+ ref_image_path ,test_image_path ,tol = tol , deadband = deadband
424
442
)
425
443
finally :
426
444
plt .close (fig_test )