From 8299c73eb9260ada6c0ab04b06db08df24d773f0 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Fri, 28 Apr 2017 23:24:31 +0200 Subject: [PATCH] Move output-fixture to confest.py and yield path * Modify test_log and test_template to use these changes --- tsstats/tests/conftest.py | 13 +++++++++++++ tsstats/tests/test_log.py | 7 ++----- tsstats/tests/test_template.py | 17 ++++------------- 3 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 tsstats/tests/conftest.py diff --git a/tsstats/tests/conftest.py b/tsstats/tests/conftest.py new file mode 100644 index 0000000..40e3124 --- /dev/null +++ b/tsstats/tests/conftest.py @@ -0,0 +1,13 @@ +from os import remove + +import pytest + + +@pytest.fixture +def output(request): + output_path = 'tsstats/tests/res/output.html' + + def clean(): + remove(output_path) + request.addfinalizer(clean) + yield output_path diff --git a/tsstats/tests/test_log.py b/tsstats/tests/test_log.py index 17edf02..1ef16bd 100644 --- a/tsstats/tests/test_log.py +++ b/tsstats/tests/test_log.py @@ -1,5 +1,4 @@ from datetime import datetime, timedelta -from os import remove from time import sleep import pytest @@ -7,7 +6,6 @@ import pytest from tsstats.exceptions import InvalidLog from tsstats.log import TimedLog, _bundle_logs, _parse_details, parse_logs from tsstats.template import render_servers -from tsstats.tests.test_template import output_path testlog_path = 'tsstats/tests/res/test.log' @@ -92,10 +90,9 @@ def test_parse_groups(): assert len(clients) == 0 -def test_parse_utf8(): +def test_parse_utf8(output): servers = parse_logs(testlog_path + '.utf8') - render_servers(servers, output_path) - remove(output_path) + render_servers(servers, output) def test_server_stop(): diff --git a/tsstats/tests/test_template.py b/tsstats/tests/test_template.py index 39ac015..f7422d3 100644 --- a/tsstats/tests/test_template.py +++ b/tsstats/tests/test_template.py @@ -1,6 +1,5 @@ import logging from datetime import timedelta -from os import remove import pytest from bs4 import BeautifulSoup @@ -9,31 +8,23 @@ from tsstats.log import Server, _parse_details from tsstats.template import render_servers from tsstats.utils import filter_threshold, seconds_to_text, sort_clients -output_path = 'tsstats/tests/res/output.html' clients = _parse_details('tsstats/tests/res/test.log', online_dc=False) servers = [Server(1, clients)] logger = logging.getLogger('tsstats') -@pytest.fixture -def output(request): - def clean(): - remove(output_path) - request.addfinalizer(clean) - - @pytest.fixture def soup(output): - render_servers(servers, output_path) - return BeautifulSoup(open(output_path), 'html.parser') + render_servers(servers, output) + return BeautifulSoup(open(output), 'html.parser') def test_debug(output): logger.setLevel(logging.DEBUG) - render_servers(servers, output_path) + render_servers(servers, output) logger.setLevel(logging.INFO) - soup = BeautifulSoup(open(output_path), 'html.parser') + soup = BeautifulSoup(open(output), 'html.parser') # check debug-label presence assert soup.find_all(style='color: red; padding-right: 10px;') for client_item in soup.find('ul', id='1.onlinetime').find_all('li'):