@@ -104,7 +104,7 @@ def _get_dig_montage_pos(montage):
104
104
return np .array ([d ['r' ] for d in _get_dig_eeg (montage .dig )])
105
105
106
106
107
- def test_dig_montage_trans (tmpdir ):
107
+ def test_dig_montage_trans (tmp_path ):
108
108
"""Test getting a trans from and applying a trans to a montage."""
109
109
nasion , lpa , rpa , * ch_pos = np .random .RandomState (0 ).randn (10 , 3 )
110
110
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):
113
113
trans = compute_native_head_t (montage )
114
114
_ensure_trans (trans )
115
115
# ensure that we can save and load it, too
116
- fname = tmpdir . join ( 'temp-mon.fif' )
116
+ fname = tmp_path / 'temp-mon.fif'
117
117
_check_roundtrip (montage , fname , 'mri' )
118
118
# test applying a trans
119
119
position1 = montage .get_positions ()
@@ -436,10 +436,10 @@ def test_documented():
436
436
id = 'brainvision' ),
437
437
])
438
438
def test_montage_readers (
439
- reader , file_content , expected_dig , ext , warning , tmpdir
439
+ reader , file_content , expected_dig , ext , warning , tmp_path
440
440
):
441
441
"""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 ))
443
443
with open (fname , 'w' ) as fid :
444
444
fid .write (file_content )
445
445
@@ -485,7 +485,7 @@ def test_read_locs():
485
485
)
486
486
487
487
488
- def test_read_dig_dat (tmpdir ):
488
+ def test_read_dig_dat (tmp_path ):
489
489
"""Test reading *.dat electrode locations."""
490
490
rows = [
491
491
['Nasion' , 78 , 0.00 , 1.00 , 0.00 ],
@@ -496,7 +496,7 @@ def test_read_dig_dat(tmpdir):
496
496
['Centroid' , 67 , 0.00 , 0.00 , 0.00 ],
497
497
]
498
498
# write mock test.dat file
499
- temp_dir = str (tmpdir )
499
+ temp_dir = str (tmp_path )
500
500
fname_temp = op .join (temp_dir , 'test.dat' )
501
501
with open (fname_temp , 'w' ) as fid :
502
502
for row in rows :
@@ -574,12 +574,12 @@ def test_read_dig_montage_using_polhemus_fastscan():
574
574
assert_allclose (val , EXPECTED_FID_IN_POLHEMUS [kk ])
575
575
576
576
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 ):
578
578
"""Test reading Polhemus FastSCAN errors."""
579
579
with open (op .join (kit_dir , 'test_elp.txt' )) as fid :
580
580
content = fid .read ().replace ('FastSCAN' , 'XxxxXXXX' )
581
581
582
- fname = str ( tmpdir . join ( 'faulty_FastSCAN.txt' ))
582
+ fname = tmp_path / 'faulty_FastSCAN.txt'
583
583
with open (fname , 'w' ) as fid :
584
584
fid .write (content )
585
585
@@ -588,7 +588,7 @@ def test_read_dig_montage_using_polhemus_fastscan_error_handling(tmpdir):
588
588
589
589
EXPECTED_ERR_MSG = "allowed value is '.txt', but got '.bar' instead"
590
590
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' )
592
592
593
593
594
594
def test_read_dig_polhemus_isotrak_hsp ():
@@ -633,13 +633,13 @@ def test_read_dig_polhemus_isotrak_elp():
633
633
634
634
635
635
@pytest .fixture (scope = 'module' )
636
- def isotrak_eeg (tmpdir_factory ):
636
+ def isotrak_eeg (tmp_path_factory ):
637
637
"""Mock isotrak file with EEG positions."""
638
638
_SEED = 42
639
639
N_ROWS , N_COLS = 5 , 3
640
640
content = np .random .RandomState (_SEED ).randn (N_ROWS , N_COLS )
641
641
642
- fname = tmpdir_factory .mktemp ('data' ). join ( 'test.eeg' )
642
+ fname = tmp_path_factory .mktemp ('data' ) / 'test.eeg'
643
643
with open (str (fname ), 'w' ) as fid :
644
644
fid .write ((
645
645
'3 200\n '
@@ -695,7 +695,7 @@ def test_read_dig_polhemus_isotrak_eeg(isotrak_eeg):
695
695
assert dig_point ['coord_frame' ] == FIFF .FIFFV_COORD_UNKNOWN
696
696
697
697
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 ):
699
699
"""Test errors in reading Polhemus IsoTrak files.
700
700
701
701
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):
711
711
)
712
712
713
713
# Check fname extensions
714
- fname = op .join (tmpdir , 'foo.bar' )
714
+ fname = op .join (tmp_path , 'foo.bar' )
715
715
with pytest .raises (
716
716
ValueError ,
717
717
match = "Allowed val.*'.hsp', '.elp', and '.eeg', but got '.bar' instead"
@@ -857,12 +857,12 @@ def test_set_dig_montage():
857
857
858
858
859
859
@testing .requires_testing_data
860
- def test_fif_dig_montage (tmpdir ):
860
+ def test_fif_dig_montage (tmp_path ):
861
861
"""Test FIF dig montage support."""
862
862
dig_montage = read_dig_fif (fif_dig_montage_fname )
863
863
864
864
# test round-trip IO
865
- temp_dir = str (tmpdir )
865
+ temp_dir = str (tmp_path )
866
866
fname_temp = op .join (temp_dir , 'test.fif' )
867
867
_check_roundtrip (dig_montage , fname_temp )
868
868
@@ -919,7 +919,7 @@ def test_fif_dig_montage(tmpdir):
919
919
920
920
921
921
@testing .requires_testing_data
922
- def test_egi_dig_montage (tmpdir ):
922
+ def test_egi_dig_montage (tmp_path ):
923
923
"""Test EGI MFF XML dig montage support."""
924
924
dig_montage = read_dig_egi (egi_dig_montage_fname )
925
925
fid , coord = _get_fid_coords (dig_montage .dig )
@@ -957,7 +957,7 @@ def test_egi_dig_montage(tmpdir):
957
957
)
958
958
959
959
# test round-trip IO
960
- fname_temp = tmpdir . join ( 'egi_test.fif' )
960
+ fname_temp = tmp_path / 'egi_test.fif'
961
961
_check_roundtrip (dig_montage , fname_temp , 'unknown' )
962
962
_check_roundtrip (dig_montage_in_head , fname_temp )
963
963
@@ -974,7 +974,7 @@ def _pop_montage(dig_montage, ch_name):
974
974
975
975
976
976
@testing .requires_testing_data
977
- def test_read_dig_captrak (tmpdir ):
977
+ def test_read_dig_captrak (tmp_path ):
978
978
"""Test reading a captrak montage file."""
979
979
EXPECTED_CH_NAMES_OLD = [
980
980
'AF3' , 'AF4' , 'AF7' , 'AF8' , 'C1' , 'C2' , 'C3' , 'C4' , 'C5' , 'C6' , 'CP1' ,
@@ -1006,7 +1006,8 @@ def test_read_dig_captrak(tmpdir):
1006
1006
)
1007
1007
1008
1008
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' ))
1010
1011
1011
1012
fid , _ = _get_fid_coords (montage .dig )
1012
1013
assert_allclose (
@@ -1607,7 +1608,7 @@ def test_montage_add_fiducials():
1607
1608
assert all ([d ['kind' ] != FIFF .FIFFV_POINT_CARDINAL for d in montage .dig ])
1608
1609
1609
1610
1610
- def test_read_dig_localite (tmpdir ):
1611
+ def test_read_dig_localite (tmp_path ):
1611
1612
"""Test reading Localite .csv file."""
1612
1613
contents = """#,id,x,y,z
1613
1614
1,Nasion,-2.016253511,6.243001715,34.63167712
@@ -1629,7 +1630,7 @@ def test_read_dig_localite(tmpdir):
1629
1630
17,ch14,-61.16539571,-61.86866187,26.23986153
1630
1631
18,ch15,-55.82855386,-34.77319103,25.8083942"""
1631
1632
1632
- fname = tmpdir / 'localite.csv'
1633
+ fname = tmp_path / 'localite.csv'
1633
1634
with open (fname , 'w' ) as f :
1634
1635
for row in contents .split ('\n ' ):
1635
1636
f .write (f'{ row .lstrip ()} \n ' )
0 commit comments