update configtests to use new exceptions and remove unneccessary debugfile-test

This commit is contained in:
Thor77 2015-07-17 14:40:11 +02:00
parent 627c5afa82
commit e3d1d7677f
1 changed files with 18 additions and 22 deletions

View File

@ -1,47 +1,43 @@
import configparser import configparser
from os import remove from os import remove
from os.path import exists from os.path import exists
import tsstats from tsstats import parse_config, exceptions, gen_abspath
from nose.tools import raises, with_setup from nose.tools import raises, with_setup
configpath = gen_abspath('tests/res/test.cfg')
def create_config(values, key='General'): def create_config(values, key='General'):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config[key] = values config[key] = values
with open('config.ini', 'w') as configfile: with open(configpath, 'w') as configfile:
config.write(configfile) config.write(configfile)
def clean_config(): def clean_config():
if exists('config.ini'): if exists(configpath):
remove('config.ini') remove(configpath)
def clean_result():
if exists('output.html'):
remove('output.html')
@with_setup(clean_config, clean_config) @with_setup(clean_config, clean_config)
@raises(Exception) @raises(exceptions.InvalidConfig)
def test_invalid_config(): def test_invalid_config():
config = configparser.ConfigParser()
create_config({ create_config({
'logfile': 'tests/res/test.log', 'loggfile': 'tests/res/test.log',
'outputfile': '', 'outputfile': ''
'deebug': 'false',
}) })
_, _, _, _ = parse_config(config_path) _, _, _, _ = parse_config(configpath)
@with_setup(clean_config, clean_config) @with_setup(clean_config, clean_config)
@raises(Exception) def test_config():
def test_debug_without_debugfile():
config = configparser.ConfigParser()
create_config({ create_config({
'logfile': 'tests/res/test.log', 'logfile': 'tests/res/test.log',
'debug': 'true', 'outputfile': 'output.html',
'debugfile': 'false', 'debug': 'true'
}) })
_, _, _, _ = parse_config(config_path) log_path, output_path, debug, debug_file = parse_config(configpath)
open('debug.txt', 'r') assert log_path == gen_abspath('tests/res/test.log')
assert output_path == gen_abspath('output.html')
assert debug
assert not debug_file