Commit 339aa0c4 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Import path, not the entire os module

- Update tests to use real config file versus mock (temporary)
- Add config file for testing
parent 6622f3ba
......@@ -24,8 +24,8 @@ import sys
import configparser
from collections import defaultdict
import os
dir_path = os.path.dirname(os.path.realpath(__file__))
from os import path
dir_path = path.dirname(path.realpath(__file__))
class SkynetConfig(object):
'Skynet Config object'
......
# Comments in the config file
[client]
configdir = /opt/skynet/config
# Another comment
[server]
dbport = 3306
# And another comment
[gui]
favicon = favicon.ico
......@@ -25,60 +25,61 @@ from collections import defaultdict
from unittest.mock import patch, mock_open
from textwrap import dedent
from os import path
class TestSkynetConfig(object):
CONFIGDATA = dedent("""
# Comments in the config file
[client]
configdir = /opt/skynet/config
defaultconfig = {'global':
{'homepage': 'http://www.godshell.com',
'version': '1.0'}
}
# Another comment
[server]
dbport = 3306
testconfig = {'global':
{'homepage': 'http://www.godshell.com',
'version': '1.0'},
'client':
{'configdir': '/opt/skynet/config'},
'server':
{'dbport': '3306'},
'gui':
{'favicon': 'favicon.ico'},
}
# And another comment
[gui]
favicon = 'favicon.ico'
""").strip()
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 == 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_custom(self):
configobject = SkynetConfig('test.conf')
dir_path = path.dirname(path.realpath(__file__))
configobject = SkynetConfig(dir_path + '/test.conf')
print(dir_path)
print(configobject._cfg)
assert configobject._defaultconfigfile == '../config/default.conf'
assert configobject._configfile == 'test.conf'
assert configobject._cfg == defaultdict(dict)
assert configobject._configfile == dir_path + '/test.conf'
assert configobject._cfg == testconfig
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_loadconfig(self):
configobject = SkynetConfig('test2.conf')
#configobject.section = 'server'
#assert configobject._defaultconfigfile == '../config/default.conf'
#assert configobject._configfile == 'myconfig.conf'
assert configobject._cfg == defaultdict(dict)
#assert configobject._section == None
configobject = SkynetConfig()
assert configobject._configfile == None
assert configobject._cfg == defaultconfig
assert configobject._section == None
dir_path = path.dirname(path.realpath(__file__))
configobject.loadconfig(dir_path + '/test.conf')
assert configobject._configfile == dir_path + '/test.conf'
assert configobject._cfg == testconfig
assert configobject._section == None
def test_section_get(self):
......
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