1
1
import os
2
2
import os .path as op
3
3
from os .path import join as pjoin
4
- import shutil
5
4
import sys
6
- from tempfile import mkdtemp , mktemp
7
5
import warnings
8
6
9
7
import pytest
@@ -82,9 +80,10 @@ def test_offscreen():
82
80
83
81
84
82
@requires_fsaverage ()
85
- def test_image ():
83
+ def test_image (tmpdir ):
86
84
"""Test image saving."""
87
- tmp_name = mktemp () + '.png'
85
+ tmp_name = tmpdir .join ('temp.png' )
86
+ tmp_name = str (tmp_name ) # coerce to str to avoid PIL error
88
87
89
88
_set_backend ()
90
89
subject_id , _ , surf = std_args
@@ -355,7 +354,7 @@ def test_morphometry():
355
354
356
355
@requires_imageio ()
357
356
@requires_fsaverage ()
358
- def test_movie ():
357
+ def test_movie (tmpdir ):
359
358
"""Test saving a movie of an MEG inverse solution."""
360
359
import imageio
361
360
@@ -373,24 +372,17 @@ def test_movie():
373
372
if sys .platform == 'darwin' and os .getenv ('TRAVIS' , '' ) == 'true' :
374
373
raise SkipTest ('movie saving on OSX Travis is not supported' )
375
374
# save movies with different options
376
- tempdir = mkdtemp ()
377
- try :
378
- dst = os .path .join (tempdir , 'test.mov' )
379
- # test the number of frames in the movie
380
- brain .save_movie (dst )
381
- frames = imageio .mimread (dst )
382
- assert len (frames ) == 2
383
- brain .save_movie (dst , time_dilation = 10 )
384
- frames = imageio .mimread (dst )
385
- assert len (frames ) == 7
386
- brain .save_movie (dst , tmin = 0.081 , tmax = 0.102 )
387
- frames = imageio .mimread (dst )
388
- assert len (frames ) == 2
389
- finally :
390
- # clean up
391
- if not (sys .platform == 'win32' and
392
- os .getenv ('APPVEYOR' , 'False' ) == 'True' ): # cleanup problems
393
- shutil .rmtree (tempdir )
375
+ dst = str (tmpdir .join ('test.mov' ))
376
+ # test the number of frames in the movie
377
+ brain .save_movie (dst )
378
+ frames = imageio .mimread (dst )
379
+ assert len (frames ) == 2
380
+ brain .save_movie (dst , time_dilation = 10 )
381
+ frames = imageio .mimread (dst )
382
+ assert len (frames ) == 7
383
+ brain .save_movie (dst , tmin = 0.081 , tmax = 0.102 )
384
+ frames = imageio .mimread (dst )
385
+ assert len (frames ) == 2
394
386
brain .close ()
395
387
396
388
@@ -475,12 +467,12 @@ def test_text():
475
467
476
468
477
469
@requires_fsaverage ()
478
- def test_animate ():
470
+ def test_animate (tmpdir ):
479
471
"""Test animation."""
480
472
_set_backend ('auto' )
481
473
brain = Brain (* std_args , size = 100 )
482
474
brain .add_morphometry ('curv' )
483
- tmp_name = mktemp () + ' .avi'
475
+ tmp_name = str ( tmpdir . join ( 'test .avi'))
484
476
brain .animate (["m" ] * 3 , n_steps = 2 )
485
477
brain .animate (['l' , 'l' ], n_steps = 2 , fname = tmp_name )
486
478
# can't rotate in axial plane
0 commit comments