diff options
author | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2010-03-17 12:42:19 +0100 |
---|---|---|
committer | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2010-03-17 12:42:19 +0100 |
commit | 190fb7de198047b745d00b9f43abc414caa05f32 (patch) | |
tree | b5adfff8bbb227594c5d39762c32cabfac9c8bf7 | |
parent | b73d14a2863d191962a5d2dccb87377c99581d06 (diff) | |
download | logilab-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.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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. |