diff options
author | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2008-09-10 15:59:18 +0200 |
---|---|---|
committer | Pierre-Yves David <pierre-yves.david@logilab.fr> | 2008-09-10 15:59:18 +0200 |
commit | 635379d648697d7818f9889268697e9c7077dc16 (patch) | |
tree | a2c0df9985d6efcca68305fc86acaa23129a38a3 /test | |
parent | 85a794a2f97befe8929d40c84cc9ecc3bc8b2de5 (diff) | |
parent | b931c4a1f234391d9351782d4e88babea4153018 (diff) | |
download | logilab-common-635379d648697d7818f9889268697e9c7077dc16.tar.gz |
merge
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_context.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/unittest_context.py b/test/unittest_context.py new file mode 100644 index 0000000..11fbe98 --- /dev/null +++ b/test/unittest_context.py @@ -0,0 +1,38 @@ +TEST = """ +from __future__ import with_statement +from os.path import isdir, exists +import shutil +from logilab.common.testlib import TestCase, unittest_main +from logilab.common.context import tempdir + +class ContextTC(TestCase): + + def test_withtempdir(self): + with tempdir() as tmpdir: + assert exists(tmpdir) + assert isdir(tmpdir) + assert not exists(tmpdir) + try: + with tempdir() as tmpdir: + assert exists(tmpdir) + shutil.rmtree(tmpdir) + except OSError: + pass + else: + self.assertTrue(False, "we should fail") + assert not exists(tmpdir) + with tempdir(ignore_error=True) as tmpdir: + shutil.rmtree(tmpdir) + def rmtree_handler(func, path, excinfo): + self.assertTrue(issubclass(excinfo[0], OSError)) + with tempdir(onerror=rmtree_handler) as tmpdir: + shutil.rmtree(tmpdir) +try: + unittest_main() +except SystemExit: + pass +""" + +import sys +if sys.version_info[:2] >= (2, 5): + exec(TEST) |