Skip to content

Commit 06fbc43

Browse files
committed
test + coverage
1 parent 160447d commit 06fbc43

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

mne_bids/tests/test_write.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import pandas as pd
2525
import pytest
2626
from mne.datasets import testing
27-
from mne.io import anonymize_info
27+
from mne.io import anonymize_info, read_raw_edf
2828
from mne.io.constants import FIFF
2929
from mne.io.kit.kit import get_kit_info
3030
from mne.utils import check_version
@@ -3455,6 +3455,42 @@ def test_convert_eeg_formats(dir_name, fmt, fname, reader, tmp_path):
34553455
assert_array_almost_equal(raw.get_data(), raw2.get_data()[:, :orig_len], decimal=6)
34563456

34573457

3458+
def test_anonymize_and_convert_to_edf(tmp_path):
3459+
"""Test anonymization if converting to EDF (different codepath than EDF → EDF)."""
3460+
bids_root = tmp_path / "EDF"
3461+
raw_fname = data_path / "NihonKohden" / "MB0400FU.EEG"
3462+
bids_path = _bids_path.copy().update(root=bids_root, datatype="eeg")
3463+
raw = _read_raw_nihon(raw_fname)
3464+
3465+
with (
3466+
pytest.warns(RuntimeWarning, match="limits `startdate` to dates after 1985"),
3467+
pytest.warns(RuntimeWarning, match="Converting data files to EDF format"),
3468+
):
3469+
bids_output_path = write_raw_bids(
3470+
raw=raw,
3471+
format="EDF",
3472+
bids_path=bids_path,
3473+
overwrite=True,
3474+
verbose=False,
3475+
anonymize=dict(daysback=41234),
3476+
)
3477+
# make sure the written EDF file is valid
3478+
direct_read = read_raw_edf(bids_output_path.fpath)
3479+
assert direct_read.info["meas_date"] == datetime(1985, 1, 1, tzinfo=timezone.utc)
3480+
# make sure MNE-BIDS replaced the 1985-1-1 date with the date from scans.tsv
3481+
bids_read = read_raw_bids(bids_output_path)
3482+
bids_output_path.update(
3483+
suffix="scans",
3484+
extension=".tsv",
3485+
task=None,
3486+
acquisition=None,
3487+
run=None,
3488+
datatype=None,
3489+
)
3490+
scans = _from_tsv(bids_output_path.fpath)
3491+
assert bids_read.info["meas_date"] == datetime.fromisoformat(scans["acq_time"][0])
3492+
3493+
34583494
@pytest.mark.parametrize("dir_name, fmt, fname, reader", test_converteeg_data)
34593495
@pytest.mark.filterwarnings(
34603496
warning_str["channel_unit_changed"],

0 commit comments

Comments
 (0)