1
0
Fork 0
mirror of https://github.com/Thor77/TeamspeakStats.git synced 2025-07-13 10:38:43 -04:00
TeamspeakStats/tsstats/tests/test_config.py
Thor77 c094edb6e9 refactor config.parse_config
* add debug-output
* return config-values as expected by __main__.main
* remove test_config_invalid
* fix tests
2016-05-21 23:14:52 +02:00

44 lines
1.1 KiB
Python

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 parse_config
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 test_config(config):
create_config({
'idmap': 'tsstats/tests/res/id_map.json',
'log': 'tsstats/tests/res/test.log',
'output': 'output.html',
'debug': 'true'
})
idmap, log, output, debug = 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