Skip to content
Merged
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
22 changes: 15 additions & 7 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,6 @@ 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))
Expand Down Expand Up @@ -702,13 +700,17 @@ def check_graphic(self, tol=None):
if err.errno != 17:
raise

figure.savefig(result_fname)
def save_figure_hash():
figure = plt.gcf()
figure.savefig(result_fname)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marqh plt.gcf().savefig(result_fname) works for me ... but I don't see the point in making such a cosmetic change here in this PR.

I'm going to have to rebase #2192 with this anyways, so I can tweak away in my PR 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a cosmetic change

previously the figure = plt.gcf() and figure.savefig(result_fname) were in the code, a little way apart.

i moved them together, without changing either line

minor point tho


# XXX: Deal with a new test result i.e. it's not in the repo
# hash the created image using sha1
with open(result_fname, 'rb') as res_file:
sha1 = hashlib.sha1(res_file.read())
return sha1

sha1 = save_figure_hash()

# hash the created image using sha1
with open(result_fname, 'rb') as res_file:
sha1 = hashlib.sha1(res_file.read())
if unique_id not in repo:
msg = 'Image comparison failed: Created image {} for test {}.'
raise ValueError(msg.format(result_fname, unique_id))
Expand All @@ -719,6 +721,12 @@ def check_graphic(self, tol=None):
expected = [os.path.splitext(os.path.basename(uri))[0]
for uri in uris]

if sha1.hexdigest() not in expected:
# This can be an accidental failure, unusual, but it occurs
# https://github.com/SciTools/iris/issues/2195
# retry once, in case it passes second time round.
sha1 = save_figure_hash()

if sha1.hexdigest() not in expected:
emsg = 'Actual SHA1 {} not in expected {} for test {}.'
emsg = emsg.format(sha1.hexdigest(), expected, unique_id)
Expand Down