Skip to content

Commit

Permalink
Added real image testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
pelson committed Sep 24, 2012
1 parent b6643e5 commit a737dc4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ lib/iris/etc/site.cfg
lib/iris/fileformats/_pyke_rules/compiled_krb/
lib/iris/std_names.py

# Iris test result files
lib/iris/tests/result_image_comparison/

# Pydev/Eclipse files
.project
Expand Down
25 changes: 24 additions & 1 deletion lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import zlib

import matplotlib
import matplotlib.testing.compare as mcompare
# NB pyplot is imported after main() so that a backend can be defined.
# import matplotlib.pyplot as plt
import numpy
Expand Down Expand Up @@ -361,14 +362,36 @@ def _get_image_checksum(self, unique_id, resultant_checksum):
open(checksum_result_path, 'w').writelines(str(checksum))
return checksum

def check_graphic(self):
def check_graphic(self, tol=0):
"""Checks the CRC matches for the current matplotlib.pyplot figure, and closes the figure."""

unique_id = self._unique_id()

figure = plt.gcf()

try:
expected_fname = os.path.join(os.path.dirname(__file__), 'results', 'visual_tests', unique_id + '.png')

if not os.path.isdir(os.path.dirname(expected_fname)):
os.makedirs(os.path.dirname(expected_fname))

result_fname = os.path.join(os.path.dirname(__file__), 'result_image_comparison', 'result-' + unique_id + '.png')

if not os.path.isdir(os.path.dirname(result_fname)):
os.makedirs(os.path.dirname(result_fname))

figure.savefig(result_fname)

if not os.path.exists(expected_fname):
warnings.warn('Created image for test %s' % unique_id)
shutil.copy2(result_fname, expected_fname)

err = mcompare.compare_images(expected_fname, result_fname, tol=tol)

assert not err, 'Image comparison failed. Message: %s' % err

# Old checksum stuff. Still passing. Will be removed.

suffix = '.png'
if _SAVE_FIGURES:
file_path = os.path.join('image_results', unique_id) + suffix
Expand Down

0 comments on commit a737dc4

Please sign in to comment.