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
29 changes: 21 additions & 8 deletions lib/iris/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import subprocess
import sys
import threading
from typing import Dict, List
import unittest
from unittest import mock
import warnings
Expand Down Expand Up @@ -878,7 +879,9 @@ def check_graphic(self):
unique_id = self._unique_id()
repo_fname = os.path.join(_RESULT_PATH, "imagerepo.json")
with open(repo_fname, "rb") as fi:
repo = json.load(codecs.getreader("utf-8")(fi))
repo: Dict[str, List[str]] = json.load(
codecs.getreader("utf-8")(fi)
)

try:
#: The path where the images generated by the tests should go.
Expand Down Expand Up @@ -949,13 +952,16 @@ def _create_missing():
phash = imagehash.phash(Image.open(buffer), hash_size=_HASH_SIZE)

if unique_id not in repo:
if dev_mode:
_create_missing()
else:
figure.savefig(result_fname)
emsg = "Missing image test result: {}."
raise AssertionError(emsg.format(unique_id))
else:
# The unique id might not be fully qualified, e.g.
# expects iris.tests.test_quickplot.TestLabels.test_contour.0,
# but got test_quickplot.TestLabels.test_contour.0
# if we find single partial match from end of the key
# then use that, else fall back to the unknown id state.
matches = [key for key in repo if key.endswith(unique_id)]
if len(matches) == 1:
unique_id = matches[0]

if unique_id in repo:
uris = repo[unique_id]
# Extract the hex basename strings from the uris.
hexes = [
Expand Down Expand Up @@ -984,6 +990,13 @@ def _create_missing():
else:
emsg = "Image comparison failed: {}"
raise AssertionError(emsg.format(msg))
else:
if dev_mode:
_create_missing()
else:
figure.savefig(result_fname)
emsg = "Missing image test result: {}."
raise AssertionError(emsg.format(unique_id))

if _DISPLAY_FIGURES:
plt.show()
Expand Down