diff --git a/doc/api/next_api_changes/2018-11-24-AL.rst b/doc/api/next_api_changes/2018-11-24-AL.rst new file mode 100644 index 000000000000..ed5f50ff3c26 --- /dev/null +++ b/doc/api/next_api_changes/2018-11-24-AL.rst @@ -0,0 +1,10 @@ +API changes +``````````` +The arguments of `matplotlib.testing.compare.calculate_rms` have been renamed +from ``expectedImage, actualImage``, to ``expected_image, actual_image``. + +Deprecations +```````````` +The ``matplotlib.testing.decorators.switch_backend`` decorator is deprecated. +Test functions should use ``pytest.mark.backend(...)``, and the mark will be +picked up by the ``matplotlib.testing.conftest.mpl_test_settings`` fixture. diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index 42092dafd7b5..9bab7e02c4d6 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -352,14 +352,14 @@ def crop_to_same(actual_path, actual_image, expected_path, expected_image): return actual_image, expected_image -def calculate_rms(expectedImage, actualImage): +def calculate_rms(expected_image, actual_image): "Calculate the per-pixel errors, then compute the root mean square error." - if expectedImage.shape != actualImage.shape: + if expected_image.shape != actual_image.shape: raise ImageComparisonFailure( "Image sizes do not match expected size: {} " - "actual size {}".format(expectedImage.shape, actualImage.shape)) + "actual size {}".format(expected_image.shape, actual_image.shape)) # Convert to float to avoid overflowing finite integer types. - return np.sqrt(((expectedImage - actualImage).astype(float) ** 2).mean()) + return np.sqrt(((expected_image - actual_image).astype(float) ** 2).mean()) def compare_images(expected, actual, tol, in_decorator=False): @@ -428,26 +428,26 @@ def compare_images(expected, actual, tol, in_decorator=False): expected = convert(expected, True) # open the image files and remove the alpha channel (if it exists) - expectedImage = _png.read_png_int(expected) - actualImage = _png.read_png_int(actual) - expectedImage = expectedImage[:, :, :3] - actualImage = actualImage[:, :, :3] + expected_image = _png.read_png_int(expected) + actual_image = _png.read_png_int(actual) + expected_image = expected_image[:, :, :3] + actual_image = actual_image[:, :, :3] - actualImage, expectedImage = crop_to_same( - actual, actualImage, expected, expectedImage) + actual_image, expected_image = crop_to_same( + actual, actual_image, expected, expected_image) diff_image = make_test_filename(actual, 'failed-diff') if tol <= 0: - if np.array_equal(expectedImage, actualImage): + if np.array_equal(expected_image, actual_image): return None # convert to signed integers, so that the images can be subtracted without # overflow - expectedImage = expectedImage.astype(np.int16) - actualImage = actualImage.astype(np.int16) + expected_image = expected_image.astype(np.int16) + actual_image = actual_image.astype(np.int16) - rms = calculate_rms(expectedImage, actualImage) + rms = calculate_rms(expected_image, actual_image) if rms <= tol: return None @@ -481,21 +481,21 @@ def save_diff_image(expected, actual, output): File path to save difference image to. ''' # Drop alpha channels, similarly to compare_images. - expectedImage = _png.read_png(expected)[..., :3] - actualImage = _png.read_png(actual)[..., :3] - actualImage, expectedImage = crop_to_same( - actual, actualImage, expected, expectedImage) - expectedImage = np.array(expectedImage).astype(float) - actualImage = np.array(actualImage).astype(float) - if expectedImage.shape != actualImage.shape: + expected_image = _png.read_png(expected)[..., :3] + actual_image = _png.read_png(actual)[..., :3] + actual_image, expected_image = crop_to_same( + actual, actual_image, expected, expected_image) + expected_image = np.array(expected_image).astype(float) + actual_image = np.array(actual_image).astype(float) + if expected_image.shape != actual_image.shape: raise ImageComparisonFailure( "Image sizes do not match expected size: {} " - "actual size {}".format(expectedImage.shape, actualImage.shape)) - absDiffImage = np.abs(expectedImage - actualImage) + "actual size {}".format(expected_image.shape, actual_image.shape)) + abs_diff_image = np.abs(expected_image - actual_image) # expand differences in luminance domain - absDiffImage *= 255 * 10 - save_image_np = np.clip(absDiffImage, 0, 255).astype(np.uint8) + abs_diff_image *= 255 * 10 + save_image_np = np.clip(abs_diff_image, 0, 255).astype(np.uint8) height, width, depth = save_image_np.shape # The PDF renderer doesn't produce an alpha channel, but the diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index 3d2cfb8f664f..989cc566bf5f 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -487,6 +487,7 @@ def _image_directories(func): return str(baseline_dir), str(result_dir) +@cbook.deprecated("3.1", alternative="pytest.mark.backend") def switch_backend(backend): def switch_backend_decorator(func):