There is another test failing.
=========================================================== test session starts ============================================================
platform darwin -- Python 2.7.10 -- pytest-2.5.1
Running tests with Astropy version 1.1.dev13304.
Running tests in astroplan /Users/bsipocz/munka/devel/astroplan/docs.
Platform: Darwin-14.5.0-x86_64-i386-64bit
Executable: /Users/bsipocz/.virtualenvs/astropy-dev/bin/python
Full Python Version:
2.7.10 (default, May 26 2015, 20:29:34)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]
encodings: sys: ascii, locale: UTF-8, filesystem: utf-8, unicode bits: 15
byteorder: little
float info: dig: 15, mant_dig: 15
Numpy: 1.9.2
Scipy: 0.16.0
Matplotlib: 1.4.3
pyephem: not available
____________________________________________________________ test_image_example ____________________________________________________________
args = (), kwargs = {}
baseline_dir = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroplan-test-qX407r/lib.macosx-10.10-x86_64-2.7/astroplan/plots/tests/baseline_images'
inspect = <module 'inspect' from '/sw/lib/python2.7/inspect.pyc'>, fig = <matplotlib.figure.Figure object at 0x109d9f8d0>
filename = 'test_image_example.png', result_dir = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT'
test_image = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/test_image_example.png'
baseline_image_ref = '/private/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/astroplan-test-qX407r/lib.macosx-10.10-x86_64-2.7/astroplan/plots/tests/baseline_images/test_image_example.png'
baseline_image = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/baseline-test_image_example.png'
@wraps(item.function)
def item_function_wrapper(*args, **kwargs):
baseline_dir = compare.kwargs.get('baseline_dir', None)
if baseline_dir is None:
if self.baseline_dir is None:
baseline_dir = os.path.join(os.path.dirname(item.fspath.strpath), 'baseline')
else:
baseline_dir = self.baseline_dir
else:
baseline_dir = os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir)
# Run test and get figure object
import inspect
if inspect.ismethod(original): # method
fig = original(*args[1:], **kwargs)
else: # function
fig = original(*args, **kwargs)
# Find test name to use as plot name
filename = compare.kwargs.get('filename', None)
if filename is None:
filename = original.__name__ + '.png'
# What we do now depends on whether we are generating the reference
# images or simply running the test.
if self.generate_dir is None:
# Save the figure
result_dir = tempfile.mkdtemp()
test_image = os.path.abspath(os.path.join(result_dir, filename))
fig.savefig(test_image, **savefig_kwargs)
# Find path to baseline image
baseline_image_ref = os.path.abspath(os.path.join(os.path.dirname(item.fspath.strpath), baseline_dir, filename))
if not os.path.exists(baseline_image_ref):
raise Exception("""Image file not found for comparison test
Generated Image:
\t{test}
This is expected for new tests.""".format(
test=test_image))
# distutils may put the baseline images in non-accessible places,
# copy to our tmpdir to be sure to keep them in case of failure
baseline_image = os.path.abspath(os.path.join(result_dir, 'baseline-' + filename))
shutil.copyfile(baseline_image_ref, baseline_image)
> msg = compare_images(baseline_image, test_image, tol=tolerance)
/sw/lib/python2.7/site-packages/pytest_mpl/plugin.py:141:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expected = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/baseline-test_image_example.png'
actual = '/var/folders/dc/hsm7tqpx2d57n7vb3k1l81xw0000gq/T/tmprKJJFT/test_image_example.png', tol = 2, in_decorator = False
def compare_images(expected, actual, tol, in_decorator=False):
"""
Compare two "image" files checking differences within a tolerance.
The two given filenames may point to files which are convertible to
PNG via the `.converter` dictionary. The underlying RMS is calculated
with the `.calculate_rms` function.
Parameters
----------
expected : str
The filename of the expected image.
actual :str
The filename of the actual image.
tol : float
The tolerance (a color value difference, where 255 is the
maximal difference). The test fails if the average pixel
difference is greater than this value.
in_decorator : bool
If called from image_comparison decorator, this should be
True. (default=False)
Example
-------
img1 = "./baseline/plot.png"
img2 = "./output/plot.png"
compare_images( img1, img2, 0.001 ):
"""
if not os.path.exists(actual):
msg = "Output image %s does not exist." % actual
raise Exception(msg)
if os.stat(actual).st_size == 0:
msg = "Output image file %s is empty." % actual
raise Exception(msg)
verify(actual)
# Convert the image to png
extension = expected.split('.')[-1]
if not os.path.exists(expected):
raise IOError('Baseline image %r does not exist.' % expected)
if extension != 'png':
actual = convert(actual, 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]
actualImage, expectedImage = crop_to_same(
actual, actualImage, expected, expectedImage)
# convert to signed integers, so that the images can be subtracted without
# overflow
expectedImage = expectedImage.astype(np.int16)
actualImage = actualImage.astype(np.int16)
> rms = calculate_rms(expectedImage, actualImage)
/sw/lib/python2.7/site-packages/matplotlib/testing/compare.py:326:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
expectedImage = array([[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
...55, 255, 255],
[255, 255, 255],
[255, 255, 255]]], dtype=int16)
actualImage = array([[[255, 255, 255],
[255, 255, 255],
[255, 255, 255],
...55, 255, 255],
[255, 255, 255],
[255, 255, 255]]], dtype=int16)
def calculate_rms(expectedImage, actualImage):
"Calculate the per-pixel errors, then compute the root mean square error."
num_values = np.prod(expectedImage.shape)
> abs_diff_image = abs(expectedImage - actualImage)
E ValueError: operands could not be broadcast together with shapes (600,800,3) (660,880,3)
/sw/lib/python2.7/site-packages/matplotlib/testing/compare.py:246: ValueError