TeamspeakStats/tests/test_config.py

44 lines
1.1 KiB
Python
Raw Normal View History

2015-07-13 15:35:05 -04:00
import configparser
from os import remove
from os.path import exists
2015-09-04 17:20:35 -04:00
2015-07-13 15:35:05 -04:00
from nose.tools import raises, with_setup
2015-09-04 17:20:35 -04:00
from tsstats import exceptions, gen_abspath, parse_config
configpath = gen_abspath('tests/res/test.cfg')
2015-07-13 15:35:05 -04:00
def create_config(values, key='General'):
config = configparser.ConfigParser()
config[key] = values
with open(configpath, 'w') as configfile:
2015-07-13 15:35:05 -04:00
config.write(configfile)
def clean_config():
if exists(configpath):
remove(configpath)
2015-07-13 15:35:05 -04:00
@with_setup(clean_config, clean_config)
@raises(exceptions.InvalidConfig)
2015-07-13 15:35:05 -04:00
def test_invalid_config():
create_config({
'loggfile': 'tests/res/test.log',
'outputfile': ''
2015-07-13 15:35:05 -04:00
})
_, _, _, _ = parse_config(configpath)
2015-07-13 15:35:05 -04:00
@with_setup(clean_config, clean_config)
def test_config():
2015-07-13 15:35:05 -04:00
create_config({
'logfile': 'tests/res/test.log',
'outputfile': 'output.html',
'debug': 'true'
2015-07-13 15:35:05 -04:00
})
log_path, output_path = parse_config(configpath)
assert log_path == gen_abspath('tests/res/test.log')
assert output_path == gen_abspath('output.html')