summaryrefslogtreecommitdiffstats
path: root/tests/util.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-10-24 15:07:07 -0600
committerJason Gerard DeRose <jderose@redhat.com>2008-10-24 15:07:07 -0600
commitf80beb948bb8914df922e85ef20d9152ca47b527 (patch)
tree9dc1b37219987641754100f6e74e659386a08c32 /tests/util.py
parent2ec0312eb6d4131fe22fab6f4409b71cac83f98f (diff)
downloadfreeipa-f80beb948bb8914df922e85ef20d9152ca47b527.tar.gz
freeipa-f80beb948bb8914df922e85ef20d9152ca47b527.tar.xz
freeipa-f80beb948bb8914df922e85ef20d9152ca47b527.zip
Added ipalib/constants.py; added Env._load_config() method along with comprehensive unit tests for same
Diffstat (limited to 'tests/util.py')
-rw-r--r--tests/util.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/util.py b/tests/util.py
index 5656515ca..a813903ae 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -22,8 +22,51 @@ Common utility functions and classes for unit tests.
"""
import inspect
+import os
+from os import path
+import tempfile
+import shutil
from ipalib import errors
+
+class TempDir(object):
+ def __init__(self):
+ self.__path = tempfile.mkdtemp(prefix='ipa.tests.')
+ assert self.path == self.__path
+
+ def __get_path(self):
+ assert path.abspath(self.__path) == self.__path
+ assert self.__path.startswith('/tmp/ipa.tests.')
+ assert path.isdir(self.__path) and not path.islink(self.__path)
+ return self.__path
+ path = property(__get_path)
+
+ def rmtree(self):
+ shutil.rmtree(self.path)
+ self.__path = None
+
+ def makedirs(self, *parts):
+ d = self.join(*parts)
+ if not path.exists(d):
+ os.makedirs(d)
+ assert path.isdir(d) and not path.islink(d)
+ return d
+
+ def touch(self, *parts):
+ d = self.makedirs(*parts[:-1])
+ f = path.join(d, parts[-1])
+ assert not path.exists(f)
+ open(f, 'w').close()
+ assert path.isfile(f) and not path.islink(f)
+ return f
+
+ def join(self, *parts):
+ return path.join(self.path, *parts)
+
+ def __del__(self):
+ self.rmtree()
+
+
class ExceptionNotRaised(Exception):
"""
Exception raised when an *expected* exception is *not* raised during a