Skip to content

Commit

Permalink
more again
Browse files Browse the repository at this point in the history
  • Loading branch information
sappelhoff committed Dec 11, 2024
1 parent b62f4ec commit 4c6af9a
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 45 deletions.
10 changes: 5 additions & 5 deletions mne_bids/commands/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions mne_bids/tests/test_copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions mne_bids/tests/test_dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions mne_bids/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions mne_bids/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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"):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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")
Expand All @@ -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(
Expand All @@ -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)

Expand All @@ -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"])
Expand Down
10 changes: 5 additions & 5 deletions mne_bids/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"):
Expand Down
9 changes: 4 additions & 5 deletions mne_bids/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4c6af9a

Please sign in to comment.