Skip to content

Commit 5098133

Browse files
committed
TEST: Unroll hash check, do not run unnecessarily
1 parent 2596179 commit 5098133

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

nibabel/freesurfer/tests/test_io.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import warnings
88
from os.path import isdir
99
from os.path import join as pjoin
10+
from pathlib import Path
1011

1112
import numpy as np
1213
import pytest
@@ -46,14 +47,6 @@
4647
)
4748

4849

49-
def _hash_file_content(fname):
50-
hasher = hashlib.md5()
51-
with open(fname, 'rb') as afile:
52-
buf = afile.read()
53-
hasher.update(buf)
54-
return hasher.hexdigest()
55-
56-
5750
@freesurfer_test
5851
def test_geometry():
5952
"""Test IO of .surf"""
@@ -179,7 +172,6 @@ def test_annot():
179172
annots = ['aparc', 'aparc.a2005s']
180173
for a in annots:
181174
annot_path = pjoin(data_path, 'label', f'lh.{a}.annot')
182-
hash_ = _hash_file_content(annot_path)
183175

184176
labels, ctab, names = read_annot(annot_path)
185177
assert labels.shape == (163842,)
@@ -190,9 +182,10 @@ def test_annot():
190182
labels_orig, _, _ = read_annot(annot_path, orig_ids=True)
191183
np.testing.assert_array_equal(labels == -1, labels_orig == 0)
192184
# Handle different version of fsaverage
193-
if hash_ == 'bf0b488994657435cdddac5f107d21e8':
185+
content_hash = hashlib.md5(Path(annot_path).read_bytes()).hexdigest()
186+
if content_hash == 'bf0b488994657435cdddac5f107d21e8':
194187
assert np.sum(labels_orig == 0) == 13887
195-
elif hash_ == 'd4f5b7cbc2ed363ac6fcf89e19353504':
188+
elif content_hash == 'd4f5b7cbc2ed363ac6fcf89e19353504':
196189
assert np.sum(labels_orig == 1639705) == 13327
197190
else:
198191
raise RuntimeError(

0 commit comments

Comments
 (0)