Skip to content

Commit 73cb5c7

Browse files
authored
Merge pull request #12877 from anntzer/pep8
fooImage -> foo_image in testing/compare.py
2 parents 0d1effc + 34c4b82 commit 73cb5c7

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
API changes
2+
```````````
3+
The arguments of `matplotlib.testing.compare.calculate_rms` have been renamed
4+
from ``expectedImage, actualImage``, to ``expected_image, actual_image``.
5+
6+
Deprecations
7+
````````````
8+
The ``matplotlib.testing.decorators.switch_backend`` decorator is deprecated.
9+
Test functions should use ``pytest.mark.backend(...)``, and the mark will be
10+
picked up by the ``matplotlib.testing.conftest.mpl_test_settings`` fixture.

lib/matplotlib/testing/compare.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,14 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image):
352352
return actual_image, expected_image
353353

354354

355-
def calculate_rms(expectedImage, actualImage):
355+
def calculate_rms(expected_image, actual_image):
356356
"Calculate the per-pixel errors, then compute the root mean square error."
357-
if expectedImage.shape != actualImage.shape:
357+
if expected_image.shape != actual_image.shape:
358358
raise ImageComparisonFailure(
359359
"Image sizes do not match expected size: {} "
360-
"actual size {}".format(expectedImage.shape, actualImage.shape))
360+
"actual size {}".format(expected_image.shape, actual_image.shape))
361361
# Convert to float to avoid overflowing finite integer types.
362-
return np.sqrt(((expectedImage - actualImage).astype(float) ** 2).mean())
362+
return np.sqrt(((expected_image - actual_image).astype(float) ** 2).mean())
363363

364364

365365
def compare_images(expected, actual, tol, in_decorator=False):
@@ -428,26 +428,26 @@ def compare_images(expected, actual, tol, in_decorator=False):
428428
expected = convert(expected, True)
429429

430430
# open the image files and remove the alpha channel (if it exists)
431-
expectedImage = _png.read_png_int(expected)
432-
actualImage = _png.read_png_int(actual)
433-
expectedImage = expectedImage[:, :, :3]
434-
actualImage = actualImage[:, :, :3]
431+
expected_image = _png.read_png_int(expected)
432+
actual_image = _png.read_png_int(actual)
433+
expected_image = expected_image[:, :, :3]
434+
actual_image = actual_image[:, :, :3]
435435

436-
actualImage, expectedImage = crop_to_same(
437-
actual, actualImage, expected, expectedImage)
436+
actual_image, expected_image = crop_to_same(
437+
actual, actual_image, expected, expected_image)
438438

439439
diff_image = make_test_filename(actual, 'failed-diff')
440440

441441
if tol <= 0:
442-
if np.array_equal(expectedImage, actualImage):
442+
if np.array_equal(expected_image, actual_image):
443443
return None
444444

445445
# convert to signed integers, so that the images can be subtracted without
446446
# overflow
447-
expectedImage = expectedImage.astype(np.int16)
448-
actualImage = actualImage.astype(np.int16)
447+
expected_image = expected_image.astype(np.int16)
448+
actual_image = actual_image.astype(np.int16)
449449

450-
rms = calculate_rms(expectedImage, actualImage)
450+
rms = calculate_rms(expected_image, actual_image)
451451

452452
if rms <= tol:
453453
return None
@@ -481,21 +481,21 @@ def save_diff_image(expected, actual, output):
481481
File path to save difference image to.
482482
'''
483483
# Drop alpha channels, similarly to compare_images.
484-
expectedImage = _png.read_png(expected)[..., :3]
485-
actualImage = _png.read_png(actual)[..., :3]
486-
actualImage, expectedImage = crop_to_same(
487-
actual, actualImage, expected, expectedImage)
488-
expectedImage = np.array(expectedImage).astype(float)
489-
actualImage = np.array(actualImage).astype(float)
490-
if expectedImage.shape != actualImage.shape:
484+
expected_image = _png.read_png(expected)[..., :3]
485+
actual_image = _png.read_png(actual)[..., :3]
486+
actual_image, expected_image = crop_to_same(
487+
actual, actual_image, expected, expected_image)
488+
expected_image = np.array(expected_image).astype(float)
489+
actual_image = np.array(actual_image).astype(float)
490+
if expected_image.shape != actual_image.shape:
491491
raise ImageComparisonFailure(
492492
"Image sizes do not match expected size: {} "
493-
"actual size {}".format(expectedImage.shape, actualImage.shape))
494-
absDiffImage = np.abs(expectedImage - actualImage)
493+
"actual size {}".format(expected_image.shape, actual_image.shape))
494+
abs_diff_image = np.abs(expected_image - actual_image)
495495

496496
# expand differences in luminance domain
497-
absDiffImage *= 255 * 10
498-
save_image_np = np.clip(absDiffImage, 0, 255).astype(np.uint8)
497+
abs_diff_image *= 255 * 10
498+
save_image_np = np.clip(abs_diff_image, 0, 255).astype(np.uint8)
499499
height, width, depth = save_image_np.shape
500500

501501
# The PDF renderer doesn't produce an alpha channel, but the

lib/matplotlib/testing/decorators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def _image_directories(func):
487487
return str(baseline_dir), str(result_dir)
488488

489489

490+
@cbook.deprecated("3.1", alternative="pytest.mark.backend")
490491
def switch_backend(backend):
491492

492493
def switch_backend_decorator(func):

0 commit comments

Comments
 (0)