diff options
Diffstat (limited to 'lang/python/tests/support.py')
-rw-r--r-- | lang/python/tests/support.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lang/python/tests/support.py b/lang/python/tests/support.py index 0b04bb6f..ed5bf615 100644 --- a/lang/python/tests/support.py +++ b/lang/python/tests/support.py @@ -20,6 +20,7 @@ del absolute_import, print_function, unicode_literals import sys import os +import tempfile import gpg # known keys @@ -72,3 +73,17 @@ def mark_key_trusted(ctx, key): return result with gpg.Data() as sink: ctx.op_edit(key, Editor().edit, sink, sink) + + +# Python2/3 compatibility +if hasattr(tempfile, "TemporaryDirectory"): + # Python3.2 and up + TemporaryDirectory = tempfile.TemporaryDirectory +else: + class TemporaryDirectory(object): + def __enter__(self): + self.path = tempfile.mkdtemp() + return self.path + def __exit__(self, *args): + import shutil + shutil.rmtree(self.path) |