summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurelien Campeas <aurelien.campeas@logilab.fr>2008-09-02 10:52:38 +0200
committerAurelien Campeas <aurelien.campeas@logilab.fr>2008-09-02 10:52:38 +0200
commit6a095482bf00005424a654d8fd3e35da4f17a08d (patch)
treeafb8a5959f2535d74446544442d04e49086b1d37
parentee7381d202fa4eb3da293c625479b3ae5712e13b (diff)
downloadlogilab-common-6a095482bf00005424a654d8fd3e35da4f17a08d.tar.gz
* update README
* make the test python < 2.5 -proof
-rw-r--r--README3
-rw-r--r--context.py4
-rw-r--r--test/unittest_context.py15
3 files changed, 15 insertions, 7 deletions
diff --git a/README b/README
index 9a896f4..5f56c34 100644
--- a/README
+++ b/README
@@ -60,6 +60,9 @@ Here is a brief description of the available modules :
Two mix-in classes to handle configuration from both command line
(using optik/optparse) and configuration file.
+* context.py :
+ One context manager (python 2.5+) to handle temporary directories.
+
* corbautils.py:
Usefull functions for use with the OmniORB CORBA library.
diff --git a/context.py b/context.py
index 5f21ae3..39c32a4 100644
--- a/context.py
+++ b/context.py
@@ -3,9 +3,9 @@ import tempfile
import shutil
@contextmanager
-def tempdir():
+def tempdir(ignore_error=False, onerror=None):
try:
path = tempfile.mkdtemp()
yield path
finally:
- shutil.rmtree(path)
+ shutil.rmtree(path, ignore_error, onerror)
diff --git a/test/unittest_context.py b/test/unittest_context.py
index 418c5e4..74eee69 100644
--- a/test/unittest_context.py
+++ b/test/unittest_context.py
@@ -1,9 +1,8 @@
+TEST = """
from __future__ import with_statement
-
-import unittest
from os.path import isdir, exists
-from logilab.common.testlib import TestCase
+from logilab.common.testlib import TestCase, unittest_main
from logilab.common.context import tempdir
class ContextTC(TestCase):
@@ -20,6 +19,12 @@ class ContextTC(TestCase):
except:
pass
assert not exists(tmpdir)
-
-if __name__ == '__main__':
+try:
unittest_main()
+except SystemExit:
+ pass
+"""
+
+import sys
+if sys.version_info[:2] >= (2, 5):
+ exec(TEST)