diff options
author | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2010-04-20 14:36:02 +0200 |
---|---|---|
committer | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2010-04-20 14:36:02 +0200 |
commit | daa63ece4d35c3ba698ec493e8029026077d55fd (patch) | |
tree | 529590db5b013173c88dfa8557437eaeae28f773 | |
parent | cea7088dee59f6fc37a361384eb8f388127c0ee9 (diff) | |
download | logilab-common-daa63ece4d35c3ba698ec493e8029026077d55fd.tar.gz |
propertly wraps decorated function (preserve name) for temporary directory
-rw-r--r-- | testlib.py | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -46,6 +46,7 @@ import warnings from compiler.consts import CO_GENERATOR from ConfigParser import ConfigParser from itertools import dropwhile +from functools import wraps try: from test import test_support @@ -81,10 +82,11 @@ __unittest = 1 def with_tempdir(callable): """A decorator ensuring no temporary file left when the function return Work only for temporary file create with the tempfile module""" + @wraps(callable) def proxy(*args, **kargs): old_tmpdir = tempfile.gettempdir() - new_tmpdir = tempfile.mkdtemp("-logilab-common-testlib","temp-dir-") + new_tmpdir = tempfile.mkdtemp(prefix="temp-lgc-") tempfile.tempdir = new_tmpdir try: return callable(*args, **kargs) @@ -98,6 +100,7 @@ def with_tempdir(callable): def in_tempdir(callable): """A decorator moving the enclosed function inside the tempfile.tempfdir """ + @wraps(callable) def proxy(*args, **kargs): old_cwd = os.getcwd() @@ -111,7 +114,9 @@ def in_tempdir(callable): def within_tempdir(callable): """A decorator run the enclosed function inside a tmpdir removed after execution """ - return with_tempdir(in_tempdir(callable)) + proxy = with_tempdir(in_tempdir(callable)) + proxy.__name__ = callable.__name__ + return proxy def run_tests(tests, quiet, verbose, runner=None, capture=0): """Execute a list of tests. |