Skip to content

Commit

Permalink
DOC: Better error message (mne-tools#6099)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored and agramfort committed Mar 30, 2019
1 parent f384253 commit 87cb639
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions mne/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,13 +1835,15 @@ def _read_annot(fname):
raise IOError('Directory for annotation does not exist: %s',
fname)
cands = os.listdir(dir_name)
cands = [c for c in cands if '.annot' in c]
cands = sorted(set(c.lstrip('lh.').lstrip('rh.').rstrip('.annot')
for c in cands if '.annot' in c),
key=lambda x: x.lower())
if len(cands) == 0:
raise IOError('No such file %s, no candidate parcellations '
'found in directory' % fname)
else:
raise IOError('No such file %s, candidate parcellations in '
'that directory: %s' % (fname, ', '.join(cands)))
'that directory:\n%s' % (fname, '\n'.join(cands)))
with open(fname, "rb") as fid:
n_verts = np.fromfile(fid, '>i4', 1)[0]
data = np.fromfile(fid, '>i4', n_verts * 2).reshape(n_verts, 2)
Expand Down
5 changes: 3 additions & 2 deletions mne/tests/test_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,9 @@ def test_annot_io():
shutil.copy(os.path.join(surf_src, 'rh.white'), surf_dir)

# read original labels
pytest.raises(IOError, read_labels_from_annot, subject, 'PALS_B12_Lobesey',
subjects_dir=tempdir)
with pytest.raises(IOError, match='\nPALS_B12_Lobes$'):
read_labels_from_annot(subject, 'PALS_B12_Lobesey',
subjects_dir=tempdir)
labels = read_labels_from_annot(subject, 'PALS_B12_Lobes',
subjects_dir=tempdir)

Expand Down

0 comments on commit 87cb639

Please sign in to comment.