From a7cfa6967f7395aba4e45d677103b8831d247433 Mon Sep 17 00:00:00 2001 From: Thor77 Date: Wed, 18 May 2016 22:08:09 +0200 Subject: [PATCH] split client and parse-tests into test_client.py and test_log.py --- tsstats/tests/test_client.py | 32 ++++++++++++++++++++++++++ tsstats/tests/test_general.py | 42 ----------------------------------- tsstats/tests/test_log.py | 33 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 42 deletions(-) create mode 100644 tsstats/tests/test_client.py create mode 100644 tsstats/tests/test_log.py diff --git a/tsstats/tests/test_client.py b/tsstats/tests/test_client.py new file mode 100644 index 0000000..810f135 --- /dev/null +++ b/tsstats/tests/test_client.py @@ -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']) == '' + assert str(clients['UID2']) == '' + + +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 diff --git a/tsstats/tests/test_general.py b/tsstats/tests/test_general.py index 4b04a83..89c6efb 100644 --- a/tsstats/tests/test_general.py +++ b/tsstats/tests/test_general.py @@ -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 diff --git a/tsstats/tests/test_log.py b/tsstats/tests/test_log.py new file mode 100644 index 0000000..8c68e83 --- /dev/null +++ b/tsstats/tests/test_log.py @@ -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