diff --git a/tests/test_tempdir.py b/tests/test_tempdir.py new file mode 100644 index 0000000000000000000000000000000000000000..742f3fc169d547fe94b027aea63815cfe7b634fb --- /dev/null +++ b/tests/test_tempdir.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# +# test_tempdir.py - +# +# Author: Paul McCarthy <pauldmccarthy@gmail.com> +# + + +import os +import os.path as op + +import fsl.utils.tempdir as tempdir + + +def test_tempdir(): + + # use ctx manager with or without arg + with tempdir.tempdir(): + d = os.getcwd() + + # dir is removed after ctx manager exit + assert not op.exists(d) + + with tempdir.tempdir() as td: + + d = td + + assert op.exists(d) + + # pwd is dir when in ctx manager + assert op.realpath(os.getcwd()) == op.realpath(td) + + assert not op.exists(d)