2016-05-10 16:50:34 -04:00
|
|
|
import logging
|
2015-07-31 15:55:26 -04:00
|
|
|
from os import remove
|
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.__main__ import main
|
|
|
|
from tsstats.log import parse_logs
|
2015-09-04 17:20:35 -04:00
|
|
|
|
2016-05-08 15:32:37 -04:00
|
|
|
clients = parse_logs('tsstats/tests/res/test.log')
|
2015-07-13 15:35:05 -04:00
|
|
|
|
|
|
|
|
2016-05-10 16:50:34 -04:00
|
|
|
logger = logging.getLogger('tsstats')
|
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
@pytest.fixture
|
|
|
|
def output(request):
|
|
|
|
def clean():
|
|
|
|
remove('tsstats/tests/res/output.html')
|
|
|
|
request.addfinalizer(clean)
|
|
|
|
|
|
|
|
|
|
|
|
def test_main(output):
|
2016-05-08 15:32:37 -04:00
|
|
|
main(config_path='tsstats/tests/res/config.ini')
|
2015-07-31 16:24:44 -04:00
|
|
|
|
|
|
|
|
2015-07-31 16:52:25 -04:00
|
|
|
def test_main_config_not_found():
|
2016-05-09 14:09:16 -04:00
|
|
|
with pytest.raises(exceptions.ConfigNotFound):
|
|
|
|
main(config_path='/some/where/no/conf.ini')
|
2015-07-31 16:52:25 -04:00
|
|
|
|
|
|
|
|
2016-05-09 14:09:16 -04:00
|
|
|
def test_main_idmap_load(output):
|
2016-05-08 15:32:37 -04:00
|
|
|
main(config_path='tsstats/tests/res/config.ini',
|
|
|
|
id_map_path='tsstats/tests/res/id_map.json')
|
2015-07-31 16:52:25 -04:00
|
|
|
|
|
|
|
|
2015-07-31 15:55:26 -04:00
|
|
|
def test_debug_log():
|
2016-05-10 16:50:34 -04:00
|
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
parse_logs('tsstats/tests/res/test.log')
|
|
|
|
logger.setLevel(logging.INFO)
|
2015-07-31 15:55:26 -04:00
|
|
|
open('debug.txt')
|
|
|
|
remove('debug.txt')
|
2015-08-28 07:47:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_broken():
|
2016-05-09 14:09:16 -04:00
|
|
|
with pytest.raises(exceptions.InvalidLog):
|
|
|
|
parse_logs('tsstats/tests/res/test.log.broken')
|