@@ -83,7 +83,7 @@ def diff_viewer(repo, key, repo_fname, phash, status,
8383
8484 result_dir = os .path .dirname (result_fname )
8585 fname = '{}.png' .format (phash )
86- base_uri = 'https://scitools.github.io/test-iris-imagehash/images/{}'
86+ base_uri = 'https://scitools.github.io/test-iris-imagehash/images/v4/ {}'
8787 uri = base_uri .format (fname )
8888 phash_fname = os .path .join (result_dir , fname )
8989
@@ -139,77 +139,27 @@ def skip(event):
139139
140140
141141def _calculate_hit (uris , phash , action ):
142+ # Extract the hex basename strings from the uris.
142143 hexes = [os .path .splitext (os .path .basename (uri ))[0 ] for uri in uris ]
143- # See https://github.com/JohannesBuchner/imagehash#changelog
144- # for details on imagehash release v4.0 old_hex_to_hash() fix.
145- hex_fix_available = hasattr (imagehash , 'old_hex_to_hash' )
144+ # Create the expected perceptual image hashes from the uris.
146145 to_hash = imagehash .hex_to_hash
147-
148- if hex_fix_available :
149- # Note that, the "hash_size" kwarg is unavailable and old
150- # style hashes will not be corrected.
151- expected = [to_hash (uri_hex ) for uri_hex in hexes ]
152- # Calculate the hamming distance vector for the result hash.
153- dnew = [e - phash for e in expected ]
154- # Retry, correcting old hex strings. Note that, the
155- # "hash_size" kwarg is required.
156- to_hash = imagehash .old_hex_to_hash
157- expected = [to_hash (uri_hex , hash_size = iris .tests ._HASH_SIZE )
158- for uri_hex in hexes ]
159- # Calculate the hamming distance vector for the result hash.
160- dold = [e - phash for e in expected ]
161- else :
162- # The version of imagehash will be prior to v4.0, so the
163- # "hash_size" kwarg is required.
164- expected = [to_hash (uri_hex , hash_size = iris .tests ._HASH_SIZE )
165- for uri_hex in hexes ]
166- dold = [e - phash for e in expected ]
167-
168- dmsg = '{} (old={})' if hex_fix_available else '{}'
146+ expected = [to_hash (uri_hex ) for uri_hex in hexes ]
147+ # Calculate the hamming distance vector for the result hash.
148+ distances = [e - phash for e in expected ]
169149
170150 if action == 'first' :
171151 index = 0
172- if hex_fix_available :
173- distance = dmsg .format (dnew [index ], dold [index ])
174- else :
175- distance = dmsg .format (dold [index ])
176152 elif action == 'last' :
177153 index = - 1
178- if hex_fix_available :
179- distance = dmsg .format (dnew [index ], dold [index ])
180- else :
181- distance = dmsg .format (dold [index ])
182154 elif action == 'similar' :
183- if hex_fix_available :
184- inew , iold = np .argmin (dnew ), np .argmin (dold )
185- vnew , vold = dnew [inew ], dold [iold ]
186- if vnew <= vold :
187- index = inew
188- distance = '{} (old={})' .format (vnew , vold )
189- else :
190- index = iold
191- distance = '{} (new={})' .format (vold , vnew )
192- else :
193- index = np .argmin (dold )
194- distance = '{}' .format (dold [index ])
155+ index = np .argmin (distances )
195156 elif action == 'different' :
196- if hex_fix_available :
197- inew , iold = np .argmax (dnew ), np .argmax (dold )
198- vnew , vold = dnew [inew ], dold [iold ]
199- if vnew >= vold :
200- index = inew
201- distance = '{} (old={})' .format (vnew , vold )
202- else :
203- index = iold
204- distance = '{} (new={})' .format (vold , vnew )
205- else :
206- index = np .argmax (dold )
207- distance = '{}' .format (dold [index ])
157+ index = np .argmax (distances )
208158 else :
209159 emsg = 'Unknown action: {!r}'
210160 raise ValueError (emsg .format (action ))
211161
212- return index , distance
162+ return index , distances [ index ]
213163
214164
215165def step_over_diffs (result_dir , action , display = True ):
@@ -282,7 +232,7 @@ def step_over_diffs(result_dir, action, display=True):
282232 os .path .basename (uri ))
283233 if not os .path .isfile (local_fname ):
284234 emsg = 'Bad URI {!r} for test {!r}.'
285- raise ValueError (uri , key )
235+ raise ValueError (emsg . format ( uri , key ) )
286236 else :
287237 # The temporary expected filename has the test name
288238 # baked into it, and is used in the diff plot title.
0 commit comments