MCPcopy
hub / github.com/mne-tools/mne-python / test_io_annotation

Function test_io_annotation

mne/tests/test_annotations.py:1053–1084  ·  view source on GitHub ↗

Test CSV, TXT, and FIF input/output (which support ch_names).

(dummy_annotation_file, tmp_path, fmt, ch_names, with_extras)

Source from the content-addressed store, hash-verified

1051@pytest.mark.parametrize("fmt", [pytest.param("csv", marks=needs_pandas), "txt", "fif"])
1052@pytest.mark.parametrize("with_extras", [True, False])
1053def test_io_annotation(dummy_annotation_file, tmp_path, fmt, ch_names, with_extras):
1054 """Test CSV, TXT, and FIF input/output (which support ch_names)."""
1055 if with_extras:
1056 pytest.importorskip("pandas")
1057 annot = read_annotations(dummy_annotation_file)
1058 assert annot.orig_time == _ORIG_TIME
1059 kwargs = dict(orig_time=_ORIG_TIME)
1060 if ch_names:
1061 kwargs["ch_names"] = ((), ("MEG0111", "MEG2563"))
1062 if with_extras:
1063 kwargs["extras"] = [
1064 {"foo1": 1, "foo2": 1.1, "foo3": "a", "foo4": None},
1065 None,
1066 ]
1067 _assert_annotations_equal(
1068 annot,
1069 Annotations([0.0, 9.0], [1.0, 2.425], ["AA", "BB"], **kwargs),
1070 tol=1e-6,
1071 comp_extras_as_str=fmt in ["csv", "txt"],
1072 )
1073
1074 # Now test writing
1075 fname = tmp_path / f"annotations-annot.{fmt}"
1076 annot.save(fname)
1077 annot2 = read_annotations(fname)
1078 _assert_annotations_equal(annot, annot2)
1079
1080 # Now without an orig_time
1081 annot._orig_time = None
1082 annot.save(fname, overwrite=True)
1083 annot2 = read_annotations(fname)
1084 _assert_annotations_equal(annot, annot2)
1085
1086
1087@pytest.mark.parametrize("fmt", [pytest.param("csv", marks=needs_pandas), "txt"])

Callers

nothing calls this directly

Calls 4

read_annotationsFunction · 0.90
AnnotationsClass · 0.90
saveMethod · 0.45

Tested by

no test coverage detected