mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-09-03 20:52:56 -05:00
Added ipalib/constants.py; added Env._load_config() method along with comprehensive unit tests for same
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user