1111from contextlib import nullcontext
1212from datetime import datetime , timezone
1313from pathlib import Path
14+ import contextlib
1415
1516import mne
1617import numpy as np
@@ -493,18 +494,7 @@ def test_get_head_mri_trans(tmp_path):
493494
494495
495496@testing .requires_testing_data
496- @pytest .mark .parametrize (
497- "with_extras" ,
498- [
499- False ,
500- pytest .param (
501- True ,
502- marks = pytest .mark .skipif (
503- not check_version ("mne" , "1.10" ), reason = "not implemented"
504- ),
505- ),
506- ],
507- )
497+ @pytest .mark .parametrize ("with_extras" , [False , True ])
508498def test_handle_events_reading (tmp_path , with_extras ):
509499 """Test reading events from a BIDS events.tsv file."""
510500 # We can use any `raw` for this
@@ -523,12 +513,25 @@ def test_handle_events_reading(tmp_path, with_extras):
523513 events_fname .parent .mkdir ()
524514 _to_tsv (events , events_fname )
525515
526- raw , event_id = _handle_events_reading (events_fname , raw )
516+ with (
517+ pytest .warns (
518+ RuntimeWarning ,
519+ match = (
520+ "The version of MNE-Python you are using (<1.10) "
521+ "does not support the extras argument in mne.Annotations. "
522+ "The extra column(s) ['foo'] will be ignored."
523+ ),
524+ )
525+ if with_extras and not check_version ("mne" , "1.10" )
526+ else contextlib .nullcontext ()
527+ ):
528+ raw , event_id = _handle_events_reading (events_fname , raw )
529+
527530 ev_arr , ev_dict = mne .events_from_annotations (raw )
528531 assert list (ev_dict .values ()) == [1 , 2 ] # auto-assigned
529532 want = len (events ["onset" ]) - 1 # one onset was n/a
530533 assert want == len (raw .annotations ) == len (ev_arr ) == len (ev_dict )
531- if with_extras :
534+ if with_extras and check_version ( "mne" , "1.10" ) :
532535 for d , v in zip (raw .annotations .extras , "abc" ):
533536 assert "foo" in d
534537 assert d ["foo" ] == v
@@ -873,9 +876,7 @@ def test_handle_chpi_reading(tmp_path):
873876 meg_json_data_freq_mismatch ["HeadCoilFrequency" ][0 ] = 123
874877 _write_json (meg_json_path , meg_json_data_freq_mismatch , overwrite = True )
875878
876- with (
877- pytest .warns (RuntimeWarning , match = "Defaulting to .* mne.Raw object" ),
878- ):
879+ with (pytest .warns (RuntimeWarning , match = "Defaulting to .* mne.Raw object" ),):
879880 raw_read = read_raw_bids (bids_path , extra_params = dict (allow_maxshield = "yes" ))
880881
881882 # cHPI "off" according to sidecar, but present in the data
@@ -1096,9 +1097,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
10961097 _to_tsv (electrodes_dict , electrodes_fname )
10971098 # popping off channels should not result in an error
10981099 # however, a warning will be raised through mne-python
1099- with (
1100- pytest .warns (RuntimeWarning , match = "DigMontage is only a subset of info" ),
1101- ):
1100+ with (pytest .warns (RuntimeWarning , match = "DigMontage is only a subset of info" ),):
11021101 read_raw_bids (bids_path = bids_fname , verbose = False )
11031102
11041103 # make sure montage is set if there are coordinates w/ 'n/a'
@@ -1114,9 +1113,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
11141113 # electrode coordinates should be nan
11151114 # when coordinate is 'n/a'
11161115 nan_chs = [electrodes_dict ["name" ][i ] for i in [0 , 3 ]]
1117- with (
1118- pytest .warns (RuntimeWarning , match = "There are channels without locations" ),
1119- ):
1116+ with (pytest .warns (RuntimeWarning , match = "There are channels without locations" ),):
11201117 raw = read_raw_bids (bids_path = bids_fname , verbose = False )
11211118 for idx , ch in enumerate (raw .info ["chs" ]):
11221119 if ch ["ch_name" ] in nan_chs :
@@ -1244,9 +1241,7 @@ def test_handle_non_mne_channel_type(tmp_path):
12441241 channels_data ["type" ][ch_idx ] = "FOOBAR"
12451242 _to_tsv (data = channels_data , fname = channels_tsv_path )
12461243
1247- with (
1248- pytest .warns (RuntimeWarning , match = 'will be set to "misc"' ),
1249- ):
1244+ with (pytest .warns (RuntimeWarning , match = 'will be set to "misc"' ),):
12501245 raw = read_raw_bids (bids_path )
12511246
12521247 # Should be a 'misc' channel.
0 commit comments