Add a basic test for teuthology.config

This commit is contained in:
Zack Cerza 2013-09-20 15:11:13 -05:00
parent 1600785d2d
commit 9de95d174f
2 changed files with 27 additions and 7 deletions

View File

@ -2,22 +2,25 @@ import os
import yaml
import logging
CONF_FILE = os.path.join(os.environ['HOME'], '.teuthology.yaml')
log = logging.getLogger(__name__)
class _Config(object):
class Config(object):
"""
This class is intended to unify teuthology's many configuration files and
objects. Currently it serves as a convenient interface to
~/.teuthology.yaml and nothing else.
"""
teuthology_yaml = os.path.join(os.environ['HOME'], '.teuthology.yaml')
def __init__(self):
if os.path.exists(CONF_FILE):
self.__conf = yaml.safe_load(file(CONF_FILE))
self.load_files()
def load_files(self):
if os.path.exists(self.teuthology_yaml):
self.__conf = yaml.safe_load(file(self.teuthology_yaml))
else:
log.debug("%s not found", CONF_FILE)
log.debug("%s not found", self.teuthology_yaml)
self.__conf = {}
# This property declaration exists mainly as an example; it is not
@ -48,4 +51,4 @@ class _Config(object):
def __getattr__(self, name):
return self.__conf.get(name)
config = _Config()
config = Config()

View File

@ -0,0 +1,17 @@
from .. import config
class TestConfig(object):
def setup(self):
pass
def teardown(self):
pass
def test_get_and_set(self):
conf_obj = config.Config()
conf_obj.teuthology_yaml = ''
conf_obj.load_files()
assert conf_obj.ceph_git_base_url == "https://github.com/ceph/"
conf_obj._Config__conf['ceph_git_base_url'] = "git://ceph.com/"
assert conf_obj.ceph_git_base_url == "git://ceph.com/"