From 076ee8d11a83da77ee6c70018076c0e77783675f Mon Sep 17 00:00:00 2001 From: Juhani Numminen Date: Thu, 11 Feb 2021 13:49:28 +0200 Subject: [PATCH] Run unittests via a single TAP test Enable standard unittest discovery by creating __init__.py files and renaming test modules to test*.py. --- MANIFEST.in | 8 ++++--- Makefile | 3 +-- run-tests.pl | 4 ++-- scripts/gen_individual_importing_tests.py | 24 ------------------- .../PLACEHOLDER => __init__.py} | 0 tests/lib/__init__.py | 0 .../{common_mocks1.py => common_mocks.py} | 0 .../{acard_unit.py => test_acard.py} | 2 +- ...cardsetparser.py => test_cardsetparser.py} | 2 +- .../{game_drag.py => test_game_drag.py} | 2 +- .../lib/pysol_tests/{hint.py => test_hint.py} | 2 +- .../{import_file1.py => test_import_file.py} | 6 ++--- ...atin1_conv_unit.py => test_latin1_conv.py} | 2 +- .../__init__.py => test_ms_deals.py} | 2 +- ...on_canMove.py => test_scorpion_canMove.py} | 6 ++--- tests/t/tap_unittests.py | 7 ++++++ 16 files changed, 27 insertions(+), 43 deletions(-) rename tests/{unit-generated/PLACEHOLDER => __init__.py} (100%) create mode 100644 tests/lib/__init__.py rename tests/lib/pysol_tests/{common_mocks1.py => common_mocks.py} (100%) rename tests/lib/pysol_tests/{acard_unit.py => test_acard.py} (92%) rename tests/lib/pysol_tests/{cardsetparser.py => test_cardsetparser.py} (97%) rename tests/lib/pysol_tests/{game_drag.py => test_game_drag.py} (91%) rename tests/lib/pysol_tests/{hint.py => test_hint.py} (93%) rename tests/lib/pysol_tests/{import_file1.py => test_import_file.py} (97%) rename tests/lib/pysol_tests/{latin1_conv_unit.py => test_latin1_conv.py} (85%) rename tests/lib/pysol_tests/{ms_deals1/__init__.py => test_ms_deals.py} (99%) rename tests/lib/pysol_tests/{scorpion_canMove.py => test_scorpion_canMove.py} (95%) create mode 100644 tests/t/tap_unittests.py diff --git a/MANIFEST.in b/MANIFEST.in index e19daaed..61ebb510 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -22,11 +22,13 @@ include scripts/create_iss.py scripts/mahjongg_utils.py include scripts/all_games.py scripts/cardset_viewer.py include scripts/cardconv include scripts/gen_individual_importing_tests.py + +recursive-include tests/ *.pm *.py *.t *.yml +exclude tests/individually-importing/* include tests/individually-importing/PLACEHOLDER -recursive-include tests/lib *.pm *.py + recursive-include tests/unit/data * -include tests/style/*.t -include tests/unit-generated/PLACEHOLDER + include .tidyallrc include android/*.py include android/mk* diff --git a/Makefile b/Makefile index de80d415..890b6f9a 100644 --- a/Makefile +++ b/Makefile @@ -61,9 +61,8 @@ pretest: python3 scripts/gen_individual_importing_tests.py TEST_ENV_PATH = $(CURDIR)$(path_sep)$(CURDIR)/tests/lib -TEST_FILES = tests/style/*.t tests/unit-generated/*.py tests/individually-importing/*.py +TEST_FILES = tests/style/*.t tests/t/*.py tests/individually-importing/*.py -test runtest: export PYTHONPATH := $(PYTHONPATH)$(path_sep)$(TEST_ENV_PATH) test runtest: export PERL5LIB := $(PERL5LIB)$(path_sep)$(TEST_ENV_PATH) test: pretest diff --git a/run-tests.pl b/run-tests.pl index ed996aef..4cbd87e5 100644 --- a/run-tests.pl +++ b/run-tests.pl @@ -63,8 +63,8 @@ sub run_tests } } -my $tests_glob = "*.{t.exe,py,t}"; -my $exclude_re_s; +my $tests_glob = "*.{t.exe,py,t}"; +my $exclude_re_s = "__init__"; my @execute; GetOptions( diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index a4d529ba..35bbeccf 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -40,27 +40,3 @@ sys.path.insert(0, ".") import %(module_name)s print('ok 1 - imported') ''')) - -for ver in PY_VERS: - for mod in [ - 'pysol_tests.acard_unit', - 'pysol_tests.cardsetparser', - 'pysol_tests.game_drag', - 'pysol_tests.hint', - 'pysol_tests.import_file1', - 'pysol_tests.latin1_conv_unit', - 'pysol_tests.ms_deals1', - 'pysol_tests.scorpion_canMove', - ]: - open(os.path.join(".", "tests", "unit-generated", - 'test__%s__v%d.py' % (mod, ver) - ), 'w').write('''#!/usr/bin/env python%(ver)d -import unittest - -from pycotap import TAPTestRunner - -from %(mod)s import MyTests - -suite = unittest.TestLoader().loadTestsFromTestCase(MyTests) -TAPTestRunner().run(suite) -''' % {'mod': mod, 'ver': ver}) diff --git a/tests/unit-generated/PLACEHOLDER b/tests/__init__.py similarity index 100% rename from tests/unit-generated/PLACEHOLDER rename to tests/__init__.py diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/lib/pysol_tests/common_mocks1.py b/tests/lib/pysol_tests/common_mocks.py similarity index 100% rename from tests/lib/pysol_tests/common_mocks1.py rename to tests/lib/pysol_tests/common_mocks.py diff --git a/tests/lib/pysol_tests/acard_unit.py b/tests/lib/pysol_tests/test_acard.py similarity index 92% rename from tests/lib/pysol_tests/acard_unit.py rename to tests/lib/pysol_tests/test_acard.py index 60b5f73a..3670cc22 100644 --- a/tests/lib/pysol_tests/acard_unit.py +++ b/tests/lib/pysol_tests/test_acard.py @@ -5,7 +5,7 @@ import unittest from pysollib.acard import AbstractCard -class MyTests(unittest.TestCase): +class AbstractCardTests(unittest.TestCase): def test_cards(self): card1 = AbstractCard(1001, 0, 1, 2, 3001) # TEST diff --git a/tests/lib/pysol_tests/cardsetparser.py b/tests/lib/pysol_tests/test_cardsetparser.py similarity index 97% rename from tests/lib/pysol_tests/cardsetparser.py rename to tests/lib/pysol_tests/test_cardsetparser.py index 1c506f9c..9878c4ee 100644 --- a/tests/lib/pysol_tests/cardsetparser.py +++ b/tests/lib/pysol_tests/test_cardsetparser.py @@ -6,7 +6,7 @@ from pysollib.cardsetparser import parse_cardset_config from pysollib.resource import CSI, CardsetConfig -class MyTests(unittest.TestCase): +class CardsetParserTests(unittest.TestCase): def _assertCcEqual(self, a, b, msg=None): """Assert that CardsetConfig objects a and b have equal attributes.""" diff --git a/tests/lib/pysol_tests/game_drag.py b/tests/lib/pysol_tests/test_game_drag.py similarity index 91% rename from tests/lib/pysol_tests/game_drag.py rename to tests/lib/pysol_tests/test_game_drag.py index a5a833b9..4333e5d3 100644 --- a/tests/lib/pysol_tests/game_drag.py +++ b/tests/lib/pysol_tests/test_game_drag.py @@ -5,7 +5,7 @@ import unittest from pysollib.game import GameDrag, GameStacks -class MyTests(unittest.TestCase): +class GameDragTests(unittest.TestCase): def test_shadows(self): d = GameDrag() d.shadows.append("test") diff --git a/tests/lib/pysol_tests/hint.py b/tests/lib/pysol_tests/test_hint.py similarity index 93% rename from tests/lib/pysol_tests/hint.py rename to tests/lib/pysol_tests/test_hint.py index 4f24a3c9..fc329464 100644 --- a/tests/lib/pysol_tests/hint.py +++ b/tests/lib/pysol_tests/test_hint.py @@ -6,7 +6,7 @@ from pysollib.acard import AbstractCard from pysollib.hint import Base_Solver_Hint -class MyTests(unittest.TestCase): +class HintTests(unittest.TestCase): def test_output(self): card = AbstractCard(1001, 0, 3, 7, 3001) h = Base_Solver_Hint(None, None, base_rank=0) diff --git a/tests/lib/pysol_tests/import_file1.py b/tests/lib/pysol_tests/test_import_file.py similarity index 97% rename from tests/lib/pysol_tests/import_file1.py rename to tests/lib/pysol_tests/test_import_file.py index 48c3b51d..b46eb9e5 100644 --- a/tests/lib/pysol_tests/import_file1.py +++ b/tests/lib/pysol_tests/test_import_file.py @@ -2,11 +2,11 @@ import unittest -from pysol_tests.common_mocks1 import MockApp, MockCanvas, MockTalon - import pysollib.stack from pysollib.hint import FreeCellSolver_Hint, PySolHintLayoutImportError +from .common_mocks import MockApp, MockCanvas, MockTalon + class MockGame: def __init__(self): @@ -38,7 +38,7 @@ class Mock_S_Game: # noqa: N801 pass -class MyTests(unittest.TestCase): +class ImportFileTests(unittest.TestCase): def _calc_hint(self, fn): """docstring for _calc_hint""" s_game = Mock_S_Game() diff --git a/tests/lib/pysol_tests/latin1_conv_unit.py b/tests/lib/pysol_tests/test_latin1_conv.py similarity index 85% rename from tests/lib/pysol_tests/latin1_conv_unit.py rename to tests/lib/pysol_tests/test_latin1_conv.py index d949093c..919eb1a4 100644 --- a/tests/lib/pysol_tests/latin1_conv_unit.py +++ b/tests/lib/pysol_tests/test_latin1_conv.py @@ -5,6 +5,6 @@ import unittest from pysollib.mfxutil import latin1_normalize -class MyTests(unittest.TestCase): +class Latin1Tests(unittest.TestCase): def test_output(self): self.assertEqual(latin1_normalize('HELLO%%good'), 'hellogood') diff --git a/tests/lib/pysol_tests/ms_deals1/__init__.py b/tests/lib/pysol_tests/test_ms_deals.py similarity index 99% rename from tests/lib/pysol_tests/ms_deals1/__init__.py rename to tests/lib/pysol_tests/test_ms_deals.py index fc447903..b9c1576e 100644 --- a/tests/lib/pysol_tests/ms_deals1/__init__.py +++ b/tests/lib/pysol_tests/test_ms_deals.py @@ -73,7 +73,7 @@ from pysollib.pysolrandom import construct_random ren = CardRenderer(True) -class MyTests(unittest.TestCase): +class MsDealsTests(unittest.TestCase): def _cmp_board(self, got_s, expected_s, blurb): if not self.assertEqual(got_s, expected_s, blurb): return False diff --git a/tests/lib/pysol_tests/scorpion_canMove.py b/tests/lib/pysol_tests/test_scorpion_canMove.py similarity index 95% rename from tests/lib/pysol_tests/scorpion_canMove.py rename to tests/lib/pysol_tests/test_scorpion_canMove.py index f31ab4c7..7d813d0a 100644 --- a/tests/lib/pysol_tests/scorpion_canMove.py +++ b/tests/lib/pysol_tests/test_scorpion_canMove.py @@ -2,14 +2,14 @@ import unittest -from pysol_tests.common_mocks1 import MockApp, MockCanvas, MockItem, MockTalon - import pysollib.stack from pysollib.acard import AbstractCard from pysollib.games.spider import ScorpionTail_RowStack from pysollib.games.spider import Scorpion_RowStack from pysollib.games.spider import Spider_RowStack +from .common_mocks import MockApp, MockCanvas, MockItem, MockTalon + class MockGame: def __init__(self): @@ -42,7 +42,7 @@ class Mock_S_Game: # noqa: N801 pass -class MyTests(unittest.TestCase): +class ScorpionTests(unittest.TestCase): def _calc_scorpion_stack(self, is_scorpion_tail): g = MockGame() stack = (ScorpionTail_RowStack diff --git a/tests/t/tap_unittests.py b/tests/t/tap_unittests.py new file mode 100644 index 00000000..c3fef09d --- /dev/null +++ b/tests/t/tap_unittests.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +import unittest + +from pycotap import LogMode, TAPTestRunner + +suite = unittest.TestLoader().discover('.') +TAPTestRunner(LogMode.LogToError).run(suite)