Skip to content

Commit b97da43

Browse files
cbrnrlarsoner
andauthored
Replace tmpdir with tmp_path (#9925)
* Replace tmpdir with tmp_path * Fix flake8 * Fix some joins * Fix test_annotations.py * More path join fixes * Even more fixes * More fixes * Hopefully final set of fixes * More fun with tmp_dir.joins * Missing ) * More... * Moar! * Fix test * Use _check_fname() instead of str() * Forgot argument * Set overwrite=True * Fix more joins * Missing parens * Replace more tmpdir with tmp_path * Convert Path to str * Overwrite * Forgot merge conflict * FIX: Specific Co-authored-by: Eric Larson <[email protected]>
1 parent 1221b9c commit b97da43

File tree

81 files changed

+769
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+769
-750
lines changed

mne/beamformer/tests/test_dics.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _make_rand_csd(info, csd):
150150
pytest.param(False, marks=pytest.mark.slowtest),
151151
True,
152152
])
153-
def test_make_dics(tmpdir, _load_forward, idx, whiten):
153+
def test_make_dics(tmp_path, _load_forward, idx, whiten):
154154
"""Test making DICS beamformer filters."""
155155
# We only test proper handling of parameters here. Testing the results is
156156
# done in test_apply_dics_timeseries and test_apply_dics_csd.
@@ -319,7 +319,7 @@ def test_make_dics(tmpdir, _load_forward, idx, whiten):
319319
# Test whether spatial filter contains src_type
320320
assert 'src_type' in filters
321321

322-
fname = op.join(str(tmpdir), 'filters-dics.h5')
322+
fname = op.join(str(tmp_path), 'filters-dics.h5')
323323
filters.save(fname)
324324
filters_read = read_beamformer(fname)
325325
assert isinstance(filters, Beamformer)

mne/beamformer/tests/test_lcmv.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def test_lcmv_vector():
214214
(0.01, False, 'surface'),
215215
(0., True, 'surface'),
216216
])
217-
def test_make_lcmv_bem(tmpdir, reg, proj, kind):
217+
def test_make_lcmv_bem(tmp_path, reg, proj, kind):
218218
"""Test LCMV with evoked data and single trials."""
219219
raw, epochs, evoked, data_cov, noise_cov, label, forward,\
220220
forward_surf_ori, forward_fixed, forward_vol = _get_data(proj=proj)
@@ -304,7 +304,7 @@ def test_make_lcmv_bem(tmpdir, reg, proj, kind):
304304
assert 'rank %s' % rank in repr(filters)
305305

306306
# I/O
307-
fname = op.join(str(tmpdir), 'filters.h5')
307+
fname = op.join(str(tmp_path), 'filters.h5')
308308
with pytest.warns(RuntimeWarning, match='-lcmv.h5'):
309309
filters.save(fname)
310310
filters_read = read_beamformer(fname)

mne/channels/tests/test_channels.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ def test_set_channel_types():
178178
pytest.raises(ValueError, raw.set_channel_types, ch_types)
179179

180180

181-
def test_read_ch_adjacency(tmpdir):
181+
def test_read_ch_adjacency(tmp_path):
182182
"""Test reading channel adjacency templates."""
183-
tempdir = str(tmpdir)
183+
tempdir = str(tmp_path)
184184
a = partial(np.array, dtype='<U7')
185185
# no pep8
186186
nbh = np.array([[(['MEG0111'], [[a(['MEG0131'])]]),

mne/channels/tests/test_layout.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def _get_test_info():
5252
return test_info
5353

5454

55-
def test_io_layout_lout(tmpdir):
55+
def test_io_layout_lout(tmp_path):
5656
"""Test IO with .lout files."""
57-
tempdir = str(tmpdir)
57+
tempdir = str(tmp_path)
5858
layout = read_layout('Vectorview-all', scale=False)
5959
layout.save(op.join(tempdir, 'foobar.lout'))
6060
layout_read = read_layout(op.join(tempdir, 'foobar.lout'), path='./',
@@ -64,9 +64,9 @@ def test_io_layout_lout(tmpdir):
6464
print(layout) # test repr
6565

6666

67-
def test_io_layout_lay(tmpdir):
67+
def test_io_layout_lay(tmp_path):
6868
"""Test IO with .lay files."""
69-
tempdir = str(tmpdir)
69+
tempdir = str(tmp_path)
7070
layout = read_layout('CTF151', scale=False)
7171
layout.save(op.join(tempdir, 'foobar.lay'))
7272
layout_read = read_layout(op.join(tempdir, 'foobar.lay'), path='./',
@@ -139,9 +139,9 @@ def test_find_topomap_coords():
139139
_find_topomap_coords(info, picks, **kwargs)
140140

141141

142-
def test_make_eeg_layout(tmpdir):
142+
def test_make_eeg_layout(tmp_path):
143143
"""Test creation of EEG layout."""
144-
tempdir = str(tmpdir)
144+
tempdir = str(tmp_path)
145145
tmp_name = 'foo'
146146
lout_name = 'test_raw'
147147
lout_orig = read_layout(kind=lout_name, path=lout_path)
@@ -165,9 +165,9 @@ def test_make_eeg_layout(tmpdir):
165165
pytest.raises(ValueError, make_eeg_layout, info, height=1.1)
166166

167167

168-
def test_make_grid_layout(tmpdir):
168+
def test_make_grid_layout(tmp_path):
169169
"""Test creation of grid layout."""
170-
tempdir = str(tmpdir)
170+
tempdir = str(tmp_path)
171171
tmp_name = 'bar'
172172
lout_name = 'test_ica'
173173
lout_orig = read_layout(kind=lout_name, path=lout_path)

mne/channels/tests/test_montage.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _get_dig_montage_pos(montage):
104104
return np.array([d['r'] for d in _get_dig_eeg(montage.dig)])
105105

106106

107-
def test_dig_montage_trans(tmpdir):
107+
def test_dig_montage_trans(tmp_path):
108108
"""Test getting a trans from and applying a trans to a montage."""
109109
nasion, lpa, rpa, *ch_pos = np.random.RandomState(0).randn(10, 3)
110110
ch_pos = {f'EEG{ii:3d}': pos for ii, pos in enumerate(ch_pos, 1)}
@@ -113,7 +113,7 @@ def test_dig_montage_trans(tmpdir):
113113
trans = compute_native_head_t(montage)
114114
_ensure_trans(trans)
115115
# ensure that we can save and load it, too
116-
fname = tmpdir.join('temp-mon.fif')
116+
fname = tmp_path / 'temp-mon.fif'
117117
_check_roundtrip(montage, fname, 'mri')
118118
# test applying a trans
119119
position1 = montage.get_positions()
@@ -436,10 +436,10 @@ def test_documented():
436436
id='brainvision'),
437437
])
438438
def test_montage_readers(
439-
reader, file_content, expected_dig, ext, warning, tmpdir
439+
reader, file_content, expected_dig, ext, warning, tmp_path
440440
):
441441
"""Test that we have an equivalent of read_montage for all file formats."""
442-
fname = op.join(str(tmpdir), 'test.{ext}'.format(ext=ext))
442+
fname = op.join(str(tmp_path), 'test.{ext}'.format(ext=ext))
443443
with open(fname, 'w') as fid:
444444
fid.write(file_content)
445445

@@ -485,7 +485,7 @@ def test_read_locs():
485485
)
486486

487487

488-
def test_read_dig_dat(tmpdir):
488+
def test_read_dig_dat(tmp_path):
489489
"""Test reading *.dat electrode locations."""
490490
rows = [
491491
['Nasion', 78, 0.00, 1.00, 0.00],
@@ -496,7 +496,7 @@ def test_read_dig_dat(tmpdir):
496496
['Centroid', 67, 0.00, 0.00, 0.00],
497497
]
498498
# write mock test.dat file
499-
temp_dir = str(tmpdir)
499+
temp_dir = str(tmp_path)
500500
fname_temp = op.join(temp_dir, 'test.dat')
501501
with open(fname_temp, 'w') as fid:
502502
for row in rows:
@@ -574,12 +574,12 @@ def test_read_dig_montage_using_polhemus_fastscan():
574574
assert_allclose(val, EXPECTED_FID_IN_POLHEMUS[kk])
575575

576576

577-
def test_read_dig_montage_using_polhemus_fastscan_error_handling(tmpdir):
577+
def test_read_dig_montage_using_polhemus_fastscan_error_handling(tmp_path):
578578
"""Test reading Polhemus FastSCAN errors."""
579579
with open(op.join(kit_dir, 'test_elp.txt')) as fid:
580580
content = fid.read().replace('FastSCAN', 'XxxxXXXX')
581581

582-
fname = str(tmpdir.join('faulty_FastSCAN.txt'))
582+
fname = tmp_path / 'faulty_FastSCAN.txt'
583583
with open(fname, 'w') as fid:
584584
fid.write(content)
585585

@@ -588,7 +588,7 @@ def test_read_dig_montage_using_polhemus_fastscan_error_handling(tmpdir):
588588

589589
EXPECTED_ERR_MSG = "allowed value is '.txt', but got '.bar' instead"
590590
with pytest.raises(ValueError, match=EXPECTED_ERR_MSG):
591-
_ = read_polhemus_fastscan(fname=tmpdir.join('foo.bar'))
591+
_ = read_polhemus_fastscan(fname=tmp_path / 'foo.bar')
592592

593593

594594
def test_read_dig_polhemus_isotrak_hsp():
@@ -633,13 +633,13 @@ def test_read_dig_polhemus_isotrak_elp():
633633

634634

635635
@pytest.fixture(scope='module')
636-
def isotrak_eeg(tmpdir_factory):
636+
def isotrak_eeg(tmp_path_factory):
637637
"""Mock isotrak file with EEG positions."""
638638
_SEED = 42
639639
N_ROWS, N_COLS = 5, 3
640640
content = np.random.RandomState(_SEED).randn(N_ROWS, N_COLS)
641641

642-
fname = tmpdir_factory.mktemp('data').join('test.eeg')
642+
fname = tmp_path_factory.mktemp('data') / 'test.eeg'
643643
with open(str(fname), 'w') as fid:
644644
fid.write((
645645
'3 200\n'
@@ -695,7 +695,7 @@ def test_read_dig_polhemus_isotrak_eeg(isotrak_eeg):
695695
assert dig_point['coord_frame'] == FIFF.FIFFV_COORD_UNKNOWN
696696

697697

698-
def test_read_dig_polhemus_isotrak_error_handling(isotrak_eeg, tmpdir):
698+
def test_read_dig_polhemus_isotrak_error_handling(isotrak_eeg, tmp_path):
699699
"""Test errors in reading Polhemus IsoTrak files.
700700
701701
1 - matching ch_names and number of points in isotrak file.
@@ -711,7 +711,7 @@ def test_read_dig_polhemus_isotrak_error_handling(isotrak_eeg, tmpdir):
711711
)
712712

713713
# Check fname extensions
714-
fname = op.join(tmpdir, 'foo.bar')
714+
fname = op.join(tmp_path, 'foo.bar')
715715
with pytest.raises(
716716
ValueError,
717717
match="Allowed val.*'.hsp', '.elp', and '.eeg', but got '.bar' instead"
@@ -857,12 +857,12 @@ def test_set_dig_montage():
857857

858858

859859
@testing.requires_testing_data
860-
def test_fif_dig_montage(tmpdir):
860+
def test_fif_dig_montage(tmp_path):
861861
"""Test FIF dig montage support."""
862862
dig_montage = read_dig_fif(fif_dig_montage_fname)
863863

864864
# test round-trip IO
865-
temp_dir = str(tmpdir)
865+
temp_dir = str(tmp_path)
866866
fname_temp = op.join(temp_dir, 'test.fif')
867867
_check_roundtrip(dig_montage, fname_temp)
868868

@@ -919,7 +919,7 @@ def test_fif_dig_montage(tmpdir):
919919

920920

921921
@testing.requires_testing_data
922-
def test_egi_dig_montage(tmpdir):
922+
def test_egi_dig_montage(tmp_path):
923923
"""Test EGI MFF XML dig montage support."""
924924
dig_montage = read_dig_egi(egi_dig_montage_fname)
925925
fid, coord = _get_fid_coords(dig_montage.dig)
@@ -957,7 +957,7 @@ def test_egi_dig_montage(tmpdir):
957957
)
958958

959959
# test round-trip IO
960-
fname_temp = tmpdir.join('egi_test.fif')
960+
fname_temp = tmp_path / 'egi_test.fif'
961961
_check_roundtrip(dig_montage, fname_temp, 'unknown')
962962
_check_roundtrip(dig_montage_in_head, fname_temp)
963963

@@ -974,7 +974,7 @@ def _pop_montage(dig_montage, ch_name):
974974

975975

976976
@testing.requires_testing_data
977-
def test_read_dig_captrak(tmpdir):
977+
def test_read_dig_captrak(tmp_path):
978978
"""Test reading a captrak montage file."""
979979
EXPECTED_CH_NAMES_OLD = [
980980
'AF3', 'AF4', 'AF7', 'AF8', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'CP1',
@@ -1006,7 +1006,8 @@ def test_read_dig_captrak(tmpdir):
10061006
)
10071007

10081008
montage = transform_to_head(montage) # transform_to_head has to be tested
1009-
_check_roundtrip(montage=montage, fname=str(tmpdir.join('bvct_test.fif')))
1009+
_check_roundtrip(montage=montage,
1010+
fname=str(tmp_path / 'bvct_test.fif'))
10101011

10111012
fid, _ = _get_fid_coords(montage.dig)
10121013
assert_allclose(
@@ -1607,7 +1608,7 @@ def test_montage_add_fiducials():
16071608
assert all([d['kind'] != FIFF.FIFFV_POINT_CARDINAL for d in montage.dig])
16081609

16091610

1610-
def test_read_dig_localite(tmpdir):
1611+
def test_read_dig_localite(tmp_path):
16111612
"""Test reading Localite .csv file."""
16121613
contents = """#,id,x,y,z
16131614
1,Nasion,-2.016253511,6.243001715,34.63167712
@@ -1629,7 +1630,7 @@ def test_read_dig_localite(tmpdir):
16291630
17,ch14,-61.16539571,-61.86866187,26.23986153
16301631
18,ch15,-55.82855386,-34.77319103,25.8083942"""
16311632

1632-
fname = tmpdir / 'localite.csv'
1633+
fname = tmp_path / 'localite.csv'
16331634
with open(fname, 'w') as f:
16341635
for row in contents.split('\n'):
16351636
f.write(f'{row.lstrip()}\n')

0 commit comments

Comments
 (0)