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:
Thor77 2017-02-22 22:00:09 +01:00
parent 5e19e38965
commit 709c573b65
1 changed files with 10 additions and 37 deletions

View File

@ -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 import pytest
from tsstats.config import load 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 @pytest.fixture
def config(request): def config():
def clean(): return load()
if exists(configpath):
remove(configpath)
request.addfinalizer(clean)
def test_config(config): def test_config(config):
create_config({ assert not config.getboolean('General', 'debug')
'idmap': 'tsstats/tests/res/id_map.json', assert config.getboolean('General', 'onlinedc')
'log': 'tsstats/tests/res/test.log', config.set('General', 'idmap', 'tsstats/tests/res/id_map.json')
'output': 'output.html', assert config.get('General', 'idmap') ==\
'debug': 'true',
'onlinedc': 'false'
})
configuration = load(configpath)
assert configuration.get('General', 'idmap') ==\
'tsstats/tests/res/id_map.json' 'tsstats/tests/res/id_map.json'
assert configuration.get('General', 'log') == 'tsstats/tests/res/test.log' config.set('General', 'log', 'tsstats/tests/res/test.log')
assert configuration.get('General', 'output') == 'output.html' assert config.get('General', 'log') == 'tsstats/tests/res/test.log'
assert configuration.getboolean('General', 'debug') is True config.set('General', 'output', 'output.html')
assert configuration.getboolean('General', 'onlinedc') is False assert config.get('General', 'output') == 'output.html'