Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
from six.moves import (filter, input, map, range, zip) # noqa
import six

import codecs
import collections
import contextlib
import difflib
import filecmp
import functools
import gzip
import hashlib
import inspect
import json
import io
import logging
import os
Expand Down Expand Up @@ -666,15 +669,12 @@ def check_graphic(self, tol=None):
unique_id = self._unique_id()

figure = plt.gcf()

repo_fname = os.path.join(os.path.dirname(__file__), 'results', 'imagerepo.json')
with open(repo_fname, 'rb') as fi:
repo = json.load(codecs.getreader('utf-8')(fi))

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))

#: The path where the images generated by the tests should go.
image_output_directory = os.path.join(os.path.dirname(__file__),
'result_image_comparison')
Expand Down Expand Up @@ -703,24 +703,25 @@ def check_graphic(self, tol=None):

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)
# XXX: Deal with a new test result i.e. it's not in the repo

# hash the created image using sha1
import hashlib
with open(result_fname, 'rb') as res_file:
sha1 = hashlib.sha1(res_file.read())

err = ''

with open(expected_fname, 'rb') as exp_file:
exp_sha1 = hashlib.sha1(exp_file.read())
exp_sha1_list = known_sha1_values[unique_id]
if sha1.hexdigest() != exp_sha1.hexdigest():
# if sha1.hexdigest() not in exp_sha1_list:
err = 'Image file SHA1: {}\n not equal to expected SHA1:{}\n '
err = err.format(sha1.hexdigest(), exp_sha1.hexdigest())

# XXX: Deal with more than one expected hash ...
try:
ehash = repo[unique_id][0]
exp_sha1 = os.path.splitext(os.path.basename(ehash))[0]
except KeyError:
emsg = 'Missing image repo entry for "{}"'.format(unique_id)
raise ValueError(emsg)

if sha1.hexdigest() != exp_sha1:
err = 'Actual SHA1 "{}" != expected SHA1 "{}" for test "{}"'
err = err.format(sha1.hexdigest(), exp_sha1, unique_id)

if _DISPLAY_FIGURES:
if err:
Expand Down
Loading