Skip to content

Commit

Permalink
TEST: Use a less finicky method of creating temporary files
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Sep 8, 2023
1 parent 2eba8db commit a42321f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nibabel/streamlines/tests/test_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def setup():
)


def test_is_supported_detect_format():
def test_is_supported_detect_format(tmp_path):
# Test is_supported and detect_format functions
# Empty file/string
f = BytesIO()
Expand All @@ -103,15 +103,17 @@ def test_is_supported_detect_format():

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

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

0 comments on commit a42321f

Please sign in to comment.