diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45b8364c6..501e073d9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,6 +5,7 @@ repos: - id: ruff name: ruff mne_bids/ files: ^mne_bids/ + args: ["--fix"] - id: ruff name: ruff examples/ # D103: missing docstring in public function diff --git a/mne_bids/conftest.py b/mne_bids/conftest.py index 784ef0479..8c1a7a110 100644 --- a/mne_bids/conftest.py +++ b/mne_bids/conftest.py @@ -13,6 +13,15 @@ def pytest_configure(config): config.addinivalue_line("usefixtures", "monkeypatch_mne") +@pytest.fixture(autouse=True) +def close_all(): + """Close all figures after each test.""" + yield + import matplotlib.pyplot as plt + + plt.close("all") + + @pytest.fixture(scope="session") def monkeypatch_mne(): """Monkeypatch MNE to ensure we have download=False everywhere in tests.""" diff --git a/mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py b/mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py index 3ce5f24a3..753e4f81e 100644 --- a/mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py +++ b/mne_bids/tests/data/tiny_bids/code/make_tiny_bids_dataset.py @@ -5,6 +5,7 @@ # %% import json +from datetime import date from pathlib import Path import mne @@ -45,7 +46,7 @@ "last_name": "Musterperson", "first_name": "Maxi", "middle_name": "Luka", - "birthday": (1970, 10, 20), + "birthday": date(1970, 10, 20), "sex": 2, "hand": 3, } diff --git a/mne_bids/tests/test_read.py b/mne_bids/tests/test_read.py index 03ef3aeb3..09a61af4e 100644 --- a/mne_bids/tests/test_read.py +++ b/mne_bids/tests/test_read.py @@ -827,12 +827,9 @@ def test_handle_chpi_reading(tmp_path): with ( pytest.warns(RuntimeWarning, match="Defaulting to .* mne.Raw object"), - pytest.warns( - RuntimeWarning, match="This file contains raw Internal Active Shielding" - ), pytest.warns(RuntimeWarning, match="The unit for channel"), ): - raw_read = read_raw_bids(bids_path) + raw_read = read_raw_bids(bids_path, extra_params=dict(allow_maxshield="yes")) # cHPI "off" according to sidecar, but present in the data meg_json_data_chpi_mismatch = meg_json_data.copy() diff --git a/mne_bids/tests/test_write.py b/mne_bids/tests/test_write.py index 2a35c587d..99c88ce8b 100644 --- a/mne_bids/tests/test_write.py +++ b/mne_bids/tests/test_write.py @@ -14,7 +14,7 @@ import shutil as sh import sys import warnings -from datetime import datetime, timedelta, timezone +from datetime import date, datetime, timedelta, timezone from glob import glob from pathlib import Path @@ -222,9 +222,12 @@ def test_write_participants(_bids_validate, tmp_path): # add fake participants data raw.set_meas_date(datetime(year=1994, month=1, day=26, tzinfo=timezone.utc)) + birthday = (1993, 1, 26) + if check_version("mne", "1.8"): + birthday = date(*birthday) raw.info["subject_info"] = { "his_id": subject_id2, - "birthday": (1993, 1, 26), + "birthday": birthday, "sex": 1, "hand": 2, } @@ -707,9 +710,12 @@ def test_fif(_bids_validate, tmp_path): # data # change the gender but don't force overwrite. raw = _read_raw_fif(raw_fname) + birthday = (1994, 1, 26) + if check_version("mne", "1.8"): + birthday = date(*birthday) raw.info["subject_info"] = { "his_id": subject_id2, - "birthday": (1994, 1, 26), + "birthday": birthday, "sex": 2, "hand": 1, } diff --git a/mne_bids/write.py b/mne_bids/write.py index 19da86847..563454c78 100644 --- a/mne_bids/write.py +++ b/mne_bids/write.py @@ -11,7 +11,7 @@ import sys import warnings from collections import OrderedDict, defaultdict -from datetime import datetime, timedelta, timezone +from datetime import date, datetime, timedelta, timezone from pathlib import Path import mne @@ -456,12 +456,14 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False): # determine the age of the participant age = subject_info.get("birthday", None) + if isinstance(age, tuple): # can be removed once MNE >= 1.8 is required + age = date(*age) meas_date = raw.info.get("meas_date", None) if isinstance(meas_date, (tuple, list, np.ndarray)): meas_date = meas_date[0] if meas_date is not None and age is not None: - bday = datetime(age[0], age[1], age[2], tzinfo=timezone.utc) + bday = datetime(age.year, age.month, age.day, tzinfo=timezone.utc) if isinstance(meas_date, datetime): meas_datetime = meas_date else: diff --git a/pyproject.toml b/pyproject.toml index 272befae4..43fdd09db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ full = [ ] # Dependencies for running the test infrastructure -test = ["mne_bids[full]", "pytest", "pytest-cov", "pytest-sugar", "ruff"] +test = ["mne_bids[full]", "pytest >= 8", "pytest-cov", "pytest-sugar", "ruff"] # Dependencies for building the documentation doc = [ @@ -148,4 +148,6 @@ filterwarnings = [ # old MNE _fake_click "ignore:The .*_event function was deprecated in Matplotlib.*:", "ignore:datetime\\.datetime\\.utcfromtimestamp.* is deprecated and scheduled for removal in a future version.*:DeprecationWarning", + # matplotlib + "ignore:Figure.*is non-interactive.*cannot be shown:UserWarning", ]