From e19edc2c673b2f672d613c97bce91c0ec238e80a Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sun, 11 Sep 2016 22:15:35 +0300 Subject: [PATCH] Use pytest for testing --- ChangeLog | 4 ++++ requirements_dev.txt | 3 +++ tests/Makefile | 2 +- tests/__init__.py | 10 ---------- tests/run_all.py | 39 --------------------------------------- tests/test_config.conf | 3 +++ tests/test_config.py | 6 ------ tests/test_format.py | 17 ++++++++--------- tests/test_glst.py | 8 +------- tests/test_inp.py | 8 +------- tests/test_search.py | 8 +------- 11 files changed, 22 insertions(+), 86 deletions(-) create mode 100644 requirements_dev.txt delete mode 100755 tests/run_all.py mode change 100755 => 100644 tests/test_config.py mode change 100755 => 100644 tests/test_format.py mode change 100755 => 100644 tests/test_glst.py mode change 100755 => 100644 tests/test_inp.py mode change 100755 => 100644 tests/test_search.py diff --git a/ChangeLog b/ChangeLog index e0d2c0e..7367ef1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Version 0.0.15 (2016-07-??) + + Use pytest for testing. + Version 0.0.14 (2016-07-29) Python 3: support for Py2 and Py3 (3.4+) with one codebase. diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..73c8ac6 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,3 @@ +-r requirements.txt + +pytest diff --git a/tests/Makefile b/tests/Makefile index b990065..0c6125e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,4 +1,4 @@ .PHONY: all all: - ./run_all.py + pytest diff --git a/tests/__init__.py b/tests/__init__.py index e55661f..598d463 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -24,13 +24,3 @@ class TestCase(unittest.TestCase): def import_inpx(self, inpx): import_inpx(os.path.join(os.path.dirname(__file__), inpx)) - - -def main(): - try: - unittest.main(testRunner=unittest.TextTestRunner()) - except SystemExit as msg: - result = msg.args[0] - else: - result = 0 - raise SystemExit(result) diff --git a/tests/run_all.py b/tests/run_all.py deleted file mode 100755 index c04d9ed..0000000 --- a/tests/run_all.py +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env python - - -from __future__ import print_function -import os -import sys -import subprocess - - -def isexecutable(filename): - infile = open(filename, 'r') - magic = infile.read(2) - infile.close() - return magic == "#!" - - -def collect_tests(): - tests = [] - for dirpath, dirs, files in os.walk("tests"): - tests.extend( - [os.path.join(dirpath, filename) for filename in files - if filename.startswith("test") and filename.endswith(".py") - ]) - return [test[:-3].replace(os.sep, '.') for test in tests - if isexecutable(test)] - - -def main(): - os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir)) - tests = collect_tests() - - os.environ["PYTHONPATH"] = os.curdir - - for test in sorted(tests): - print(test) - subprocess.call((sys.executable, '-m', test)) - -if __name__ == '__main__': - main() diff --git a/tests/test_config.conf b/tests/test_config.conf index 8154b2b..249deef 100644 --- a/tests/test_config.conf +++ b/tests/test_config.conf @@ -1,2 +1,5 @@ [library] path = /home/test-config + +[download] +format = %f diff --git a/tests/test_config.py b/tests/test_config.py old mode 100755 new mode 100644 index 6e0c6a3..0a6e07b --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,8 +1,6 @@ -#! /usr/bin/env python import os import unittest -from tests import main from m_librarian.config import get_config @@ -13,7 +11,3 @@ class TestFormat(unittest.TestCase): get_config(config_path) ml_conf = get_config() self.assertEqual(ml_conf.get('library', 'path'), '/home/test-config') - - -if __name__ == "__main__": - main() diff --git a/tests/test_format.py b/tests/test_format.py old mode 100755 new mode 100644 index 8dc1a22..2710af9 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -1,18 +1,17 @@ -#! /usr/bin/env python - +import os import unittest -from tests import main -from m_librarian import config, download +from m_librarian import download +from m_librarian.config import get_config class TestFormat(unittest.TestCase): def test_compile_format(self): - config.get_config().set('download', 'format', '%a/%s/%n %t') + config_path = os.path.join( + os.path.dirname(__file__), 'test_config.conf') + get_config(config_path) + ml_conf = get_config() + ml_conf.set('download', 'format', '%a/%s/%n %t') download._compile_format() self.assertEqual(download.compiled_format, u'%(author)s/%(series)s/%(ser_no)d %(title)s') - - -if __name__ == "__main__": - main() diff --git a/tests/test_glst.py b/tests/test_glst.py old mode 100755 new mode 100644 index 5349bb3..bf4bd0c --- a/tests/test_glst.py +++ b/tests/test_glst.py @@ -1,7 +1,5 @@ -#! /usr/bin/env python - -from tests import TestCase, main +from tests import TestCase from m_librarian.db import Genre from m_librarian.glst import import_glst @@ -10,7 +8,3 @@ class TestGlst(TestCase): def test_import_glst(self): import_glst() self.assertEqual(Genre.select().count(), 340) - - -if __name__ == "__main__": - main() diff --git a/tests/test_inp.py b/tests/test_inp.py old mode 100755 new mode 100644 index 6aeefd1..9471421 --- a/tests/test_inp.py +++ b/tests/test_inp.py @@ -1,7 +1,5 @@ -#! /usr/bin/env python - -from tests import TestCase, main +from tests import TestCase from m_librarian.db import Author, Book @@ -13,7 +11,3 @@ class TestInp(TestCase): self.import_inpx('test.inpx') self.assertEqual(Author.select().count(), 4) self.assertEqual(Book.select().count(), 4) - - -if __name__ == "__main__": - main() diff --git a/tests/test_search.py b/tests/test_search.py old mode 100755 new mode 100644 index bc6ceca..7fdf9fe --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,8 +1,6 @@ -#! /usr/bin/env python # coding: utf-8 - -from tests import TestCase, main +from tests import TestCase from m_librarian.db import Author, Book from m_librarian.search import mk_search_conditions, \ search_authors, search_books @@ -30,7 +28,3 @@ class TestSearch(TestCase): search_books('start', False, {'title': u'тест'}, join_expressions).count(), 2) - - -if __name__ == "__main__": - main() -- 2.39.2