Skip to content

Commit a42321f

Browse files
committed
TEST: Use a less finicky method of creating temporary files
1 parent 2eba8db commit a42321f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

nibabel/streamlines/tests/test_streamlines.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def setup():
8484
)
8585

8686

87-
def test_is_supported_detect_format():
87+
def test_is_supported_detect_format(tmp_path):
8888
# Test is_supported and detect_format functions
8989
# Empty file/string
9090
f = BytesIO()
@@ -103,15 +103,17 @@ def test_is_supported_detect_format():
103103

104104
# Wrong extension but right magic number
105105
for tfile_cls in FORMATS.values():
106-
with tempfile.TemporaryFile(mode='w+b', suffix='.txt') as f:
106+
fpath = tmp_path / 'test.txt'
107+
with open(fpath, 'w+b') as f:
107108
f.write(asbytes(tfile_cls.MAGIC_NUMBER))
108109
f.seek(0, os.SEEK_SET)
109110
assert nib.streamlines.is_supported(f)
110111
assert nib.streamlines.detect_format(f) is tfile_cls
111112

112113
# Good extension but wrong magic number
113114
for ext, tfile_cls in FORMATS.items():
114-
with tempfile.TemporaryFile(mode='w+b', suffix=ext) as f:
115+
fpath = tmp_path / f'test{ext}'
116+
with open(fpath, 'w+b') as f:
115117
f.write(b'pass')
116118
f.seek(0, os.SEEK_SET)
117119
assert not nib.streamlines.is_supported(f)

0 commit comments

Comments
 (0)