Skip to content

Commit 1e597f1

Browse files
committed
FIX: Some [skip circle]
1 parent 2f35fb9 commit 1e597f1

10 files changed

Lines changed: 55 additions & 14 deletions

File tree

mne/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
Bunch,
4040
_assert_no_instances,
4141
_check_qt_version,
42+
_chmod_rw_R,
4243
_pl,
4344
_record_warnings,
4445
_TempDir,
@@ -771,6 +772,7 @@ def subjects_dir_tmp(tmp_path):
771772
"""Copy MNE-testing-data subjects_dir to a temp dir for manipulation."""
772773
for key in ("sample", "fsaverage"):
773774
shutil.copytree(op.join(subjects_dir, key), str(tmp_path / key))
775+
_chmod_rw_R(tmp_path)
774776
return str(tmp_path)
775777

776778

@@ -788,6 +790,7 @@ def subjects_dir_tmp_few(tmp_path):
788790
shutil.copytree(
789791
test_path / "subjects" / "sample" / dirname, sample_path / dirname
790792
)
793+
_chmod_rw_R(subjects_path)
791794
return subjects_path
792795

793796

mne/io/ctf/tests/test_ctf.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@
3232
from mne.io.tests.test_raw import _test_raw_reader
3333
from mne.tests.test_annotations import _assert_annotations_equal
3434
from mne.transforms import apply_trans
35-
from mne.utils import _clean_names, _record_warnings, _stamp_to_dt, catch_logging
35+
from mne.utils import (
36+
_clean_names,
37+
_record_warnings,
38+
_stamp_to_dt,
39+
catch_logging,
40+
copytree_rw,
41+
)
3642

3743
ctf_dir = testing.data_path(download=False) / "CTF"
3844
ctf_fname_continuous = "testdata_ctf.ds"
@@ -75,7 +81,7 @@ def test_read_ctf(tmp_path):
7581
# Create a dummy .eeg file so we can test our reading/application of it
7682
os.mkdir(op.join(temp_dir, "randpos"))
7783
ctf_eeg_fname = op.join(temp_dir, "randpos", ctf_fname_catch)
78-
shutil.copytree(op.join(ctf_dir, ctf_fname_catch), ctf_eeg_fname)
84+
copytree_rw(op.join(ctf_dir, ctf_fname_catch), ctf_eeg_fname)
7985
with pytest.warns(RuntimeWarning, match="RMSP .* changed to a MISC ch"):
8086
raw = _test_raw_reader(read_raw_ctf, directory=ctf_eeg_fname)
8187
picks = pick_types(raw.info, meg=False, eeg=True)
@@ -689,7 +695,7 @@ def _bad_res4_grad_comp(dsdir):
689695
def test_missing_res4(tmp_path):
690696
"""Test that res4 missing is handled gracefully."""
691697
use_ds = tmp_path / ctf_fname_continuous
692-
shutil.copytree(ctf_dir / ctf_fname_continuous, tmp_path / ctf_fname_continuous)
698+
copytree_rw(ctf_dir / ctf_fname_continuous, tmp_path / ctf_fname_continuous)
693699
read_raw_ctf(use_ds)
694700
os.remove(use_ds / (ctf_fname_continuous[:-2] + "meg4"))
695701
with pytest.raises(OSError, match="could not find the following"):

mne/io/egi/tests/test_egi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from mne.io import read_evokeds_mff, read_raw_egi, read_raw_fif
2121
from mne.io.egi.egi import _combine_triggers
2222
from mne.io.tests.test_raw import _test_raw_reader
23-
from mne.utils import object_diff
23+
from mne.utils import _chmod_rw_R, object_diff
2424

2525
base_dir = Path(__file__).parent / "data"
2626
egi_fname = base_dir / "test_egi.raw"
@@ -338,6 +338,7 @@ def test_io_egi_pns_mff(tmp_path):
338338
# EEG missing
339339
new_mff = tmp_path / "temp.mff"
340340
shutil.copytree(egi_mff_pns_fname, new_mff)
341+
_chmod_rw_R(new_mff)
341342
read_raw_egi(new_mff, verbose="error")
342343
os.remove(new_mff / "info1.xml")
343344
os.remove(new_mff / "signal1.bin")
@@ -594,6 +595,7 @@ def test_egi_mff_bad_xml(tmp_path):
594595
"""Test that corrupt XML files are gracefully handled."""
595596
pytest.importorskip("defusedxml")
596597
mff_fname = shutil.copytree(egi_mff_fname, tmp_path / "test_egi_bad_xml.mff")
598+
_chmod_rw_R(mff_fname)
597599
bad_xml = mff_fname / "bad.xml"
598600
bad_xml.write_text("<foo>", encoding="utf-8")
599601
# Missing coordinate file

mne/io/fil/tests/test_fil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License: BSD-3-Clause
33
# Copyright the MNE-Python contributors.
44

5-
import shutil
65
from os import remove
76

87
import pytest
@@ -14,6 +13,7 @@
1413
from mne.datasets import testing
1514
from mne.io import read_raw_fil
1615
from mne.io.fil.sensors import _get_pos_units
16+
from mne.utils import copytree_rw
1717

1818
fil_path = testing.data_path(download=False) / "FIL"
1919

@@ -161,7 +161,7 @@ def test_fil_complete():
161161
def test_fil_no_positions(tmp_path):
162162
"""Test FIL reader in cases where a position file is missing."""
163163
test_path = tmp_path / "FIL"
164-
shutil.copytree(fil_path, test_path)
164+
copytree_rw(fil_path, test_path)
165165

166166
posname = test_path / "sub-noise_ses-001_task-noise220622_run-001_positions.tsv"
167167
binname = test_path / "sub-noise_ses-001_task-noise220622_run-001_meg.bin"
@@ -179,7 +179,7 @@ def test_fil_no_positions(tmp_path):
179179
def test_fil_bad_channel_spec(tmp_path):
180180
"""Test FIL reader when a bad channel is specified in channels.tsv."""
181181
test_path = tmp_path / "FIL"
182-
shutil.copytree(fil_path, test_path)
182+
copytree_rw(fil_path, test_path)
183183

184184
channame = test_path / "sub-noise_ses-001_task-noise220622_run-001_channels.tsv"
185185
binname = test_path / "sub-noise_ses-001_task-noise220622_run-001_meg.bin"

mne/io/nirx/tests/test_nirx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import datetime as dt
66
import os
7-
import shutil
87

98
import numpy as np
109
import pytest
@@ -22,6 +21,7 @@
2221
source_detector_distances,
2322
)
2423
from mne.transforms import _get_trans, apply_trans
24+
from mne.utils import copytree_rw
2525

2626
testing_path = data_path(download=False)
2727
fname_nirx_15_0 = testing_path / "NIRx" / "nirscout" / "nirx_15_0_recording"
@@ -246,7 +246,7 @@ def test_nirx_missing_warn():
246246
@requires_testing_data
247247
def test_nirx_missing_evt(tmp_path):
248248
"""Test reading NIRX files when missing data."""
249-
shutil.copytree(fname_nirx_15_2_short, str(tmp_path) + "/data/")
249+
copytree_rw(fname_nirx_15_2_short, str(tmp_path) + "/data/")
250250
os.rename(
251251
tmp_path / "data" / "NIRS-2019-08-23_001.evt",
252252
tmp_path / "data" / "NIRS-2019-08-23_001.xxx",
@@ -259,7 +259,7 @@ def test_nirx_missing_evt(tmp_path):
259259
@requires_testing_data
260260
def test_nirx_dat_warn(tmp_path):
261261
"""Test reading NIRX files when missing data."""
262-
shutil.copytree(fname_nirx_15_2_short, str(tmp_path) + "/data/")
262+
copytree_rw(fname_nirx_15_2_short, str(tmp_path) + "/data/")
263263
os.rename(
264264
tmp_path / "data" / "NIRS-2019-08-23_001.dat",
265265
tmp_path / "data" / "NIRS-2019-08-23_001.tmp",
@@ -461,7 +461,7 @@ def test_nirx_15_3_short():
461461
def test_locale_encoding(tmp_path):
462462
"""Test NIRx encoding."""
463463
fname = tmp_path / "latin"
464-
shutil.copytree(fname_nirx_15_2, fname)
464+
copytree_rw(fname_nirx_15_2, fname)
465465
hdr_fname = fname / "NIRS-2019-10-02_003.hdr"
466466
hdr = list()
467467
with open(hdr_fname, "rb") as fid:

mne/io/persyst/tests/test_persyst.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from mne.datasets.testing import data_path, requires_testing_data
1313
from mne.io import read_raw_persyst
1414
from mne.io.tests.test_raw import _test_raw_reader
15+
from mne.utils import _chmod_rw_R
1516

1617
testing_path = data_path(download=False)
1718
fname_lay = (
@@ -144,6 +145,7 @@ def test_persyst_moved_file(tmp_path):
144145
new_fname_lay = tmp_path / fname_lay.name
145146
new_fname_dat = tmp_path / fname_dat.name
146147
shutil.copy(fname_lay, new_fname_lay)
148+
_chmod_rw_R(tmp_path)
147149

148150
# original file read should work
149151
read_raw_persyst(fname_lay)

mne/io/snirf/tests/test_snirf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
source_detector_distances,
2929
)
3030
from mne.transforms import _get_trans, apply_trans
31-
from mne.utils import catch_logging
31+
from mne.utils import _chmod_rw_R, catch_logging
3232

3333
testing_path = data_path(download=False)
3434
# SfNIRS files
@@ -252,8 +252,9 @@ def test_snirf_against_nirx():
252252
@requires_testing_data
253253
def test_snirf_nonstandard(tmp_path):
254254
"""Test custom tags."""
255-
shutil.copy(sfnirs_homer_103_wShort, str(tmp_path) + "/mod.snirf")
256255
fname = str(tmp_path) + "/mod.snirf"
256+
shutil.copy(sfnirs_homer_103_wShort, fname)
257+
_chmod_rw_R(tmp_path)
257258
# Manually mark up the file to match MNE-NIRS custom tags
258259
with h5py.File(fname, "r+") as f:
259260
f.create_dataset("nirs/metaDataTags/middleName", data=[b"X"])
@@ -287,8 +288,9 @@ def test_snirf_nonstandard(tmp_path):
287288
@requires_testing_data
288289
def test_snirf_empty_landmark_labels(tmp_path):
289290
"""Test reading SNIRF files with empty landmarkLabels (gh-13627)."""
290-
shutil.copy(sfnirs_homer_103_wShort, tmp_path / "empty_labels.snirf")
291291
fname = tmp_path / "empty_labels.snirf"
292+
shutil.copy(sfnirs_homer_103_wShort, fname)
293+
_chmod_rw_R(tmp_path)
292294

293295
# Modify file to have landmarkPos3D but empty/scalar landmarkLabels
294296
with h5py.File(fname, "r+") as f:
@@ -586,6 +588,7 @@ def test_sample_rate_jitter(tmp_path):
586588
# Create a clean copy and ensure it loads without error
587589
new_file = tmp_path / "snirf_nirsport2_2019.snirf"
588590
copy2(snirf_nirsport2_20219, new_file)
591+
_chmod_rw_R(tmp_path)
589592
read_raw_snirf(new_file)
590593

591594
# Edit the file and add jitter within tolerance (0.99%)

mne/tests/test_bem.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from mne.surface import _get_ico_surface, read_surface
4545
from mne.transforms import translation
4646
from mne.utils import (
47+
_chmod_rw_R,
4748
_record_warnings,
4849
catch_logging,
4950
check_version,
@@ -231,6 +232,7 @@ def test_bem_model_topology(tmp_path):
231232
subjects_dir / "sample" / "bem" / fname,
232233
tmp_path / "foo" / "bem" / fname,
233234
)
235+
_chmod_rw_R(tmp_path)
234236
outer_fname = tmp_path / "foo" / "bem" / "outer_skull.surf"
235237
rr, tris = read_surface(outer_fname)
236238
tris = tris[:-1]

mne/utils/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ __all__ = [
5656
"_check_stc_units",
5757
"_check_subject",
5858
"_check_time_format",
59+
"_chmod_rw_R",
5960
"_clean_names",
6061
"_click_ch_name",
6162
"_compute_row_norms",
@@ -202,6 +203,7 @@ from ._logging import (
202203
)
203204
from ._testing import (
204205
ArgvSetter,
206+
_chmod_rw_R,
205207
_click_ch_name,
206208
_raw_annot,
207209
_TempDir,

mne/utils/_testing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import inspect
88
import os
9+
import shutil
910
import sys
1011
import tempfile
1112
import traceback
@@ -417,3 +418,23 @@ def assert_trans_allclose(actual, desired, dist_tol=0.0, angle_tol=0.0):
417418
f"{1000 * dist:0.3f} > {1000 * dist_tol:0.3f} mm translation"
418419
)
419420
assert angle <= angle_tol, f"{angle:0.3f} > {angle_tol:0.3f}° rotation"
421+
422+
423+
def _chmod_rw_R(path):
424+
assert os.path.isdir(path), f"Expected a directory, got {path}"
425+
os.chmod(path, 0o700 | os.stat(path).st_mode)
426+
for root, dirs, files in os.walk(path):
427+
for name in files:
428+
this_name = os.path.join(root, name)
429+
os.chmod(this_name, 0o600 | os.stat(this_name).st_mode)
430+
for name in dirs:
431+
this_name = os.path.join(root, name)
432+
os.chmod(this_name, 0o770 | os.stat(this_name).st_mode)
433+
434+
435+
def copytree_rw(src, dst):
436+
"""Copy a directory tree and make it read/write."""
437+
assert os.path.isdir(src), f"Expected a directory, got {src}"
438+
shutil.copytree(src, dst)
439+
_chmod_rw_R(dst)
440+
return dst

0 commit comments

Comments
 (0)