From 290f192465dc68b9e037ec4c1c2dc6fb522f2fdc Mon Sep 17 00:00:00 2001 From: Olivier Grisel Date: Mon, 30 Jun 2014 11:09:26 +0200 Subject: Move tempdir context manager to numpy.testing.utils --- numpy/testing/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'numpy/testing/utils.py') 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) -- cgit v1.2.1