TeamspeakStats/tsstats/tests/test_config.py

51 lines
1.2 KiB
Python
Raw Normal View History

2016-05-08 21:42:28 +02:00
try:
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
2015-07-13 21:35:05 +02:00
from os import remove
from os.path import abspath, exists
2015-09-04 23:20:35 +02:00
import pytest
2015-07-13 21:35:05 +02:00
from tsstats import exceptions
from tsstats.config import parse_config
2015-09-04 23:20:35 +02:00
configpath = abspath('tsstats/tests/res/test.cfg')
2015-07-13 21:35:05 +02:00
def create_config(values, key='General'):
2016-05-08 21:42:28 +02: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 21:35:05 +02:00
config.write(configfile)
@pytest.fixture
def config(request):
def clean():
if exists(configpath):
remove(configpath)
request.addfinalizer(clean)
2015-07-13 21:35:05 +02:00
def test_invalid_config(config):
2015-07-13 21:35:05 +02:00
create_config({
'loggfile': 'tsstats/tests/res/test.log',
'outputfile': ''
2015-07-13 21:35:05 +02:00
})
with pytest.raises(exceptions.InvalidConfig):
_, _, _, _ = parse_config(configpath)
2015-07-13 21:35:05 +02:00
def test_config(config):
2015-07-13 21:35:05 +02:00
create_config({
'log': 'tsstats/tests/res/test.log',
'output': 'output.html',
2015-07-13 21:35:05 +02:00
})
log, output = parse_config(configpath)
assert log == abspath('tsstats/tests/res/test.log')
assert output == abspath('output.html')