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
|
2016-05-08 15:32:37 -04:00
|
|
|
from os.path import abspath, exists
|
2015-09-04 17:20:35 -04:00
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
import pytest
|
2015-07-13 15:35:05 -04:00
|
|
|
|
2016-05-08 15:32:37 -04:00
|
|
|
from tsstats import exceptions
|
|
|
|
from tsstats.config import parse_config
|
2015-09-04 17:20:35 -04:00
|
|
|
|
2016-05-08 15:32:37 -04:00
|
|
|
configpath = abspath('tsstats/tests/res/test.cfg')
|
2015-07-17 08:40:11 -04:00
|
|
|
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
def create_config(values, key='General'):
|
2016-05-08 15:42:28 -04:00
|
|
|
config = ConfigParser()
|
2016-05-09 13:34:13 -04:00
|
|
|
config.add_section('General')
|
|
|
|
for option, value in values.items():
|
|
|
|
config.set('General', option, value)
|
2015-07-17 08:40:11 -04:00
|
|
|
with open(configpath, 'w') as configfile:
|
2015-07-13 15:35:05 -04:00
|
|
|
config.write(configfile)
|
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
@pytest.fixture
|
|
|
|
def config(request):
|
|
|
|
def clean():
|
|
|
|
if exists(configpath):
|
|
|
|
remove(configpath)
|
|
|
|
request.addfinalizer(clean)
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
def test_invalid_config(config):
|
2015-07-13 15:35:05 -04:00
|
|
|
create_config({
|
2016-05-08 15:32:37 -04:00
|
|
|
'loggfile': 'tsstats/tests/res/test.log',
|
2015-07-17 08:40:11 -04:00
|
|
|
'outputfile': ''
|
2015-07-13 15:35:05 -04:00
|
|
|
})
|
2016-05-09 14:09:16 -04:00
|
|
|
with pytest.raises(exceptions.InvalidConfig):
|
|
|
|
_, _, _, _ = parse_config(configpath)
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
def test_config(config):
|
2015-07-13 15:35:05 -04:00
|
|
|
create_config({
|
2016-05-10 16:56:48 -04:00
|
|
|
'log': 'tsstats/tests/res/test.log',
|
|
|
|
'output': 'output.html',
|
2015-07-13 15:35:05 -04:00
|
|
|
})
|
2016-05-10 16:56:48 -04:00
|
|
|
log, output = parse_config(configpath)
|
|
|
|
assert log == abspath('tsstats/tests/res/test.log')
|
|
|
|
assert output == abspath('output.html')
|