Skip to content

Commit 68b5523

Browse files
[pre-commit.ci] pre-commit autoupdate (#13255)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric Larson <larson.eric.d@gmail.com>
1 parent 1ea5dbb commit 68b5523

File tree

3 files changed

+26
-58
lines changed

3 files changed

+26
-58
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
repos:
22
# Ruff mne
33
- repo: https://github.com/astral-sh/ruff-pre-commit
4-
rev: v0.11.9
4+
rev: v0.11.10
55
hooks:
66
- id: ruff
77
name: ruff lint mne

mne/channels/tests/test_channels.py

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
from pathlib import Path
99

1010
import numpy as np
11+
import pooch
1112
import pytest
13+
from flaky import flaky
1214
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
1315
from scipy.io import savemat
1416

@@ -35,7 +37,6 @@
3537
)
3638
from mne.channels.channels import (
3739
_BUILTIN_CHANNEL_ADJACENCIES,
38-
_BuiltinChannelAdjacency,
3940
_ch_neighbor_adjacency,
4041
_compute_ch_adjacency,
4142
)
@@ -49,7 +50,6 @@
4950
read_raw_fif,
5051
read_raw_kit,
5152
)
52-
from mne.parallel import parallel_func
5353
from mne.utils import requires_good_network
5454

5555
io_dir = Path(__file__).parents[2] / "io"
@@ -348,64 +348,34 @@ def test_read_ch_adjacency(tmp_path):
348348
pytest.raises(ValueError, read_ch_adjacency, mat_fname)
349349

350350

351-
def _download_ft_neighbors(target_dir):
352-
"""Download the known neighbors from FieldTrip."""
351+
_CHECK_ADJ = [adj for adj in _BUILTIN_CHANNEL_ADJACENCIES if adj.source_url is not None]
353352

354-
# The entire FT repository is larger than a GB, so we'll just download
355-
# the few files we need.
356-
def _download_one_ft_neighbor(neighbor: _BuiltinChannelAdjacency):
357-
# Log level setting must happen inside the job to work properly
358-
import pooch
359353

360-
pooch.get_logger().setLevel("ERROR") # reduce verbosity
361-
fname = neighbor.fname
362-
url = neighbor.source_url
363-
364-
pooch.retrieve(
365-
url=url,
366-
known_hash=None,
367-
fname=fname,
368-
path=target_dir,
369-
)
370-
371-
parallel, p_fun, _ = parallel_func(func=_download_one_ft_neighbor, n_jobs=-1)
372-
parallel(
373-
p_fun(neighbor)
374-
for neighbor in _BUILTIN_CHANNEL_ADJACENCIES
375-
if neighbor.source_url is not None
376-
)
377-
378-
379-
@pytest.mark.slowtest
354+
# This test is ~15s long across all montages, and we shouldn't need to check super
355+
# often for mismatches. So let's mark it ultraslowtest so only one CI runs it.
356+
@flaky
357+
@pytest.mark.ultraslowtest
380358
@requires_good_network
381-
def test_adjacency_matches_ft(tmp_path):
359+
@pytest.mark.parametrize("adj", _CHECK_ADJ)
360+
def test_adjacency_matches_ft(tmp_path, adj):
382361
"""Test correspondence of built-in adjacency matrices with FT repo."""
383362
builtin_neighbors_dir = Path(__file__).parents[1] / "data" / "neighbors"
384363
ft_neighbors_dir = tmp_path
385364
del tmp_path
386-
387-
_download_ft_neighbors(target_dir=ft_neighbors_dir)
388-
389-
for adj in _BUILTIN_CHANNEL_ADJACENCIES:
390-
fname = adj.fname
391-
if not (ft_neighbors_dir / fname).exists():
392-
continue # only exists in MNE, not FT
393-
394-
hash_mne = hashlib.sha256()
395-
hash_ft = hashlib.sha256()
396-
397-
with open(builtin_neighbors_dir / fname, "rb") as f:
398-
data = f.read()
399-
hash_mne.update(data)
400-
401-
with open(ft_neighbors_dir / fname, "rb") as f:
402-
data = f.read()
403-
hash_ft.update(data)
404-
405-
if hash_mne.hexdigest() != hash_ft.hexdigest():
406-
raise ValueError(
407-
f"Hash mismatch between built-in and FieldTrip neighbors for {fname}"
408-
)
365+
fname = adj.fname
366+
pooch.retrieve(
367+
url=adj.source_url,
368+
known_hash=None,
369+
fname=fname,
370+
path=ft_neighbors_dir,
371+
)
372+
hash_mne = hashlib.sha256()
373+
hash_ft = hashlib.sha256()
374+
hash_mne.update((builtin_neighbors_dir / fname).read_bytes())
375+
hash_ft.update((ft_neighbors_dir / fname).read_bytes())
376+
assert hash_mne.hexdigest() == hash_ft.hexdigest(), (
377+
f"Hash mismatch between built-in and FieldTrip neighbors for {fname}"
378+
)
409379

410380

411381
def test_get_set_sensor_positions():

mne/utils/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,10 @@ def _open_lock(path, *args, **kwargs):
251251

252252
lock_context = contextlib.nullcontext() # default to no lock
253253

254-
if filelock is not None:
254+
if filelock:
255255
lock_path = f"{path}.lock"
256256
try:
257-
from filelock import FileLock
258-
259-
lock_context = FileLock(lock_path, timeout=5)
257+
lock_context = filelock.FileLock(lock_path, timeout=5)
260258
lock_context.acquire()
261259
except TimeoutError:
262260
warn(

0 commit comments

Comments
 (0)