tests: Move __init__ logic into functions, for clarity

This commit is contained in:
Cole Robinson 2017-02-23 18:47:57 -05:00
parent dffb2aaa2d
commit 0055798d21
1 changed files with 46 additions and 33 deletions

View File

@ -32,39 +32,52 @@ reload(cliconfig)
from tests import utils
# Setup logging
rootLogger = logging.getLogger()
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)-8s %(message)s")
if utils.get_debug():
rootLogger.setLevel(logging.DEBUG)
else:
rootLogger.setLevel(logging.ERROR)
_cleanup_imports = []
def _import(name, path):
_cleanup_imports.append(path + "c")
return imp.load_source(name, path)
def _cleanup_imports_cb():
for f in _cleanup_imports:
if os.path.exists(f):
os.unlink(f)
atexit.register(_cleanup_imports_cb)
virtinstall = _import("virtinstall", "virt-install")
virtclone = _import("virtclone", "virt-clone")
virtconvert = _import("virtconvert", "virt-convert")
virtxml = _import("virtxml", "virt-xml")
# Variable used to store a local iso or dir path to check for a distro
# Specified via 'python setup.py test_urls --path"
URLTEST_LOCAL_MEDIA = []
virtinstall = None
virtclone = None
virtconvert = None
virtxml = None
def _setup_logging():
rootLogger = logging.getLogger()
for handler in rootLogger.handlers:
rootLogger.removeHandler(handler)
logging.basicConfig(level=logging.DEBUG,
format="%(levelname)-8s %(message)s")
if utils.get_debug():
rootLogger.setLevel(logging.DEBUG)
else:
rootLogger.setLevel(logging.ERROR)
def _setup_cli_imports():
_cleanup_imports = []
def _cleanup_imports_cb():
for f in _cleanup_imports:
if os.path.exists(f):
os.unlink(f)
def _import(name, path):
_cleanup_imports.append(path + "c")
return imp.load_source(name, path)
global virtinstall
global virtclone
global virtconvert
global virtxml
atexit.register(_cleanup_imports_cb)
virtinstall = _import("virtinstall", "virt-install")
virtclone = _import("virtclone", "virt-clone")
virtconvert = _import("virtconvert", "virt-convert")
virtxml = _import("virtxml", "virt-xml")
_setup_logging()
_setup_cli_imports()