From 9891b1d785bbe36f4a2a837cfb9304855a0acb6d Mon Sep 17 00:00:00 2001
From: Thor77 <xXThor77Xx@gmail.com>
Date: Mon, 9 May 2016 20:09:16 +0200
Subject: [PATCH] use py.test instead of nose for testing

---
 .coveragerc                    |  4 +++-
 .travis.yml                    |  4 ++--
 testing_requirements.txt       |  2 +-
 tsstats/tests/test_config.py   | 21 +++++++++--------
 tsstats/tests/test_general.py  | 23 +++++++++++-------
 tsstats/tests/test_template.py | 43 +++++++++++++++++++---------------
 6 files changed, 56 insertions(+), 41 deletions(-)

diff --git a/.coveragerc b/.coveragerc
index 3f1cd06..27ed50e 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,4 +1,6 @@
 [report]
-include = tsstats/*.py
 exclude_lines =
     if __name__ == .__main__.:
+
+[run]
+omit = tsstats/tests/*
diff --git a/.travis.yml b/.travis.yml
index eba509e..10f85e6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/testing_requirements.txt b/testing_requirements.txt
index c725286..b17a11a 100644
--- a/testing_requirements.txt
+++ b/testing_requirements.txt
@@ -1,3 +1,3 @@
-nose>=1.3.7
+pytest>=2.9.1
 pyflakes>=1.2.2
 BeautifulSoup4>=4.4.1
diff --git a/tsstats/tests/test_config.py b/tsstats/tests/test_config.py
index 5a561ab..0351fb0 100644
--- a/tsstats/tests/test_config.py
+++ b/tsstats/tests/test_config.py
@@ -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',
diff --git a/tsstats/tests/test_general.py b/tsstats/tests/test_general.py
index a1afb96..17471dd 100644
--- a/tsstats/tests/test_general.py
+++ b/tsstats/tests/test_general.py
@@ -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():
diff --git a/tsstats/tests/test_template.py b/tsstats/tests/test_template.py
index 423edf6..4f21cb4 100644
--- a/tsstats/tests/test_template.py
+++ b/tsstats/tests/test_template.py
@@ -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