summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves David <pierre-yves.david@logilab.fr>2010-03-17 12:42:19 +0100
committerPierre-Yves David <pierre-yves.david@logilab.fr>2010-03-17 12:42:19 +0100
commit190fb7de198047b745d00b9f43abc414caa05f32 (patch)
treeb5adfff8bbb227594c5d39762c32cabfac9c8bf7
parentb73d14a2863d191962a5d2dccb87377c99581d06 (diff)
downloadlogilab-common-190fb7de198047b745d00b9f43abc414caa05f32.tar.gz
[testlib] add in_tempdir, within_tempdir decorator
in_tempdir change the directory for tempfile.tempdir during the function call. within_tempdir combine with_tmpdir and in_tmpdir (create a temp dir and change current directory to a created tempdir during the function call and clear it afterward)
-rw-r--r--testlib.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/testlib.py b/testlib.py
index 2cd14ce..83edc37 100644
--- a/testlib.py
+++ b/testlib.py
@@ -95,6 +95,23 @@ def with_tempdir(callable):
tempfile.tempdir = old_tmpdir
return proxy
+def in_tempdir(callable):
+ """A decorator moving the enclosed function inside the tempfile.tempfdir
+ """
+ def proxy(*args, **kargs):
+
+ old_cwd = os.getcwd()
+ os.chdir(tempfile.tempdir)
+ try:
+ return callable(*args, **kargs)
+ finally:
+ os.chdir(old_cwd)
+ return proxy
+
+def within_tempdir(callable):
+ """A decorator run the enclosed function inside a tmpdir removed after execution
+ """
+ return with_tempdir(in_tempdir(callable))
def run_tests(tests, quiet, verbose, runner=None, capture=0):
"""Execute a list of tests.