|
8 | 8 | from pathlib import Path
|
9 | 9 |
|
10 | 10 | import numpy as np
|
| 11 | +import pooch |
11 | 12 | import pytest
|
| 13 | +from flaky import flaky |
12 | 14 | from numpy.testing import assert_allclose, assert_array_equal, assert_equal
|
13 | 15 | from scipy.io import savemat
|
14 | 16 |
|
|
35 | 37 | )
|
36 | 38 | from mne.channels.channels import (
|
37 | 39 | _BUILTIN_CHANNEL_ADJACENCIES,
|
38 |
| - _BuiltinChannelAdjacency, |
39 | 40 | _ch_neighbor_adjacency,
|
40 | 41 | _compute_ch_adjacency,
|
41 | 42 | )
|
|
49 | 50 | read_raw_fif,
|
50 | 51 | read_raw_kit,
|
51 | 52 | )
|
52 |
| -from mne.parallel import parallel_func |
53 | 53 | from mne.utils import requires_good_network
|
54 | 54 |
|
55 | 55 | io_dir = Path(__file__).parents[2] / "io"
|
@@ -348,64 +348,34 @@ def test_read_ch_adjacency(tmp_path):
|
348 | 348 | pytest.raises(ValueError, read_ch_adjacency, mat_fname)
|
349 | 349 |
|
350 | 350 |
|
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] |
353 | 352 |
|
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 |
359 | 353 |
|
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 |
380 | 358 | @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): |
382 | 361 | """Test correspondence of built-in adjacency matrices with FT repo."""
|
383 | 362 | builtin_neighbors_dir = Path(__file__).parents[1] / "data" / "neighbors"
|
384 | 363 | ft_neighbors_dir = tmp_path
|
385 | 364 | 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 | + ) |
409 | 379 |
|
410 | 380 |
|
411 | 381 | def test_get_set_sensor_positions():
|
|
0 commit comments