diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-24 16:02:26 -0600 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-10-24 16:02:26 -0600 |
commit | 8ca44bcbfa2aec0c7c84205dc08c81f711a22c5d (patch) | |
tree | 35a3dfbdd3c48843318f66cabf1024d2e69c3fe2 /tests/util.py | |
parent | 2a41db33c6d9f6efa826e16d91eba76defe899d2 (diff) | |
download | freeipa-8ca44bcbfa2aec0c7c84205dc08c81f711a22c5d.tar.gz freeipa-8ca44bcbfa2aec0c7c84205dc08c81f711a22c5d.tar.xz freeipa-8ca44bcbfa2aec0c7c84205dc08c81f711a22c5d.zip |
Added tests.util.TempHome class for created a tempdir and setting os.environ['HOME'] to it; updated various unit tests for Env so they are run using a tempdir for home
Diffstat (limited to 'tests/util.py')
-rw-r--r-- | tests/util.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/util.py b/tests/util.py index a813903ae..1cbc4e312 100644 --- a/tests/util.py +++ b/tests/util.py @@ -42,8 +42,9 @@ class TempDir(object): path = property(__get_path) def rmtree(self): - shutil.rmtree(self.path) - self.__path = None + if self.__path is not None: + shutil.rmtree(self.path) + self.__path = None def makedirs(self, *parts): d = self.join(*parts) @@ -67,6 +68,17 @@ class TempDir(object): self.rmtree() +class TempHome(TempDir): + def __init__(self): + super(TempHome, self).__init__() + self.__home = os.environ['HOME'] + os.environ['HOME'] = self.path + + def rmtree(self): + os.environ['HOME'] = self.__home + super(TempHome, self).rmtree() + + class ExceptionNotRaised(Exception): """ Exception raised when an *expected* exception is *not* raised during a |