11import os
22import os .path as op
33from os .path import join as pjoin
4- import shutil
54import sys
6- from tempfile import mkdtemp , mktemp
75import warnings
86
97import pytest
@@ -82,9 +80,10 @@ def test_offscreen():
8280
8381
8482@requires_fsaverage ()
85- def test_image ():
83+ def test_image (tmpdir ):
8684 """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
8887
8988 _set_backend ()
9089 subject_id , _ , surf = std_args
@@ -355,7 +354,7 @@ def test_morphometry():
355354
356355@requires_imageio ()
357356@requires_fsaverage ()
358- def test_movie ():
357+ def test_movie (tmpdir ):
359358 """Test saving a movie of an MEG inverse solution."""
360359 import imageio
361360
@@ -373,24 +372,17 @@ def test_movie():
373372 if sys .platform == 'darwin' and os .getenv ('TRAVIS' , '' ) == 'true' :
374373 raise SkipTest ('movie saving on OSX Travis is not supported' )
375374 # 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
394386 brain .close ()
395387
396388
@@ -475,12 +467,12 @@ def test_text():
475467
476468
477469@requires_fsaverage ()
478- def test_animate ():
470+ def test_animate (tmpdir ):
479471 """Test animation."""
480472 _set_backend ('auto' )
481473 brain = Brain (* std_args , size = 100 )
482474 brain .add_morphometry ('curv' )
483- tmp_name = mktemp () + ' .avi'
475+ tmp_name = str ( tmpdir . join ( 'test .avi'))
484476 brain .animate (["m" ] * 3 , n_steps = 2 )
485477 brain .animate (['l' , 'l' ], n_steps = 2 , fname = tmp_name )
486478 # can't rotate in axial plane
0 commit comments