From a53d676491597c8c02354a5a3ec23e88b78b1cb9 Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 6 Nov 2025 14:40:39 -0600 Subject: [PATCH 1/2] split preload test --- mne_bids/tests/test_write.py | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index d253c93ee..529235e09 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -103,6 +103,8 @@ "ignore:Channel mismatch between .*channels\\.tsv and the raw data file " "detected\\.:RuntimeWarning:mne" ), + converting_to_edf=r"ignore:Converting data files to [BE]DF format:RuntimeWarning", + edf_date="ignore:.*limits dates to after 1985-01-01:RuntimeWarning", ) @@ -3749,8 +3751,8 @@ def test_write_associated_emptyroom(_bids_validate, tmp_path, empty_room_dtype): assert meg_json_data["AssociatedEmptyRoom"] == expected_rel -def test_preload(_bids_validate, tmp_path): - """Test writing custom preloaded raw objects.""" +def test_preload_errors(tmp_path): + """Test allow_preload error handling.""" bids_root = tmp_path / "bids" bids_path = _bids_path.copy().update(root=bids_root) sfreq, n_points = 1024.0, int(1e6) @@ -3760,21 +3762,35 @@ def test_preload(_bids_validate, tmp_path): raw.orig_format = "single" raw.info["line_freq"] = 60 + shared_kwargs = dict(raw=raw, bids_path=bids_path, verbose=False, overwrite=True) # reject preloaded by default with pytest.raises(ValueError, match="allow_preload"): - write_raw_bids(raw, bids_path, verbose=False, overwrite=True) + write_raw_bids(**shared_kwargs) # preloaded raw must specify format with pytest.raises(ValueError, match="format"): - write_raw_bids( - raw, bids_path, allow_preload=True, verbose=False, overwrite=True - ) + write_raw_bids(**shared_kwargs, allow_preload=True) + +@pytest.mark.filterwarnings( + warning_str["converting_to_edf"], + warning_str["edfblocks"], +) +@pytest.mark.parametrize("format,ch_type", (("BrainVision", "eeg"), ("EDF", "seeg"))) +def test_preload(_bids_validate, tmp_path, format, ch_type): + """Test writing custom preloaded raw objects.""" + bids_root = tmp_path / "bids" + bids_path = _bids_path.copy().update(root=bids_root) + sfreq = 1024.0 + info = mne.create_info(["ch1", "ch2"], sfreq, ch_type) + raw = mne.io.RawArray(np.zeros((2, 100), dtype=np.float32), info) + raw.orig_format = "single" + raw.info["line_freq"] = 60 write_raw_bids( raw, bids_path, allow_preload=True, - format="BrainVision", + format=format, verbose=False, overwrite=True, ) From baebd12e1e8ee65464917e3ee6e7246123b0087b Mon Sep 17 00:00:00 2001 From: Daniel McCloy Date: Thu, 6 Nov 2025 16:36:26 -0600 Subject: [PATCH 2/2] fix test --- mne_bids/tests/test_write.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index 529235e09..d214af262 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -3783,7 +3783,9 @@ def test_preload(_bids_validate, tmp_path, format, ch_type): bids_path = _bids_path.copy().update(root=bids_root) sfreq = 1024.0 info = mne.create_info(["ch1", "ch2"], sfreq, ch_type) - raw = mne.io.RawArray(np.zeros((2, 100), dtype=np.float32), info) + data = np.zeros((2, 100), dtype=np.float32) + data[0, 5] = 1.0 # avoid physical_min == physical_max + raw = mne.io.RawArray(data, info) raw.orig_format = "single" raw.info["line_freq"] = 60 write_raw_bids(