MCPcopy Create free account
hub / github.com/mne-tools/mne-python / dummy_annotation_file

Function dummy_annotation_file

mne/tests/test_annotations.py:997–1046  ·  view source on GitHub ↗

Create csv file for testing.

(tmp_path_factory, ch_names, fmt, with_extras)

Source from the content-addressed store, hash-verified

995
996@pytest.fixture(scope="function", params=("ch_names", "fmt", "with_extras"))
997def dummy_annotation_file(tmp_path_factory, ch_names, fmt, with_extras):
998 """Create csv file for testing."""
999 extras_row0 = {"foo1": 1, "foo2": 1.1, "foo3": "a", "foo4": None}
1000 if fmt == "csv":
1001 content = (
1002 "onset,duration,description\n"
1003 "2002-12-03 19:01:11.720100,1.0,AA\n"
1004 "2002-12-03 19:01:20.720100,2.425,BB"
1005 )
1006 elif fmt == "txt":
1007 content = (
1008 "# MNE-Annotations\n"
1009 "# orig_time : 2002-12-03 19:01:11.720100\n"
1010 "# onset, duration, description\n"
1011 "0, 1, AA \n"
1012 "9, 2.425, BB"
1013 )
1014 else:
1015 assert fmt == "fif"
1016 extras = [extras_row0, None] if with_extras else None
1017 content = Annotations(
1018 [0, 9], [1, 2.425], ["AA", "BB"], orig_time=_ORIG_TIME, extras=extras
1019 )
1020
1021 if ch_names:
1022 if isinstance(content, Annotations):
1023 # this is a bit of a hack but it works
1024 content.ch_names[:] = ((), ("MEG0111", "MEG2563"))
1025 else:
1026 content = content.splitlines()
1027 content[-3] += ",ch_names"
1028 content[-2] += ","
1029 content[-1] += ",MEG0111:MEG2563"
1030 content = "\n".join(content)
1031 if with_extras and fmt != "fif":
1032 content = content.splitlines()
1033 content[-3] += "," + ",".join(extras_row0.keys())
1034 content[-2] += "," + ",".join(
1035 ["" if v is None else str(v) for v in extras_row0.values()]
1036 )
1037 content[-1] += ",,,,"
1038 content = "\n".join(content)
1039
1040 fname = tmp_path_factory.mktemp("data") / f"annotations-annot.{fmt}"
1041 if isinstance(content, str):
1042 with open(fname, "w") as f:
1043 f.write(content)
1044 else:
1045 content.save(fname)
1046 return fname
1047
1048
1049@pytest.mark.filterwarnings("ignore:.*heterogeneous dtypes.*")

Callers

nothing calls this directly

Calls 3

saveMethod · 0.95
AnnotationsClass · 0.90
writeMethod · 0.80

Tested by

no test coverage detected