Skip to content

Commit

Permalink
Fix string format "blabla" "bla" (#1243)
Browse files Browse the repository at this point in the history
* fix string style

* warn at stacklevel=2

* Revert "warn at stacklevel=2"

This reverts commit 60406f0.

* fix one more

* fix  a couple more
  • Loading branch information
Mathieu Scheltienne authored Apr 2, 2024
1 parent 509012d commit 598ff7f
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 74 deletions.
4 changes: 2 additions & 2 deletions mne_bids/commands/mne_bids_calibration_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def run():
parser.add_option(
"--bids_root",
dest="bids_root",
help="The path of the folder containing the BIDS " "dataset",
help="The path of the folder containing the BIDS dataset",
)
parser.add_option("--subject_id", dest="subject", help=("Subject name"))
parser.add_option("--subject_id", dest="subject", help="Subject name")
parser.add_option("--session_id", dest="session", help="Session name")
parser.add_option("--file", dest="fname", help="The path of the crosstalk file")
parser.add_option(
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/commands/mne_bids_count_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run():
"--describe",
dest="describe",
action="store_true",
help=("If set print the descriptive statistics " "(min, max, etc.)."),
help="If set print the descriptive statistics (min, max, etc.).",
)

parser.add_option(
Expand Down Expand Up @@ -70,7 +70,7 @@ def run():
if not all([opt.bids_root]):
parser.print_help()
parser.error(
"Arguments missing. You need to specify the " "--bids_root parameter."
"Arguments missing. You need to specify the --bids_root parameter."
)

if opt.output and Path(opt.output).exists() and not opt.overwrite:
Expand Down
8 changes: 3 additions & 5 deletions mne_bids/commands/mne_bids_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def run():
"""Run the cp command."""
from mne.commands.utils import get_optparser

accepted_formats_msg = (
"(accepted formats: BrainVision .vhdr, " "EEGLAB .set, CTF .ds)"
)
accepted_formats_msg = "(accepted formats: BrainVision .vhdr, EEGLAB .set, CTF .ds)"

parser = get_optparser(
__file__,
Expand All @@ -29,15 +27,15 @@ def run():
"-i",
"--input",
dest="input",
help=(f"path to the input file. {accepted_formats_msg}"),
help=f"path to the input file. {accepted_formats_msg}",
metavar="INPUT",
)

parser.add_option(
"-o",
"--output",
dest="output",
help=("path to the output file (MUST be same format " "as input file)"),
help="path to the output file (MUST be same format as input file)",
metavar="OUTPUT",
)

Expand Down
8 changes: 3 additions & 5 deletions mne_bids/commands/mne_bids_crosstalk_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def run():
parser.add_option(
"--bids_root",
dest="bids_root",
help="The path of the folder containing the BIDS " "dataset",
help="The path of the folder containing the BIDS dataset",
)
parser.add_option("--subject_id", dest="subject", help=("Subject name"))
parser.add_option("--subject_id", dest="subject", help="Subject name")
parser.add_option("--session_id", dest="session", help="Session name")
parser.add_option("--file", dest="fname", help="The path of the crosstalk file")
parser.add_option(
Expand All @@ -44,9 +44,7 @@ def run():
opt, args = parser.parse_args()
if args:
parser.print_help()
parser.error(
f"Please do not specify arguments without flags. " f"Got: {args}.\n"
)
parser.error(f"Please do not specify arguments without flags. Got: {args}.\n")

if opt.bids_root is None:
parser.print_help()
Expand Down
10 changes: 5 additions & 5 deletions mne_bids/commands/mne_bids_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def run():
parser.add_option(
"--bids_root",
dest="bids_root",
help="The path of the folder containing the BIDS " "dataset",
help="The path of the folder containing the BIDS dataset",
)
parser.add_option("--subject_id", dest="subject", help=("Subject name"))
parser.add_option("--subject_id", dest="subject", help="Subject name")
parser.add_option("--session_id", dest="session", help="Session name")
parser.add_option("--task", dest="task", help="Task name")
parser.add_option("--acq", dest="acquisition", help="Acquisition parameter")
Expand All @@ -44,17 +44,17 @@ def run():
parser.add_option(
"--suffix",
dest="suffix",
help="The filename suffix, i.e. the last part before " "the extension",
help="The filename suffix, i.e. the last part before the extension",
)
parser.add_option(
"--ext",
dest="extension",
help="The filename extension, including the leading " "period, e.g. .fif",
help="The filename extension, including the leading period, e.g. .fif",
)
parser.add_option(
"--find_flat",
dest="find_flat",
help="Whether to auto-detect flat channels and time " "segments",
help="Whether to auto-detect flat channels and time segments",
)
parser.add_option(
"--l_freq", dest="l_freq", help="The high-pass filter cutoff frequency"
Expand Down
12 changes: 5 additions & 7 deletions mne_bids/commands/mne_bids_mark_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def run():
parser.add_option(
"--bids_root",
dest="bids_root",
help="The path of the folder containing the BIDS " "dataset",
help="The path of the folder containing the BIDS dataset",
)
parser.add_option("--subject_id", dest="subject", help=("Subject name"))
parser.add_option("--subject_id", dest="subject", help="Subject name")
parser.add_option("--session_id", dest="session", help="Session name")
parser.add_option("--task", dest="task", help="Task name")
parser.add_option("--acq", dest="acquisition", help="Acquisition parameter")
Expand All @@ -71,12 +71,12 @@ def run():
parser.add_option(
"--suffix",
dest="suffix",
help="The filename suffix, i.e. the last part before " "the extension",
help="The filename suffix, i.e. the last part before the extension",
)
parser.add_option(
"--ext",
dest="extension",
help="The filename extension, including the leading " "period, e.g. .fif",
help="The filename extension, including the leading period, e.g. .fif",
)
parser.add_option(
"--verbose",
Expand All @@ -88,9 +88,7 @@ def run():
opt, args = parser.parse_args()
if args:
parser.print_help()
parser.error(
f"Please do not specify arguments without flags. " f"Got: {args}.\n"
)
parser.error(f"Please do not specify arguments without flags. Got: {args}.\n")

if opt.bids_root is None:
parser.print_help()
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/commands/mne_bids_raw_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run():
parser.add_option(
"--subject_id",
dest="subject_id",
help=("subject name in BIDS compatible format " "(01, 02, etc.)"),
help="subject name in BIDS compatible format (01, 02, etc.)",
)
parser.add_option(
"--task", dest="task", help="name of the task the data is based on"
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/commands/mne_bids_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def run():
if not all([opt.bids_root]):
parser.print_help()
parser.error(
"Arguments missing. You need to specify the " "--bids_root parameter."
"Arguments missing. You need to specify the --bids_root parameter."
)

report = make_report(opt.bids_root)
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def find_empty_room(self, use_sidecar_only=False, *, verbose=None):
Returns ``None`` if none was found.
"""
if self.datatype not in ("meg", None):
raise ValueError("Empty-room data is only supported for MEG " "datasets")
raise ValueError("Empty-room data is only supported for MEG datasets")

if self.root is None:
raise ValueError(
Expand Down Expand Up @@ -1251,7 +1251,7 @@ def meg_calibration_fpath(self):
if self.root is None or self.subject is None:
raise ValueError("root and subject must be set.")
if self.datatype not in (None, "meg"):
raise ValueError("Can only find fine-calibration file for MEG " "datasets.")
raise ValueError("Can only find fine-calibration file for MEG datasets.")

path = BIDSPath(
subject=self.subject,
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def _handle_info_reading(sidecar_fname, raw):
)
else:
addmsg = (
".\n(Because no 'HeadCoilFrequency' data " "was found in the sidecar.)"
".\n(Because no 'HeadCoilFrequency' data was found in the sidecar.)"
)
logger.info(msg.format(addmsg))

Expand Down
2 changes: 1 addition & 1 deletion mne_bids/tests/test_copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_get_brainvision_paths(tmp_path):


@pytest.mark.filterwarnings(
"ignore:.*Exception ignored.*:" "pytest.PytestUnraisableExceptionWarning"
"ignore:.*Exception ignored.*:pytest.PytestUnraisableExceptionWarning"
)
def test_copyfile_brainvision(tmp_path):
"""Test the copying of BrainVision vhdr, vmrk and eeg files."""
Expand Down
4 changes: 1 addition & 3 deletions mne_bids/tests/test_dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ def test_template_to_head():
raw = _load_raw()
montage_empty = mne.channels.make_dig_montage(hsp=[[0, 0, 0]])
_set_montage_no_trans(raw, montage_empty)
with pytest.raises(
RuntimeError, match="No channel locations " "found in the montage"
):
with pytest.raises(RuntimeError, match="No channel locations found in the montage"):
template_to_head(raw.info, "fsaverage", coord_frame="auto")

# test unexpected coordinate frame
Expand Down
8 changes: 4 additions & 4 deletions mne_bids/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ def test_make_filenames():
datatype="ieeg",
)
expected_str = (
"sub-one_ses-two_task-three_acq-four_run-1_proc-six_" "rec-seven_ieeg.json"
"sub-one_ses-two_task-three_acq-four_run-1_proc-six_rec-seven_ieeg.json"
)
assert BIDSPath(**prefix_data).basename == expected_str
assert (
Expand Down Expand Up @@ -902,7 +902,7 @@ def test_make_filenames():
) # noqa

# what happens with scans.tsv file
with pytest.raises(ValueError, match="scans.tsv file name " "can only contain"):
with pytest.raises(ValueError, match="scans.tsv file name can only contain"):
BIDSPath(
subject=subject_id,
session=session_id,
Expand Down Expand Up @@ -961,7 +961,7 @@ def test_match(return_bids_test_dir):
bids_path_01 = BIDSPath(root=bids_root, run="01")
paths = bids_path_01.match()
assert len(paths) == 3
assert paths[0].basename == ("sub-01_ses-01_task-testing_run-01_channels.tsv")
assert paths[0].basename == "sub-01_ses-01_task-testing_run-01_channels.tsv"

bids_path_01 = BIDSPath(root=bids_root, subject="unknown")
paths = bids_path_01.match()
Expand Down Expand Up @@ -1188,7 +1188,7 @@ def test_find_empty_room(return_bids_test_dir, tmp_path):
write_raw_bids(raw, bids_path, overwrite=True, format="FIF")
with pytest.raises(
ValueError,
match="The provided recording does not " "have a measurement date set",
match="The provided recording does not have a measurement date set",
):
bids_path.find_empty_room()

Expand Down
22 changes: 9 additions & 13 deletions mne_bids/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

warning_str = dict(
channel_unit_changed="ignore:The unit for chann*.:RuntimeWarning:mne",
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:" "mne",
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:mne",
nasion_not_found="ignore:.*nasion not found:RuntimeWarning:mne",
maxshield="ignore:.*Internal Active Shielding:RuntimeWarning:mne",
)
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_not_implemented(tmp_path):
with open(raw_fname, "w", encoding="utf-8"):
pass
with pytest.raises(
ValueError, match=("there is no IO support for " "this file format yet")
ValueError, match=("there is no IO support for this file format yet")
):
_read_raw(raw_fname)

Expand Down Expand Up @@ -867,7 +867,7 @@ def test_handle_eeg_coords_reading(tmp_path):
)
_update_sidecar(coordsystem_fname, "EEGCoordinateSystem", "besa")
with pytest.warns(
RuntimeWarning, match="is not a BIDS-acceptable " "coordinate frame for EEG"
RuntimeWarning, match="is not a BIDS-acceptable coordinate frame for EEG"
):
raw_test = read_raw_bids(bids_path)
assert raw_test.info["dig"] is None
Expand Down Expand Up @@ -939,7 +939,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
electrodes_dict[axis] = np.multiply(orig_electrodes_dict[axis], scaling)
_to_tsv(electrodes_dict, electrodes_fname)
with pytest.warns(
RuntimeWarning, match="Coordinate unit is not " "an accepted BIDS unit"
RuntimeWarning, match="Coordinate unit is not an accepted BIDS unit"
):
raw_test = read_raw_bids(bids_path=bids_fname, verbose=False)

Expand Down Expand Up @@ -967,9 +967,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
_update_sidecar(coordsystem_fname, "iEEGCoordinateSystem", coord_frame)
# read in raw file w/ updated coordinate frame
# and make sure all digpoints are MRI coordinate frame
with pytest.warns(
RuntimeWarning, match="not an MNE-Python " "coordinate frame"
):
with pytest.warns(RuntimeWarning, match="not an MNE-Python coordinate frame"):
raw_test = read_raw_bids(bids_path=bids_fname, verbose=False)
assert raw_test.info["dig"] is not None

Expand All @@ -984,7 +982,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
raw_test = read_raw_bids(bids_path=bids_fname, verbose=False)
else:
with pytest.warns(
RuntimeWarning, match="not an MNE-Python " "coordinate frame"
RuntimeWarning, match="not an MNE-Python coordinate frame"
):
raw_test = read_raw_bids(bids_path=bids_fname, verbose=False)
assert raw_test.info["dig"] is not None
Expand All @@ -998,9 +996,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):

# if we delete the coordsystem.json file, an error will be raised
os.remove(coordsystem_fname)
with pytest.raises(
RuntimeError, match="BIDS mandates that " "the coordsystem.json"
):
with pytest.raises(RuntimeError, match="BIDS mandates that the coordsystem.json"):
raw = read_raw_bids(bids_path=bids_fname, verbose=False)

# test error message if electrodes is not a subset of Raw
Expand All @@ -1014,7 +1010,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
_to_tsv(electrodes_dict, electrodes_fname)
# popping off channels should not result in an error
# however, a warning will be raised through mne-python
with pytest.warns(RuntimeWarning, match="DigMontage is " "only a subset of info"):
with pytest.warns(RuntimeWarning, match="DigMontage is only a subset of info"):
read_raw_bids(bids_path=bids_fname, verbose=False)

# make sure montage is set if there are coordinates w/ 'n/a'
Expand All @@ -1030,7 +1026,7 @@ def test_handle_ieeg_coords_reading(bids_path, tmp_path):
# electrode coordinates should be nan
# when coordinate is 'n/a'
nan_chs = [electrodes_dict["name"][i] for i in [0, 3]]
with pytest.warns(RuntimeWarning, match="There are channels " "without locations"):
with pytest.warns(RuntimeWarning, match="There are channels without locations"):
raw = read_raw_bids(bids_path=bids_fname, verbose=False)
for idx, ch in enumerate(raw.info["chs"]):
if ch["ch_name"] in nan_chs:
Expand Down
2 changes: 1 addition & 1 deletion mne_bids/tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_update_sidecar_jsons(

# error should raise if the file path doesn't exist
error_bids_path = sidecar_path.copy().update(subject="02")
with pytest.raises(RuntimeError, match="Sidecar file " "does not exist."):
with pytest.raises(RuntimeError, match="Sidecar file does not exist."):
update_sidecar_json(error_bids_path, _get_sidecar_json_update_file)


Expand Down
10 changes: 5 additions & 5 deletions mne_bids/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

warning_str = dict(
channel_unit_changed="ignore:The unit for chann*.:RuntimeWarning:mne",
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:" "mne",
meas_date_set_to_none="ignore:.*'meas_date' set to None:RuntimeWarning:mne",
nasion_not_found="ignore:.*nasion not found:RuntimeWarning:mne",
unraisable_exception="ignore:.*Exception ignored.*:"
"pytest.PytestUnraisableExceptionWarning",
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def test_eegieeg(dir_name, fname, reader, _bids_validate, tmp_path):

# electrodes are not written w/o landmarks
with pytest.raises(
RuntimeError, match="'head' coordinate frame must " "contain nasion"
RuntimeError, match="'head' coordinate frame must contain nasion"
):
if warning_to_catch[dir_name] is None:
write_raw_bids(**kwargs)
Expand Down Expand Up @@ -3048,7 +3048,7 @@ def test_coordsystem_json_compliance(
_write_json(coordsystem_fname, new_coordsystem_json, overwrite=True)
kwargs.update(bids_path=bids_path.copy().update(run="03"))
with pytest.raises(
RuntimeError, match="Trying to write coordsystem.json, " "but it already exists"
RuntimeError, match="Trying to write coordsystem.json, but it already exists"
):
write_raw_bids(**kwargs)
_write_json(coordsystem_fname, coordsystem_json, overwrite=True)
Expand All @@ -3068,7 +3068,7 @@ def test_coordsystem_json_compliance(
kwargs.update(bids_path=bids_path.copy().update(run="04"))
with pytest.raises(
RuntimeError,
match="Trying to write electrodes.tsv, " "but it already exists",
match="Trying to write electrodes.tsv, but it already exists",
):
write_raw_bids(**kwargs)

Expand Down Expand Up @@ -3459,7 +3459,7 @@ def test_error_write_meg_as_eeg(dir_name, format, fname, reader, tmp_path):

# if we accidentally add MEG channels, then an error will occur
raw.set_channel_types({raw.info["ch_names"][0]: "mag"})
with pytest.raises(ValueError, match="Got file extension .*" "for MEG data"):
with pytest.raises(ValueError, match="Got file extension .*for MEG data"):
write_raw_bids(**kwargs)


Expand Down
Loading

0 comments on commit 598ff7f

Please sign in to comment.