2015-07-13 15:35:05 -04:00
|
|
|
import configparser
|
|
|
|
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
|
|
|
|
2015-07-13 15:35:05 -04:00
|
|
|
from nose.tools import raises, with_setup
|
|
|
|
|
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'):
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config[key] = values
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
def clean_config():
|
2015-07-17 08:40:11 -04:00
|
|
|
if exists(configpath):
|
|
|
|
remove(configpath)
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
@with_setup(clean_config, clean_config)
|
2015-07-17 08:40:11 -04:00
|
|
|
@raises(exceptions.InvalidConfig)
|
2015-07-13 15:35:05 -04:00
|
|
|
def test_invalid_config():
|
|
|
|
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
|
|
|
})
|
2015-07-17 08:40:11 -04:00
|
|
|
_, _, _, _ = parse_config(configpath)
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
@with_setup(clean_config, clean_config)
|
2015-07-17 08:40:11 -04:00
|
|
|
def test_config():
|
2015-07-13 15:35:05 -04:00
|
|
|
create_config({
|
2016-05-08 15:32:37 -04:00
|
|
|
'logfile': 'tsstats/tests/res/test.log',
|
2015-07-17 08:40:11 -04:00
|
|
|
'outputfile': 'output.html',
|
|
|
|
'debug': 'true'
|
2015-07-13 15:35:05 -04:00
|
|
|
})
|
2015-08-26 13:58:17 -04:00
|
|
|
log_path, output_path = parse_config(configpath)
|
2016-05-08 15:32:37 -04:00
|
|
|
assert log_path == abspath('tsstats/tests/res/test.log')
|
|
|
|
assert output_path == abspath('output.html')
|