Skip to content

Commit d4ec7e9

Browse files
committed
more op to path conversions
1 parent 5d4320f commit d4ec7e9

File tree

3 files changed

+38
-64
lines changed

3 files changed

+38
-64
lines changed

mne_bids/tests/test_path.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def return_bids_test_dir(tmp_path_factory):
6464
"Smiley": 5,
6565
"Button": 32,
6666
}
67-
events_fname = op.join(
68-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
69-
)
67+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
7068
cal_fname = op.join(data_path, "SSS", "sss_cal_mgh.dat")
7169
crosstalk_fname = op.join(data_path, "SSS", "ct_sparse.fif")
7270

mne_bids/tests/test_read.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ def test_get_head_mri_trans(tmp_path):
226226
"""Test getting a trans object from BIDS data."""
227227
nib = pytest.importorskip("nibabel")
228228

229-
events_fname = op.join(
230-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
231-
)
229+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
232230
subjects_dir = op.join(data_path, "subjects")
233231

234232
# Drop unknown events.

mne_bids/tests/test_write.py

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_write_participants(_bids_validate, tmp_path):
217217
files are kept, and mne-bids correctly writes all
218218
the subject info it can using ``raw.info['subject_info']``.
219219
"""
220-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
220+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
221221
raw = _read_raw_fif(raw_fname)
222222

223223
# add fake participants data
@@ -319,7 +319,7 @@ def test_write_participants(_bids_validate, tmp_path):
319319
@testing.requires_testing_data
320320
def test_write_correct_inputs():
321321
"""Test that inputs of write_raw_bids is correct."""
322-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
322+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
323323
raw = _read_raw_fif(raw_fname)
324324

325325
bids_path_str = "sub-01_ses-01_meg.fif"
@@ -441,7 +441,7 @@ def test_stamp_to_dt():
441441
@testing.requires_testing_data
442442
def test_get_anonymization_daysback():
443443
"""Test daysback querying for anonymization."""
444-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
444+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
445445
raw = _read_raw_fif(raw_fname)
446446
daysback_min, daysback_max = _get_anonymization_daysback(raw)
447447
# max_val off by 1 on Windows for some reason
@@ -521,7 +521,7 @@ def test_fif(_bids_validate, tmp_path):
521521
pytest.importorskip("pybv", PYBV_VERSION)
522522
bids_root = tmp_path / "bids1"
523523
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg")
524-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
524+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
525525

526526
event_id = {
527527
"Auditory/Left": 1,
@@ -531,9 +531,7 @@ def test_fif(_bids_validate, tmp_path):
531531
"Smiley": 5,
532532
"Button": 32,
533533
}
534-
events_fname = op.join(
535-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
536-
)
534+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
537535

538536
# Drop unknown events.
539537
events = mne.read_events(events_fname)
@@ -899,7 +897,7 @@ def test_chpi(_bids_validate, tmp_path, fmt):
899897
def test_fif_dtype(_bids_validate, tmp_path):
900898
"""Test functionality of the write_raw_bids conversion for fif."""
901899
bids_path = _bids_path.copy().update(root=tmp_path, datatype="meg")
902-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
900+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
903901
desired_fmt = "int"
904902
raw = _read_raw_fif(raw_fname)
905903

@@ -919,7 +917,7 @@ def test_fif_anonymize(_bids_validate, tmp_path):
919917
"""Test write_raw_bids() with anonymization fif."""
920918
bids_root = tmp_path / "bids1"
921919
bids_path = _bids_path.copy().update(root=bids_root)
922-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
920+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
923921

924922
event_id = {
925923
"Auditory/Left": 1,
@@ -929,9 +927,7 @@ def test_fif_anonymize(_bids_validate, tmp_path):
929927
"Smiley": 5,
930928
"Button": 32,
931929
}
932-
events_fname = op.join(
933-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
934-
)
930+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
935931

936932
# Drop unknown events.
937933
events = mne.read_events(events_fname)
@@ -1006,7 +1002,7 @@ def test_fif_anonymize(_bids_validate, tmp_path):
10061002
@testing.requires_testing_data
10071003
def test_fif_ias(tmp_path):
10081004
"""Test writing FIF files with internal active shielding."""
1009-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
1005+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
10101006
raw = _read_raw_fif(raw_fname)
10111007

10121008
raw.set_channel_types({raw.ch_names[0]: "ias"})
@@ -1022,7 +1018,7 @@ def test_fif_ias(tmp_path):
10221018
@testing.requires_testing_data
10231019
def test_fif_exci(tmp_path):
10241020
"""Test writing FIF files with excitation channel."""
1025-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
1021+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
10261022
raw = _read_raw_fif(raw_fname)
10271023

10281024
raw.set_channel_types({raw.ch_names[0]: "exci"})
@@ -1983,7 +1979,7 @@ def test_get_anat_landmarks():
19831979
# Needs to be converted to Nifti because we only have mgh in our test base
19841980
t1w_mgh = op.join(data_path, "subjects", "sample", "mri", "T1.mgz")
19851981
fs_subjects_dir = op.join(data_path, "subjects")
1986-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
1982+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
19871983
raw = _read_raw_fif(raw_fname)
19881984
# Write some MRI data and supply a `trans`
19891985
trans_fname = raw_fname.replace("_raw.fif", "-trans.fif")
@@ -2094,7 +2090,7 @@ def test_write_anat(_bids_validate, tmp_path):
20942090
)
20952091

20962092
# write base bids directory
2097-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2093+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
20982094

20992095
event_id = {
21002096
"Auditory/Left": 1,
@@ -2104,9 +2100,7 @@ def test_write_anat(_bids_validate, tmp_path):
21042100
"Smiley": 5,
21052101
"Button": 32,
21062102
}
2107-
events_fname = op.join(
2108-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2109-
)
2103+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
21102104

21112105
# Drop unknown events.
21122106
events = mne.read_events(events_fname)
@@ -2254,7 +2248,7 @@ def test_write_anat(_bids_validate, tmp_path):
22542248
@testing.requires_testing_data
22552249
def test_write_raw_pathlike(tmp_path):
22562250
"""Ensure writing pathlib.Path works."""
2257-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2251+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
22582252
event_id = {
22592253
"Auditory/Left": 1,
22602254
"Auditory/Right": 2,
@@ -2285,7 +2279,7 @@ def test_write_raw_pathlike(tmp_path):
22852279
@testing.requires_testing_data
22862280
def test_write_raw_no_dig(tmp_path):
22872281
"""Test writing without dig."""
2288-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2282+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
22892283
raw = _read_raw_fif(raw_fname)
22902284
bids_root = tmp_path
22912285
bids_path = _bids_path.copy().update(root=bids_root)
@@ -2305,7 +2299,7 @@ def test_write_raw_no_dig(tmp_path):
23052299
def test_write_anat_pathlike(tmp_path):
23062300
"""Test writing anatomical data with pathlib.Paths."""
23072301
pytest.importorskip("nibabel")
2308-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2302+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
23092303
trans_fname = raw_fname.replace("_raw.fif", "-trans.fif")
23102304
raw = _read_raw_fif(raw_fname)
23112305
trans = mne.read_trans(trans_fname)
@@ -2338,10 +2332,8 @@ def test_write_anat_pathlike(tmp_path):
23382332
@testing.requires_testing_data
23392333
def test_write_does_not_alter_events_inplace(tmp_path):
23402334
"""Test that writing does not modify the passed events array."""
2341-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2342-
events_fname = op.join(
2343-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2344-
)
2335+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
2336+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
23452337

23462338
raw = _read_raw_fif(raw_fname)
23472339
events = mne.read_events(events_fname)
@@ -2419,7 +2411,7 @@ def test_mark_channels(
24192411
# Setup: Create a fresh BIDS dataset.
24202412
bids_root = tmp_path / "bids1"
24212413
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg", suffix="meg")
2422-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2414+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
24232415
event_id = {
24242416
"Auditory/Left": 1,
24252417
"Auditory/Right": 2,
@@ -2428,9 +2420,7 @@ def test_mark_channels(
24282420
"Smiley": 5,
24292421
"Button": 32,
24302422
}
2431-
events_fname = op.join(
2432-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2433-
)
2423+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
24342424

24352425
# Drop unknown events.
24362426
events = mne.read_events(events_fname)
@@ -2531,7 +2521,7 @@ def test_mark_channel_roundtrip(tmp_path):
25312521
# Setup: Create a fresh BIDS dataset.
25322522
bids_root = tmp_path / "bids1"
25332523
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg", suffix="meg")
2534-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2524+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
25352525
event_id = {
25362526
"Auditory/Left": 1,
25372527
"Auditory/Right": 2,
@@ -2540,9 +2530,7 @@ def test_mark_channel_roundtrip(tmp_path):
25402530
"Smiley": 5,
25412531
"Button": 32,
25422532
}
2543-
events_fname = op.join(
2544-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2545-
)
2533+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
25462534

25472535
# Drop unknown events.
25482536
events = mne.read_events(events_fname)
@@ -2583,7 +2571,7 @@ def test_error_mark_channels(tmp_path):
25832571
# Setup: Create a fresh BIDS dataset.
25842572
bids_root = tmp_path / "bids1"
25852573
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg", suffix="meg")
2586-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2574+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
25872575
event_id = {
25882576
"Auditory/Left": 1,
25892577
"Auditory/Right": 2,
@@ -2592,9 +2580,7 @@ def test_error_mark_channels(tmp_path):
25922580
"Smiley": 5,
25932581
"Button": 32,
25942582
}
2595-
events_fname = op.join(
2596-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2597-
)
2583+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
25982584

25992585
# Drop unknown events.
26002586
events = mne.read_events(events_fname)
@@ -2660,7 +2646,7 @@ def test_write_meg_calibration(_bids_validate, tmp_path):
26602646
bids_root = tmp_path / "bids1"
26612647
bids_path = _bids_path.copy().update(root=bids_root)
26622648

2663-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2649+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
26642650
raw = _read_raw_fif(raw_fname, verbose=False)
26652651
write_raw_bids(raw, bids_path=bids_path, verbose=False)
26662652

@@ -2707,7 +2693,7 @@ def test_write_meg_crosstalk(_bids_validate, tmp_path):
27072693
bids_root = tmp_path / "bids1"
27082694
bids_path = _bids_path.copy().update(root=bids_root, suffix="meg")
27092695

2710-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2696+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
27112697
raw = _read_raw_fif(raw_fname, verbose=False)
27122698
write_raw_bids(raw, bids_path=bids_path, verbose=False)
27132699

@@ -2746,10 +2732,8 @@ def test_annotations(_bids_validate, bad_segments, tmp_path):
27462732
"""Test that Annotations are stored as events."""
27472733
bids_root = tmp_path / "bids1"
27482734
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg")
2749-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2750-
events_fname = op.join(
2751-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2752-
)
2735+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
2736+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
27532737

27542738
events = mne.read_events(events_fname)
27552739
event_id = {
@@ -2890,10 +2874,8 @@ def test_undescribed_events(_bids_validate, drop_undescribed_events, tmp_path):
28902874
"""Test we're raising if event descriptions are missing."""
28912875
bids_root = tmp_path / "bids1"
28922876
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg")
2893-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2894-
events_fname = op.join(
2895-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2896-
)
2877+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
2878+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
28972879

28982880
events = mne.read_events(events_fname)
28992881
if drop_undescribed_events:
@@ -2940,10 +2922,8 @@ def test_event_storage(tmp_path):
29402922
"""Test we're retaining the original event IDs when storing events."""
29412923
bids_root = tmp_path / "bids1"
29422924
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg")
2943-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
2944-
events_fname = op.join(
2945-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
2946-
)
2925+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
2926+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
29472927
events_tsv_fname = bids_path.copy().update(suffix="events", extension=".tsv")
29482928

29492929
events = mne.read_events(events_fname)
@@ -3281,10 +3261,8 @@ def test_sidecar_encoding(_bids_validate, tmp_path):
32813261
"""Test we're properly encoding text as UTF8."""
32823262
bids_root = tmp_path / "bids1"
32833263
bids_path = _bids_path.copy().update(root=bids_root, datatype="meg")
3284-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
3285-
events_fname = op.join(
3286-
data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif"
3287-
)
3264+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
3265+
events_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw-eve.fif"
32883266

32893267
raw = _read_raw_fif(raw_fname)
32903268
events = mne.read_events(events_fname)
@@ -3668,7 +3646,7 @@ def test_symlink(tmp_path):
36683646
def test_write_associated_emptyroom(_bids_validate, tmp_path, empty_room_dtype):
36693647
"""Test functionality of the write_raw_bids conversion for fif."""
36703648
bids_root = tmp_path / "bids1"
3671-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
3649+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
36723650
raw = _read_raw_fif(raw_fname)
36733651
meas_date = datetime(year=2020, month=1, day=10, tzinfo=timezone.utc)
36743652

@@ -3760,7 +3738,7 @@ def test_preload(_bids_validate, tmp_path):
37603738
@testing.requires_testing_data
37613739
def test_write_raw_special_paths(tmp_path, dir_name):
37623740
"""Test writing to locations containing strings with special meaning."""
3763-
raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif")
3741+
raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif"
37643742
raw = _read_raw_fif(raw_fname)
37653743

37663744
root = tmp_path / dir_name

0 commit comments

Comments
 (0)