TeamspeakStats/tsstats/tests/test_config.py

47 lines
1.2 KiB
Python
Raw Normal View History

2016-05-08 15:42:28 -04:00
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
2015-07-13 15:35:05 -04:00
from os import remove
from os.path import abspath, exists
2015-09-04 17:20:35 -04:00
import pytest
2015-07-13 15:35:05 -04:00
from tsstats.config import parse_config
2015-09-04 17:20:35 -04:00
configpath = abspath('tsstats/tests/res/test.cfg')
2015-07-13 15:35:05 -04:00
def create_config(values, key='General'):
2016-05-08 15:42:28 -04:00
config = ConfigParser()
config.add_section('General')
for option, value in values.items():
config.set('General', option, value)
with open(configpath, 'w') as configfile:
2015-07-13 15:35:05 -04:00
config.write(configfile)
@pytest.fixture
def config(request):
def clean():
if exists(configpath):
remove(configpath)
request.addfinalizer(clean)
2015-07-13 15:35:05 -04:00
def test_config(config):
2015-07-13 15:35:05 -04:00
create_config({
'idmap': 'tsstats/tests/res/id_map.json',
'log': 'tsstats/tests/res/test.log',
'output': 'output.html',
'debug': 'true',
'onlinedc': 'false'
2015-07-13 15:35:05 -04:00
})
idmap, log, output, debug, onlinedc = parse_config(configpath)
assert idmap == 'tsstats/tests/res/id_map.json'
assert log == 'tsstats/tests/res/test.log'
assert output == 'output.html'
assert debug is True
assert onlinedc is False