edit config_tests

This commit is contained in:
Bastian Schroll 2019-02-27 13:06:41 +01:00
parent a879f27407
commit a8a4116464
3 changed files with 69 additions and 80 deletions

View file

@ -1,12 +0,0 @@
[test]
one = 1
two = two
[testcase]
test = ok
[boolTest]
one = 1
two = True
three = 0
four = False

5
test/test.yaml Normal file
View file

@ -0,0 +1,5 @@
types:
string: Hello World
boolean: true
integer: 11
float: 3.14

View file

@ -17,7 +17,9 @@
import logging import logging
from boswatch.utils import paths from boswatch.utils import paths
from boswatch.config import Config from boswatch import configYaml
# FIXME complete tests
class Test_Config: class Test_Config:
@ -28,80 +30,74 @@ class Test_Config:
def test_loadLocalConfig(self): def test_loadLocalConfig(self):
"""!load a local config file""" """!load a local config file"""
bwConfig = Config() bwConfig = configYaml.loadConfigFile(paths.TEST_PATH + "test.yaml")
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini") assert bwConfig is not None
assert bwConfig._config is not None
def test_getLocalConfig(self): def test_getLocalConfig(self):
"""!get values from local config file""" """!get values from local config file"""
bwConfig = Config() bwConfig = configYaml.loadConfigFile(paths.TEST_PATH + "test.yaml")
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini") assert bwConfig["types"]["integer"] == 11
assert bwConfig.getInt("test", "one") == 1 assert bwConfig["types"]["boolean"] is True
assert bwConfig.getBool("test", "one") is True
assert bwConfig.getStr("test", "two") == "two"
assert bwConfig.getStr("testcase", "test") == "ok"
def test_getLocalConfigFailed(self): def test_getLocalConfigFailed(self):
"""!fail while get values from local config file""" """!fail while get values from local config file"""
bwConfig = Config() bwConfig = configYaml.loadConfigFile(paths.TEST_PATH + "test.yaml")
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini") assert bwConfig["test"]["abc"] is None
assert bwConfig.getStr("test", "abc") is None assert bwConfig["abc"]["test"] is None
assert bwConfig.getStr("abc", "test") is None
def test_shareConfig(self): def test_shareConfig(self):
"""!load local config file and share it""" """!load local config file and share it"""
bwConfig = Config() configYaml.loadConfigFile(paths.TEST_PATH + "test.yaml", "test_shareConfig")
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfig") assert configYaml.loadConfigSharepoint("test_shareConfig") is not None
assert bwConfig._sharePoints["test_shareConfig"] is not None
def test_shareConfigUsed(self): # def test_shareConfigUsed(self):
"""!load local config file and tr to share it twice with same name""" # """!load local config file and tr to share it twice with same name"""
bwConfig1 = Config() # bwConfig1 = Config()
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfigUsed") # bwConfig1.loadConfigFile(paths.TEST_PATH + "test.yaml", "test_shareConfigUsed")
assert bwConfig1._sharePoints["test_shareConfigUsed"] is not None # assert bwConfig1._sharePoints["test_shareConfigUsed"] is not None
bwConfig2 = Config() # bwConfig2 = Config()
bwConfig2.loadConfigFile(paths.TEST_PATH + "test.ini") # bwConfig2.loadConfigFile(paths.TEST_PATH + "test.yaml")
assert not bwConfig2._shareConfig("test_shareConfigUsed") # assert not bwConfig2._shareConfig("test_shareConfigUsed")
#
def test_getNotSetSharedConfig(self): # def test_getNotSetSharedConfig(self):
"""!try to get values from shared config where not exists""" # """!try to get values from shared config where not exists"""
bwConfig = Config() # bwConfig = Config()
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini") # bwConfig.loadConfigFile(paths.TEST_PATH + "test.yaml")
assert bwConfig.getInt("test", "one") == 1 # assert bwConfig.getInt("test", "one") == 1
assert bwConfig.getInt("test", "one", "NotSetSharedConfig") is None # assert bwConfig.getInt("test", "one", "NotSetSharedConfig") is None
#
def test_getSharedConfig(self): # def test_getSharedConfig(self):
"""!get values from shared config file""" # """!get values from shared config file"""
bwConfig1 = Config() # bwConfig1 = Config()
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_getSharedConfig") # bwConfig1.loadConfigFile(paths.TEST_PATH + "test.yaml", "test_getSharedConfig")
assert bwConfig1._sharePoints["test_getSharedConfig"] is not None # assert bwConfig1._sharePoints["test_getSharedConfig"] is not None
#
bwConfig2 = Config() # bwConfig2 = Config()
assert bwConfig2.getStr("test", "one") is None # assert bwConfig2.getStr("test", "one") is None
assert bwConfig2.getInt("test", "one", "test_getSharedConfig") == 1 # assert bwConfig2.getInt("test", "one", "test_getSharedConfig") == 1
#
def test_getSharedConfigFailed(self): # def test_getSharedConfigFailed(self):
"""!fail while get values from shared config file""" # """!fail while get values from shared config file"""
bwConfig1 = Config() # bwConfig1 = Config()
bwConfig1.loadConfigFile(paths.TEST_PATH + "test.ini", "test_getSharedConfigFailed") # bwConfig1.loadConfigFile(paths.TEST_PATH + "test.yaml", "test_getSharedConfigFailed")
assert bwConfig1._sharePoints["test_getSharedConfigFailed"] is not None # assert bwConfig1._sharePoints["test_getSharedConfigFailed"] is not None
#
bwConfig2 = Config() # bwConfig2 = Config()
assert bwConfig2.getStr("test", "abc", "test_getSharedConfigFailed") is None # assert bwConfig2.getStr("test", "abc", "test_getSharedConfigFailed") is None
assert bwConfig2.getStr("abc", "test", "test_getSharedConfigFailed") is None # assert bwConfig2.getStr("abc", "test", "test_getSharedConfigFailed") is None
#
def test_getDataTypes(self): # def test_getDataTypes(self):
bwConfig = Config() # bwConfig = Config()
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini") # bwConfig.loadConfigFile(paths.TEST_PATH + "test.yaml")
assert bwConfig.getStr("testcase", "test") == "ok" # assert bwConfig.getStr("testcase", "test") == "ok"
assert bwConfig.getInt("test", "one") == 1 # assert bwConfig.getInt("test", "one") == 1
assert bwConfig.getInt("boolTest", "three") == 0 # assert bwConfig.getInt("boolTest", "three") == 0
assert bwConfig.getBool("boolTest", "one") # assert bwConfig.getBool("boolTest", "one")
assert bwConfig.getBool("boolTest", "two") # assert bwConfig.getBool("boolTest", "two")
assert not bwConfig.getBool("boolTest", "three") # assert not bwConfig.getBool("boolTest", "three")
assert not bwConfig.getBool("boolTest", "four") # assert not bwConfig.getBool("boolTest", "four")
#
def test_getAllSharepoints(self): # def test_getAllSharepoints(self):
bwConfig = Config() # bwConfig = Config()
bwConfig.loadConfigFile(paths.TEST_PATH + "test.ini", "test_shareConfig") # bwConfig.loadConfigFile(paths.TEST_PATH + "test.yaml", "test_shareConfig")
assert bwConfig.getAllSharepoints() is not None # assert bwConfig.getAllSharepoints() is not None