From 0806a1ffe91fa821b4e2da23855d78fa93e20100 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 10 Jan 2024 10:08:30 -0500 Subject: [PATCH] FIX: Correct order --- mne/_fiff/open.py | 3 +-- mne/_fiff/tag.py | 6 +----- mne/commands/tests/test_commands.py | 13 +++++++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mne/_fiff/open.py b/mne/_fiff/open.py index ed9a640e706..16d69e280d4 100644 --- a/mne/_fiff/open.py +++ b/mne/_fiff/open.py @@ -137,7 +137,6 @@ def fiff_open(fname, preload=False, verbose=None): raise -# @profile def _fiff_open(fname, fid, preload): # do preloading of entire file if preload: @@ -315,7 +314,7 @@ def _show_tree( for k, kn, size, pos, type_ in zip(kinds[:-1], kinds[1:], sizes, poss, types): if not tag_found and k != tag_id: continue - tag = Tag(k, size, 0, -1, pos) + tag = Tag(kind=k, type=type_, size=size, next=FIFF.FIFFV_NEXT_NONE, pos=pos) if read_limit is None or size <= read_limit: try: tag = read_tag(fid, pos) diff --git a/mne/_fiff/tag.py b/mne/_fiff/tag.py index 727d7bb497d..e1ae5ae571a 100644 --- a/mne/_fiff/tag.py +++ b/mne/_fiff/tag.py @@ -424,7 +424,7 @@ def _read_julian(fid, tag, shape, rlims): _call_dict_names[key] = dtype -def read_tag(fid, pos, shape=None, rlims=None, *, advance=True): +def read_tag(fid, pos, shape=None, rlims=None): """Read a Tag from a file at a given position. Parameters @@ -441,10 +441,6 @@ def read_tag(fid, pos, shape=None, rlims=None, *, advance=True): Note that data are assumed to be stored row-major in the file. Only to be used with data stored as a vector (not implemented for matrices yet). - advance : bool - If True (default), advance to next tag position after reading. - - .. versionadded:: 1.7 Returns ------- diff --git a/mne/commands/tests/test_commands.py b/mne/commands/tests/test_commands.py index ea87c717db0..ac7ffe60ac3 100644 --- a/mne/commands/tests/test_commands.py +++ b/mne/commands/tests/test_commands.py @@ -43,7 +43,7 @@ mne_what, ) from mne.datasets import testing -from mne.io import read_info, read_raw_fif +from mne.io import read_info, read_raw_fif, show_fiff from mne.utils import ( ArgvSetter, _record_warnings, @@ -100,13 +100,22 @@ def test_compare_fiff(): check_usage(mne_compare_fiff) -def test_show_fiff(): +def test_show_fiff(tmp_path): """Test mne compare_fiff.""" check_usage(mne_show_fiff) with ArgvSetter((raw_fname,)): mne_show_fiff.run() with ArgvSetter((raw_fname, "--tag=102")): mne_show_fiff.run() + bad_fname = tmp_path / "test_bad_raw.fif" + with open(bad_fname, "wb") as fout: + with open(raw_fname, "rb") as fin: + fout.write(fin.read(100000)) + with pytest.warns(RuntimeWarning, match="Invalid tag"): + lines = show_fiff(str(bad_fname), output=list) + last_line = lines[-1] + assert ">>>>BAD" in last_line + assert "302 = FIFF_EPOCH (734412b >f4)" in last_line @requires_mne