split client and parse-tests into test_client.py and test_log.py

This commit is contained in:
Thor77 2016-05-18 22:08:09 +02:00
parent bab20d0848
commit a7cfa6967f
3 changed files with 65 additions and 42 deletions

View File

@ -0,0 +1,32 @@
from tsstats.client import Clients
clients = Clients()
clients += 1
clients += 2
clients += 'UID1'
clients += 'UID2'
def test_client_get():
'''
Currently not testable because of tsstats.client.Clients add-behaviour
'''
pass
def test_client_seperation():
assert len(clients.clients_by_id) == 2
assert len(clients.clients_by_uid) == 2
def test_client_repr():
assert str(clients['1']) == '<1,None>'
assert str(clients['2']) == '<2,None>'
assert str(clients['UID1']) == '<UID1,None>'
assert str(clients['UID2']) == '<UID2,None>'
def test_clients_iter():
clients_length = len(clients.clients_by_id) + len(clients.clients_by_uid)
clients_iter = [client for client in clients]
assert len(clients_iter) == clients_length

View File

@ -34,42 +34,6 @@ def test_main_idmap_load(output):
id_map_path='tsstats/tests/res/id_map.json')
def test_length():
assert len(clients.clients_by_id) == 2
assert len(clients.clients_by_uid) == 1
def test_getter():
# check getter not raise
assert clients['UIDClient2'].onlinetime == 0
def test_parse_onlinetime():
# check different dicts
assert clients['1'].onlinetime == 402
assert clients['2'].onlinetime == 20
def test_parse_kicks():
assert clients['UIDClient1'].kicks == 1
def test_parse_pkicks():
assert clients['2'].pkicks == 1
def test_parse_bans():
assert clients['UIDClient1'].bans == 1
def test_parse_pbans():
assert clients['2'].pbans == 1
def test_client_repr():
assert str(clients['1']) == '<1,Client1>'
def test_debug_log():
logger.setLevel(logging.DEBUG)
parse_logs('tsstats/tests/res/test.log')
@ -81,9 +45,3 @@ def test_debug_log():
def test_parse_broken():
with pytest.raises(exceptions.InvalidLog):
parse_logs('tsstats/tests/res/test.log.broken')
def test_iter_clients():
clients_length = len(clients.clients_by_id) + len(clients.clients_by_uid)
clients_iter = [client for client in clients]
assert len(clients_iter) == clients_length

33
tsstats/tests/test_log.py Normal file
View File

@ -0,0 +1,33 @@
import pytest
from tsstats.log import parse_logs
@pytest.fixture
def clients():
return parse_logs('tsstats/tests/res/test.log')
def test_log_client_count(clients):
assert len(clients.clients_by_id) == 2
assert len(clients.clients_by_uid) == 1
def test_log_onlinetime(clients):
assert clients['1'].onlinetime == 402
assert clients['2'].onlinetime == 20
def test_log_kicks(clients):
assert clients['UIDClient1'].kicks == 1
def test_log_pkicks(clients):
assert clients['2'].pkicks == 1
def test_log_bans(clients):
assert clients['UIDClient1'].bans == 1
def test_log_pbans(clients):
assert clients['2'].pbans == 1