add some config tests

This commit is contained in:
Bastian Schroll 2019-10-21 10:28:46 +02:00
parent 0e587e7698
commit 40e0a951da
3 changed files with 37 additions and 31 deletions

View file

@ -56,6 +56,12 @@ def test_loadConfigFileNotFound(getConfig):
assert getConfig.loadConfigFile(paths.TEST_PATH + "test_configNotFound.yaml") is False
def test_getConfigAsString(getFilledConfig):
"""!Get the string representation of the config"""
assert type(str(getFilledConfig)) is str
logging.debug(getFilledConfig)
def test_getTypes(getFilledConfig):
"""!Get and check different data types in config"""
assert type(getFilledConfig.get("types")) is ConfigYAML
@ -65,6 +71,11 @@ def test_getTypes(getFilledConfig):
assert type(getFilledConfig.get("types", "float")) is float
def test_getDefaultValue(getFilledConfig):
"""!Get the default value of an not existent entry"""
assert getFilledConfig.get("notExistent", default="defaultValue") == "defaultValue"
def test_getNestedConfig(getFilledConfig):
"""!Work with nested sub-config elements"""
nestedConfig = getFilledConfig.get("types")
@ -78,4 +89,17 @@ def test_configIterationList(getFilledConfig):
for item in getFilledConfig.get("list"):
assert type(item) is str
counter += 1
assert counter == 3
assert counter is 3
def test_configIterationListWithNestedList(getFilledConfig):
"""!Try to iterate over a list in the config where its elements are lists itself"""
listCnt = 0
strCnt = 0
for item in getFilledConfig.get("list1"):
if type(item) is ConfigYAML:
listCnt += 1
if type(item) is str:
strCnt += 1
assert listCnt == 2
assert strCnt == 1