Refactor config-tests
by just testing the return-value of tsstats.config.load instead of writing and reading a config-file from disk as there's absolutely no need to test that as it's just basic ConfigParser-functionality
This commit is contained in:
parent
5e19e38965
commit
709c573b65
|
@ -1,47 +1,20 @@
|
|||
try:
|
||||
from configparser import ConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from os import remove
|
||||
from os.path import abspath, exists
|
||||
|
||||
import pytest
|
||||
|
||||
from tsstats.config import load
|
||||
|
||||
configpath = abspath('tsstats/tests/res/test.cfg')
|
||||
|
||||
|
||||
def create_config(values, key='General'):
|
||||
config = ConfigParser()
|
||||
config.add_section('General')
|
||||
for option, value in values.items():
|
||||
config.set('General', option, value)
|
||||
with open(configpath, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config(request):
|
||||
def clean():
|
||||
if exists(configpath):
|
||||
remove(configpath)
|
||||
request.addfinalizer(clean)
|
||||
def config():
|
||||
return load()
|
||||
|
||||
|
||||
def test_config(config):
|
||||
create_config({
|
||||
'idmap': 'tsstats/tests/res/id_map.json',
|
||||
'log': 'tsstats/tests/res/test.log',
|
||||
'output': 'output.html',
|
||||
'debug': 'true',
|
||||
'onlinedc': 'false'
|
||||
})
|
||||
configuration = load(configpath)
|
||||
assert configuration.get('General', 'idmap') ==\
|
||||
assert not config.getboolean('General', 'debug')
|
||||
assert config.getboolean('General', 'onlinedc')
|
||||
config.set('General', 'idmap', 'tsstats/tests/res/id_map.json')
|
||||
assert config.get('General', 'idmap') ==\
|
||||
'tsstats/tests/res/id_map.json'
|
||||
assert configuration.get('General', 'log') == 'tsstats/tests/res/test.log'
|
||||
assert configuration.get('General', 'output') == 'output.html'
|
||||
assert configuration.getboolean('General', 'debug') is True
|
||||
assert configuration.getboolean('General', 'onlinedc') is False
|
||||
config.set('General', 'log', 'tsstats/tests/res/test.log')
|
||||
assert config.get('General', 'log') == 'tsstats/tests/res/test.log'
|
||||
config.set('General', 'output', 'output.html')
|
||||
assert config.get('General', 'output') == 'output.html'
|
||||
|
|
Loading…
Reference in New Issue