From 4c6af9ab2b1e817b3d53bf222a21719dcaa1e118 Mon Sep 17 00:00:00 2001 From: Stefan Appelhoff Date: Wed, 11 Dec 2024 14:04:25 +0100 Subject: [PATCH] more again --- mne_bids/commands/tests/test_cli.py | 10 +++++----- mne_bids/tests/test_copyfiles.py | 16 ++++++++-------- mne_bids/tests/test_dig.py | 6 +++--- mne_bids/tests/test_path.py | 16 ++++++++-------- mne_bids/tests/test_read.py | 22 +++++++++++----------- mne_bids/tests/test_update.py | 10 +++++----- mne_bids/tests/test_utils.py | 9 ++++----- 7 files changed, 44 insertions(+), 45 deletions(-) diff --git a/mne_bids/commands/tests/test_cli.py b/mne_bids/commands/tests/test_cli.py index ee4287ade..513493cd7 100644 --- a/mne_bids/commands/tests/test_cli.py +++ b/mne_bids/commands/tests/test_cli.py @@ -54,7 +54,7 @@ def check_usage(module, force_help=False): def test_raw_to_bids(tmp_path): """Test mne_bids raw_to_bids.""" output_path = str(tmp_path) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" # Check that help is printed check_usage(mne_bids_raw_to_bids) @@ -150,7 +150,7 @@ def test_mark_bad_channels_single_file(tmp_path): # Create test dataset. output_path = str(tmp_path) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" events_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif" ) @@ -237,7 +237,7 @@ def test_mark_bad_channels_multiple_files(tmp_path): # Create test dataset. output_path = str(tmp_path) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" events_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif" ) @@ -344,7 +344,7 @@ def test_count_events(tmp_path): # Create test dataset. output_path = str(tmp_path) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = mne.io.read_raw(raw_fname) raw.info["line_freq"] = 60.0 @@ -393,7 +393,7 @@ def test_inspect(tmp_path): subject = "01" task = "test" datatype = "meg" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = mne.io.read_raw(raw_fname) raw.info["line_freq"] = 60.0 diff --git a/mne_bids/tests/test_copyfiles.py b/mne_bids/tests/test_copyfiles.py index f2d68e166..68a36c202 100644 --- a/mne_bids/tests/test_copyfiles.py +++ b/mne_bids/tests/test_copyfiles.py @@ -188,8 +188,8 @@ def test_copyfile_edfbdf_uppercase(tmp_path): # Test regular copying for ext in [".edf", ".bdf"]: - raw_fname = op.join(data_path, "test" + ext) - new_name = op.join(bids_root, "test_copy" + ext.upper()) + raw_fname = data_path / f"test{ext}" + new_name = bids_root / f"test_copy{ext.upper()}" with pytest.warns(RuntimeWarning, match="Upper-case extension"): copyfile_edf(raw_fname, new_name) @@ -203,8 +203,8 @@ def test_copyfile_edfbdf_uppercase(tmp_path): def test_copyfile_eeglab(tmp_path, fname): """Test the copying of EEGlab set and fdt files.""" bids_root = str(tmp_path) - data_path = op.join(testing_path, "EEGLAB") - raw_fname = op.join(data_path, fname) + data_path = testing_path / "EEGLAB" + raw_fname = data_path / fname new_name = op.join(bids_root, f"CONVERTED_{fname}.set") # IO error testing @@ -227,10 +227,10 @@ def test_copyfile_kit(tmp_path): """Test copying and renaming KIT files to a new location.""" output_path = str(tmp_path) data_path = base_path / "kit" / "tests" / "data" - raw_fname = op.join(data_path, "test.sqd") - hpi_fname = op.join(data_path, "test_mrk.sqd") - electrode_fname = op.join(data_path, "test.elp") - headshape_fname = op.join(data_path, "test.hsp") + raw_fname = data_path / "test.sqd" + hpi_fname = data_path / "test_mrk.sqd" + electrode_fname = data_path / "test.elp" + headshape_fname = data_path / "test.hsp" subject_id = "01" session_id = "01" run = "01" diff --git a/mne_bids/tests/test_dig.py b/mne_bids/tests/test_dig.py index 30c12e4a9..ed3a2c64b 100644 --- a/mne_bids/tests/test_dig.py +++ b/mne_bids/tests/test_dig.py @@ -49,7 +49,7 @@ def _load_raw(): """Load the sample raw data.""" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = mne.io.read_raw(raw_fname) raw.drop_channels(raw.info["bads"]) raw.info["line_freq"] = 60 @@ -338,11 +338,11 @@ def test_convert_montage(): raw = _load_raw() montage = raw.get_montage() trans = mne.read_trans( - op.join(data_path, "MEG", "sample", "sample_audvis_trunc-trans.fif") + data_path / "MEG" / "sample" / "sample_audvis_trunc-trans.fif" ) montage.apply_trans(trans) - subjects_dir = op.join(data_path, "subjects") + subjects_dir = data_path / "subjects" # test read with pytest.raises(RuntimeError, match="incorrectly formatted"): convert_montage_to_mri(montage, "foo", subjects_dir) diff --git a/mne_bids/tests/test_path.py b/mne_bids/tests/test_path.py index bcf42f682..7cd580a3f 100644 --- a/mne_bids/tests/test_path.py +++ b/mne_bids/tests/test_path.py @@ -53,7 +53,7 @@ def return_bids_test_dir(tmp_path_factory): """Return path to a written test BIDS dir.""" bids_root = str(tmp_path_factory.mktemp("mnebids_utils_test_bids_ds")) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" event_id = { "Auditory/Left": 1, @@ -66,8 +66,8 @@ def return_bids_test_dir(tmp_path_factory): events_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif" ) - cal_fname = op.join(data_path, "SSS", "sss_cal_mgh.dat") - crosstalk_fname = op.join(data_path, "SSS", "ct_sparse.fif") + cal_fname = data_path / "SSS" / "sss_cal_mgh.dat" + crosstalk_fname = data_path / "SSS" / "ct_sparse.fif" raw = mne.io.read_raw_fif(raw_fname) raw.info["line_freq"] = 60 @@ -1127,7 +1127,7 @@ def test_find_matching_paths(return_bids_test_dir): @testing.requires_testing_data def test_find_empty_room(return_bids_test_dir, tmp_path): """Test reading of empty room data.""" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" bids_root = tmp_path / "bids" bids_root.mkdir() @@ -1269,7 +1269,7 @@ def test_find_empty_room(return_bids_test_dir, tmp_path): @testing.requires_testing_data def test_find_emptyroom_ties(tmp_path): """Test that we receive a warning on a date tie.""" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" bids_root = str(tmp_path) bids_path = _bids_path.copy().update(root=bids_root, datatype="meg") @@ -1283,7 +1283,7 @@ def test_find_emptyroom_ties(tmp_path): raw = _read_raw_fif(raw_fname) - er_raw_fname = op.join(data_path, "MEG", "sample", "ernoise_raw.fif") + er_raw_fname = data_path / "MEG" / "sample" / "ernoise_raw.fif" raw.copy().crop(0, 10).save(er_raw_fname, overwrite=True) er_raw = _read_raw_fif(er_raw_fname) raw.set_meas_date(meas_date) @@ -1306,7 +1306,7 @@ def test_find_emptyroom_ties(tmp_path): @testing.requires_testing_data def test_find_emptyroom_no_meas_date(tmp_path): """Test that we warn if measurement date can be read or inferred.""" - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" bids_root = str(tmp_path) bids_path = _bids_path.copy().update(root=bids_root) @@ -1324,7 +1324,7 @@ def test_find_emptyroom_no_meas_date(tmp_path): er_basename = er_bids_path.basename raw = _read_raw_fif(raw_fname) - er_raw_fname = op.join(data_path, "MEG", "sample", "ernoise_raw.fif") + er_raw_fname = data_path / "MEG" / "sample" / "ernoise_raw.fif" raw.copy().crop(0, 10).save(er_raw_fname, overwrite=True) er_raw = _read_raw_fif(er_raw_fname) er_raw.set_meas_date(er_meas_date) diff --git a/mne_bids/tests/test_read.py b/mne_bids/tests/test_read.py index ef5b00777..f33f34b22 100644 --- a/mne_bids/tests/test_read.py +++ b/mne_bids/tests/test_read.py @@ -63,10 +63,10 @@ # Get the MNE testing sample data - USA data_path = testing.data_path(download=False) -raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") +raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" # Data with cHPI info -raw_fname_chpi = op.join(data_path, "SSS", "test_move_anon_raw.fif") +raw_fname_chpi = data_path / "SSS" / "test_move_anon_raw.fif" # Tiny BIDS testing dataset mne_bids_root = Path(mne_bids.__file__).parents[1] @@ -229,7 +229,7 @@ def test_get_head_mri_trans(tmp_path): events_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif" ) - subjects_dir = op.join(data_path, "subjects") + subjects_dir = data_path / "subjects" # Drop unknown events. events = mne.read_events(events_fname) @@ -253,7 +253,7 @@ def test_get_head_mri_trans(tmp_path): # Get the T1 weighted MRI data file ... test write_anat with a nibabel # image instead of a file path - t1w_mgh = op.join(data_path, "subjects", "sample", "mri", "T1.mgz") + t1w_mgh = data_path / "subjects" / "sample" / "mri" / "T1.mgz" t1w_mgh = nib.load(t1w_mgh) landmarks = get_anat_landmarks( @@ -278,7 +278,7 @@ def test_get_head_mri_trans(tmp_path): raw.info["dig"][0]["r"] = np.full(3, np.nan) sh.rmtree(anat_dir) bad_landmarks = get_anat_landmarks( - t1w_mgh, raw.info, trans, "sample", op.join(data_path, "subjects") + t1w_mgh, raw.info, trans, "sample", data_path / "subjects" ) write_anat(t1w_mgh, bids_path=t1w_bids_path, landmarks=bad_landmarks) with pytest.raises(RuntimeError, match="AnatomicalLandmarkCoordinates"): @@ -873,7 +873,7 @@ def test_handle_eeg_coords_reading(tmp_path): root=tmp_path, ) - raw_fname = op.join(data_path, "EDF", "test_reduced.edf") + raw_fname = data_path / "EDF" / "test_reduced.edf" raw = _read_raw_edf(raw_fname) # ensure we are writing 'eeg' data @@ -933,7 +933,7 @@ def test_handle_eeg_coords_reading(tmp_path): @testing.requires_testing_data def test_handle_ieeg_coords_reading(bids_path, tmp_path): """Test reading iEEG coordinates from BIDS files.""" - raw_fname = op.join(data_path, "EDF", "test_reduced.edf") + raw_fname = data_path / "EDF" / "test_reduced.edf" bids_fname = bids_path.copy().update( datatype="ieeg", suffix="ieeg", extension=".edf", root=tmp_path ) @@ -1105,7 +1105,7 @@ def test_get_head_mri_trans_ctf(fname, tmp_path): """Test getting a trans object from BIDS data in CTF.""" nib = pytest.importorskip("nibabel") - ctf_data_path = op.join(data_path, "CTF") + ctf_data_path = data_path / "CTF" raw_ctf_fname = op.join(ctf_data_path, fname) raw_ctf = _read_raw_ctf(raw_ctf_fname, clean_names=True) bids_path = _bids_path.copy().update(root=tmp_path, datatype="meg", suffix="meg") @@ -1116,7 +1116,7 @@ def test_get_head_mri_trans_ctf(fname, tmp_path): # Get the T1 weighted MRI data file ... test write_anat with a nibabel # image instead of a file path - t1w_mgh = op.join(data_path, "subjects", "sample", "mri", "T1.mgz") + t1w_mgh = data_path / "subjects" / "sample" / "mri" / "T1.mgz" t1w_mgh = nib.load(t1w_mgh) t1w_bids_path = BIDSPath( @@ -1127,7 +1127,7 @@ def test_get_head_mri_trans_ctf(fname, tmp_path): raw_ctf.info, trans, fs_subject="sample", - fs_subjects_dir=op.join(data_path, "subjects"), + fs_subjects_dir=data_path / "subjects", ) write_anat(t1w_mgh, bids_path=t1w_bids_path, landmarks=landmarks) @@ -1136,7 +1136,7 @@ def test_get_head_mri_trans_ctf(fname, tmp_path): bids_path=bids_path, extra_params=dict(clean_names=True), fs_subject="sample", - fs_subjects_dir=op.join(data_path, "subjects"), + fs_subjects_dir=data_path / "subjects", ) assert_almost_equal(trans["trans"], estimated_trans["trans"]) diff --git a/mne_bids/tests/test_update.py b/mne_bids/tests/test_update.py index 868462e74..e28dde128 100644 --- a/mne_bids/tests/test_update.py +++ b/mne_bids/tests/test_update.py @@ -43,7 +43,7 @@ def _get_bids_test_dir(tmp_path_factory): """Return path to a written test BIDS dir.""" bids_root = str(tmp_path_factory.mktemp("mnebids_utils_test_bids_ds")) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" event_id = { "Auditory/Left": 1, @@ -56,8 +56,8 @@ def _get_bids_test_dir(tmp_path_factory): events_fname = op.join( data_path, "MEG", "sample", "sample_audvis_trunc_raw-eve.fif" ) - cal_fname = op.join(data_path, "SSS", "sss_cal_mgh.dat") - crosstalk_fname = op.join(data_path, "SSS", "ct_sparse.fif") + cal_fname = data_path / "SSS" / "sss_cal_mgh.dat" + crosstalk_fname = data_path / "SSS" / "ct_sparse.fif" raw = mne.io.read_raw_fif(raw_fname) raw.info["line_freq"] = 60 @@ -316,7 +316,7 @@ def test_readme_conflicts(extension, _get_bids_test_dir): root=_get_bids_test_dir, ) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = mne.io.read_raw_fif(raw_fname) write_raw_bids(raw, bids_path, overwrite=False) @@ -341,7 +341,7 @@ def test_multiple_readmes_invalid(_get_bids_test_dir): root=_get_bids_test_dir, ) - raw_fname = op.join(data_path, "MEG", "sample", "sample_audvis_trunc_raw.fif") + raw_fname = data_path / "MEG" / "sample" / "sample_audvis_trunc_raw.fif" raw = mne.io.read_raw_fif(raw_fname) with pytest.raises(RuntimeError, match="Multiple README files found"): diff --git a/mne_bids/tests/test_utils.py b/mne_bids/tests/test_utils.py index f2da6044e..e72d2a9d1 100644 --- a/mne_bids/tests/test_utils.py +++ b/mne_bids/tests/test_utils.py @@ -3,7 +3,6 @@ # Authors: The MNE-BIDS developers # SPDX-License-Identifier: BSD-3-Clause -import os.path as op from datetime import datetime from pathlib import Path @@ -150,16 +149,16 @@ def test_infer_eeg_placement_scheme(): """Test inferring a correct EEG placement scheme.""" # no eeg channels case (e.g., MEG data) data_path = base_path / "bti" / "tests" / "data" - raw_fname = op.join(data_path, "test_pdf_linux") - config_fname = op.join(data_path, "test_config_linux") - headshape_fname = op.join(data_path, "test_hs_linux") + raw_fname = data_path / "test_pdf_linux" + config_fname = data_path / "test_config_linux" + headshape_fname = data_path / "test_hs_linux" raw = mne.io.read_raw_bti(raw_fname, config_fname, headshape_fname) placement_scheme = _infer_eeg_placement_scheme(raw) assert placement_scheme == "n/a" # 1020 case data_path = base_path / "brainvision" / "tests" / "data" - raw_fname = op.join(data_path, "test.vhdr") + raw_fname = data_path / "test.vhdr" raw = mne.io.read_raw_brainvision(raw_fname) placement_scheme = _infer_eeg_placement_scheme(raw) assert placement_scheme == "based on the extended 10/20 system"