summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorOlivier Grisel <olivier.grisel@ensta.org>2014-06-30 11:09:26 +0200
committerOlivier Grisel <olivier.grisel@ensta.org>2014-06-30 11:12:32 +0200
commit290f192465dc68b9e037ec4c1c2dc6fb522f2fdc (patch)
tree764516564e4bc12e12af4c9294b2004496504933 /numpy/testing/utils.py
parent7f0f6c85f44e4a25eae823c29537ebec294a104e (diff)
downloadnumpy-290f192465dc68b9e037ec4c1c2dc6fb522f2fdc.tar.gz
Move tempdir context manager to numpy.testing.utils
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index ddf21e2bc..13c3e4610 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -10,6 +10,9 @@ import re
import operator
import warnings
from functools import partial
+import shutil
+import contextlib
+from tempfile import mkdtemp
from .nosetester import import_nose
from numpy.core import float32, empty, arange, array_repr, ndarray
@@ -1692,3 +1695,16 @@ def _gen_alignment_data(dtype=float32, type='binary', max_size=24):
class IgnoreException(Exception):
"Ignoring this exception due to disabled feature"
+
+
+@contextlib.contextmanager
+def tempdir(*args, **kwargs):
+ """Context manager to provide a temporary test folder.
+
+ All arguments are passed as this to the underlying tempfile.mkdtemp
+ function.
+
+ """
+ tmpdir = mkdtemp(*args, **kwargs)
+ yield tmpdir
+ shutil.rmtree(tmpdir)