Commit 67b6e3ba authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Default instantiation should load config

- Update tests accordingly
parent 214da5ee
......@@ -39,6 +39,8 @@ class SkynetConfig(object):
if configfile:
self.loadconfig(configfile)
else:
self.loadconfig()
def loadconfig(self, configfile=None):
......
......@@ -44,17 +44,22 @@ class TestSkynetConfig(object):
def test_instantiation(self):
configobject = SkynetConfig()
defaultconfig = {'global':
{'homepage': 'http://www.godshell.com',
'version': '1.0'}
}
assert configobject._defaultconfigfile == '../config/default.conf'
assert configobject._configfile == None
assert configobject._cfg == defaultdict(dict)
assert configobject._cfg == defaultconfig
assert configobject._section == None
# TODO: Figure out how to mock this and test
@pytest.mark.xfail(reason='Unsure how to mock this')
#@patch("builtins.open", mock_open(read_data=CONFIGDATA))
def test_instantiate_and_load(self):
configobject = SkynetConfig()
def test_instantiate_custom(self):
configobject = SkynetConfig('test.conf')
assert configobject._defaultconfigfile == '../config/default.conf'
assert configobject._configfile == None
......@@ -66,9 +71,7 @@ class TestSkynetConfig(object):
@pytest.mark.xfail(reason='Unsure how to mock this')
#@patch("builtins.open", mock_open(read_data=CONFIGDATA))
def test_loadconfig(self):
configobject = SkynetConfig()
configobject.loadconfig()
configobject = SkynetConfig('test2.conf')
#configobject.section = 'server'
......@@ -89,8 +92,6 @@ class TestSkynetConfig(object):
def test_section_set(self):
configobject = SkynetConfig()
configobject.loadconfig()
configobject.section = 'global'
assert configobject.section == 'global'
assert configobject._section == 'global'
......@@ -101,12 +102,16 @@ class TestSkynetConfig(object):
def test_cfg(self):
configobject = SkynetConfig()
assert configobject._cfg == defaultdict(dict)
defaultconfig = {'global':
{'homepage': 'http://www.godshell.com',
'version': '1.0'}
}
assert configobject._cfg == defaultconfig
def test_getkey(self):
configobject = SkynetConfig()
configobject.loadconfig()
assert configobject.getkey('foo') == None
assert configobject.getkey('homepage') == None
......@@ -116,7 +121,6 @@ class TestSkynetConfig(object):
def test_getsection(self):
configobject = SkynetConfig()
configobject.loadconfig()
defaultconfig = {'homepage': 'http://www.godshell.com',
'version': '1.0'}
......@@ -126,7 +130,6 @@ class TestSkynetConfig(object):
def test_getsectionkey(self):
configobject = SkynetConfig()
configobject.loadconfig()
assert configobject.getsectionkey('global', 'version') == '1.0'
assert configobject.getsectionkey('global', 'homepage') == 'http://www.godshell.com'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment