use py.test instead of nose for testing

This commit is contained in:
Thor77 2016-05-09 20:09:16 +02:00
parent 6889946ab6
commit 9891b1d785
6 changed files with 56 additions and 41 deletions

View File

@ -1,4 +1,6 @@
[report]
include = tsstats/*.py
exclude_lines =
if __name__ == .__main__.:
[run]
omit = tsstats/tests/*

View File

@ -16,9 +16,9 @@ matrix:
install:
- pip install -r requirements.txt
- pip install -r testing_requirements.txt
- pip install coverage
- pip install pytest-cov
script: nosetests --with-coverage
script: py.test --cov=tsstats tsstats/
after_success:
- pip install coveralls

View File

@ -1,3 +1,3 @@
nose>=1.3.7
pytest>=2.9.1
pyflakes>=1.2.2
BeautifulSoup4>=4.4.1

View File

@ -6,7 +6,7 @@ except ImportError:
from os import remove
from os.path import abspath, exists
from nose.tools import raises, with_setup
import pytest
from tsstats import exceptions
from tsstats.config import parse_config
@ -23,23 +23,24 @@ def create_config(values, key='General'):
config.write(configfile)
def clean_config():
if exists(configpath):
remove(configpath)
@pytest.fixture
def config(request):
def clean():
if exists(configpath):
remove(configpath)
request.addfinalizer(clean)
@with_setup(clean_config, clean_config)
@raises(exceptions.InvalidConfig)
def test_invalid_config():
def test_invalid_config(config):
create_config({
'loggfile': 'tsstats/tests/res/test.log',
'outputfile': ''
})
_, _, _, _ = parse_config(configpath)
with pytest.raises(exceptions.InvalidConfig):
_, _, _, _ = parse_config(configpath)
@with_setup(clean_config, clean_config)
def test_config():
def test_config(config):
create_config({
'logfile': 'tsstats/tests/res/test.log',
'outputfile': 'output.html',

View File

@ -1,6 +1,6 @@
from os import remove
from nose.tools import raises
import pytest
from tsstats import exceptions
from tsstats.__main__ import main
@ -9,16 +9,23 @@ from tsstats.log import parse_logs
clients = parse_logs('tsstats/tests/res/test.log')
def test_main():
@pytest.fixture
def output(request):
def clean():
remove('tsstats/tests/res/output.html')
request.addfinalizer(clean)
def test_main(output):
main(config_path='tsstats/tests/res/config.ini')
@raises(exceptions.ConfigNotFound)
def test_main_config_not_found():
main(config_path='/some/where/no/conf.ini')
with pytest.raises(exceptions.ConfigNotFound):
main(config_path='/some/where/no/conf.ini')
def test_main_idmap_load():
def test_main_idmap_load(output):
main(config_path='tsstats/tests/res/config.ini',
id_map_path='tsstats/tests/res/id_map.json')
@ -60,14 +67,14 @@ def test_client_repr():
def test_debug_log():
clients = parse_logs('tsstats/tests/res/test.log', file_log=True)
parse_logs('tsstats/tests/res/test.log', file_log=True)
open('debug.txt')
remove('debug.txt')
@raises(exceptions.InvalidLog)
def test_parse_broken():
clients = parse_logs('tsstats/tests/res/test.log.broken')
with pytest.raises(exceptions.InvalidLog):
parse_logs('tsstats/tests/res/test.log.broken')
def test_iter_clients():

View File

@ -1,32 +1,37 @@
from os import remove
import pytest
from bs4 import BeautifulSoup
from tsstats.utils import seconds_to_text
from tsstats.log import parse_logs
from tsstats.template import render_template
from tsstats.utils import seconds_to_text
output_path = 'tsstats/tests/res/output.html'
clients = parse_logs('tsstats/tests/res/test.log')
class TestTemplate:
def teardown_class():
remove(output_path)
@pytest.fixture
def output(request):
def clean():
remove('tsstats/tests/res/output.html')
request.addfinalizer(clean)
def test_debug(self):
render_template(clients, output_path, debug=True)
soup = BeautifulSoup(open(output_path), 'html.parser')
# check red label
assert soup.find_all(class_='alert alert-danger')
# check ident present after nick
li = soup.find('li')
assert li
assert '(' in li.text.split()[1]
def test_data(self):
render_template(clients, output_path)
soup = BeautifulSoup(open(output_path), 'html.parser')
# check onlinetime-data
assert seconds_to_text(clients['1'].onlinetime) == \
soup.find('span', class_='badge').text
def test_debug(output):
render_template(clients, output_path, debug=True)
soup = BeautifulSoup(open(output_path), 'html.parser')
# check red label
assert soup.find_all(class_='alert alert-danger')
# check ident present after nick
li = soup.find('li')
assert li
assert '(' in li.text.split()[1]
def test_data(output):
render_template(clients, output_path)
soup = BeautifulSoup(open(output_path), 'html.parser')
# check onlinetime-data
assert seconds_to_text(clients['1'].onlinetime) == \
soup.find('span', class_='badge').text