From 1f0db0934c7b6afbffdfd99b8b3658a77e32d1a4 Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Thu, 5 Jan 2017 22:43:01 +0100 Subject: [PATCH] Issue #116: Test suite: use test.regrtest as test driver in runAll.py Change Stackless/unittests/runAll.py to use the test driver of the C-Python test suite. Now we can use all CPython test suite options with Stackless too. https://bitbucket.org/stackless-dev/stackless/issues/116 (grafted from 28757ff577e0a8b796ef33c9ffb31f6372ba222f) --- Stackless/unittests/runAll.py | 25 ++++++++++++++----- Stackless/unittests/support.py | 21 ++++++++++++++++ Stackless/unittests/test_chan_cb.py | 2 ++ Stackless/unittests/test_channel.py | 2 ++ Stackless/unittests/test_defects.py | 1 + Stackless/unittests/test_exception.py | 2 ++ Stackless/unittests/test_generator.py | 2 ++ Stackless/unittests/test_miscell.py | 2 ++ Stackless/unittests/test_outside.py | 2 ++ Stackless/unittests/test_pickle.py | 1 + Stackless/unittests/test_sched_cb.py | 2 ++ Stackless/unittests/test_shutdown.py | 1 + Stackless/unittests/test_thread.py | 2 ++ .../test_tpflags_have_stackless_call.py | 2 ++ Stackless/unittests/test_tracing.py | 2 ++ Stackless/unittests/test_tstate.py | 2 ++ Stackless/unittests/test_watchdog.py | 2 ++ Stackless/unittests/test_weakref.py | 2 ++ 18 files changed, 69 insertions(+), 6 deletions(-) diff --git a/Stackless/unittests/runAll.py b/Stackless/unittests/runAll.py index 325a12faf27836..993fa5557f883c 100644 --- a/Stackless/unittests/runAll.py +++ b/Stackless/unittests/runAll.py @@ -1,19 +1,32 @@ """ runAll.py -Runs all testcases in files named test_*.py. +Runs all test-cases in files named test_*.py. Should be run in the folder Stackless/unittests. + +This driver reuses the CPython test.regrtest driver and +supports its options. """ +from __future__ import absolute_import import os -import unittest +# just to make sure, it can be imported +import support # @UnusedImport + +from test import regrtest +from test import __path__ as test_path + +# path of the Stackless unittest directory +path = os.path.split(__file__)[0] +# add the stackless unittest dir to the package "test" +test_path.insert(0, path) + +# monkey patch: remove all standard tests +del regrtest.STDTESTS[:] def main(): - path = os.path.split(__file__)[0] - print(path) - testSuite = unittest.TestLoader().discover(path) - unittest.TextTestRunner(verbosity=2).run(testSuite) + return regrtest.main(testdir=path) if __name__ == '__main__': main() diff --git a/Stackless/unittests/support.py b/Stackless/unittests/support.py index ee334deb530854..427ec928283cba 100644 --- a/Stackless/unittests/support.py +++ b/Stackless/unittests/support.py @@ -32,6 +32,7 @@ import io import contextlib import gc +from test.support import run_unittest # emit warnings about uncollectable objects gc.set_debug(gc.DEBUG_UNCOLLECTABLE) @@ -444,3 +445,23 @@ def helper(): result = c.receive() assert self._ran_AsTaskletTestCase_setUp return result + + +def test_main(): + """Main function for the CPython :mod:`test.regrtest` test driver. + + Import this function into your test_ module. It uses introspection + to find the module name and run your tests. + """ + stack = inspect.stack(0) + for i in range(1, 5): + try: + the_module = stack[i][0].f_locals["the_module"] + break + except KeyError: + pass + else: + raise RuntimeError("can't find local variable 'the_module'") + + test_suite = unittest.TestLoader().loadTestsFromModule(the_module) + return run_unittest(test_suite) diff --git a/Stackless/unittests/test_chan_cb.py b/Stackless/unittests/test_chan_cb.py index e5f2fe52292f75..8ec97eed923532 100644 --- a/Stackless/unittests/test_chan_cb.py +++ b/Stackless/unittests/test_chan_cb.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import import unittest from support import StacklessTestCase +from support import test_main # @UnusedImport class ChannelMonitor: diff --git a/Stackless/unittests/test_channel.py b/Stackless/unittests/test_channel.py index 96ab13640fba38..9d5407c1ad0ae6 100644 --- a/Stackless/unittests/test_channel.py +++ b/Stackless/unittests/test_channel.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import unittest import stackless try: @@ -8,6 +9,7 @@ import sys import traceback import contextlib +from support import test_main # @UnusedImport from support import StacklessTestCase, require_one_thread diff --git a/Stackless/unittests/test_defects.py b/Stackless/unittests/test_defects.py index 374bbd0754a57b..b2ad20708eb3dc 100644 --- a/Stackless/unittests/test_defects.py +++ b/Stackless/unittests/test_defects.py @@ -13,6 +13,7 @@ withThreads = False from stackless import _test_nostacklesscall as apply_not_stackless +from support import test_main # @UnusedImport from support import StacklessTestCase, captured_stderr, require_one_thread diff --git a/Stackless/unittests/test_exception.py b/Stackless/unittests/test_exception.py index 121795cbd83151..c7a229f07809ad 100644 --- a/Stackless/unittests/test_exception.py +++ b/Stackless/unittests/test_exception.py @@ -1,5 +1,7 @@ +from __future__ import absolute_import import unittest +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_generator.py b/Stackless/unittests/test_generator.py index 1c1fa781ace07c..4d5837af91a2f4 100644 --- a/Stackless/unittests/test_generator.py +++ b/Stackless/unittests/test_generator.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import import unittest import gc import stackless import types +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_miscell.py b/Stackless/unittests/test_miscell.py index 2ab76581a05b1a..202d35f2a384bd 100644 --- a/Stackless/unittests/test_miscell.py +++ b/Stackless/unittests/test_miscell.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import # import common import unittest @@ -18,6 +19,7 @@ except: withThreads = False +from support import test_main # @UnusedImport from support import StacklessTestCase, AsTaskletTestCase, require_one_thread diff --git a/Stackless/unittests/test_outside.py b/Stackless/unittests/test_outside.py index 8bc8ab79090abe..397acfde73f8d6 100644 --- a/Stackless/unittests/test_outside.py +++ b/Stackless/unittests/test_outside.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import import unittest from stackless import test_cframe, test_cframe_nr, test_outside, test_cstate from stackless import tasklet, channel, run +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_pickle.py b/Stackless/unittests/test_pickle.py index 0658b29d6920f1..83786ddb1bd720 100644 --- a/Stackless/unittests/test_pickle.py +++ b/Stackless/unittests/test_pickle.py @@ -6,6 +6,7 @@ from stackless import schedule, tasklet, stackless +from support import test_main # @UnusedImport from support import StacklessTestCase, StacklessPickleTestCase diff --git a/Stackless/unittests/test_sched_cb.py b/Stackless/unittests/test_sched_cb.py index c828f6ab57a00e..d66e473ec1ab4a 100644 --- a/Stackless/unittests/test_sched_cb.py +++ b/Stackless/unittests/test_sched_cb.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import import unittest import stackless import gc import traceback import sys +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_shutdown.py b/Stackless/unittests/test_shutdown.py index 9b61563b9e9d4a..b35f94b76fc9bd 100644 --- a/Stackless/unittests/test_shutdown.py +++ b/Stackless/unittests/test_shutdown.py @@ -48,6 +48,7 @@ withThreads = True except: withThreads = False +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_thread.py b/Stackless/unittests/test_thread.py index 3c8f0a29e8dfe8..b0af364a6eb4cc 100644 --- a/Stackless/unittests/test_thread.py +++ b/Stackless/unittests/test_thread.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import # import common import unittest @@ -6,6 +7,7 @@ import time from stackless import _test_nostacklesscall as apply_not_stackless +from support import test_main # @UnusedImport from support import StacklessTestCase, AsTaskletTestCase try: import threading diff --git a/Stackless/unittests/test_tpflags_have_stackless_call.py b/Stackless/unittests/test_tpflags_have_stackless_call.py index e0b91ac9d36c91..e7ee972f4926e2 100644 --- a/Stackless/unittests/test_tpflags_have_stackless_call.py +++ b/Stackless/unittests/test_tpflags_have_stackless_call.py @@ -21,10 +21,12 @@ This is a test for issue http://www.stackless.com/ticket/18 """ +from __future__ import absolute_import import unittest import stackless import gc import sys +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_tracing.py b/Stackless/unittests/test_tracing.py index cb4e99c468af9f..79f25fde14d64d 100644 --- a/Stackless/unittests/test_tracing.py +++ b/Stackless/unittests/test_tracing.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import import unittest import stackless import sys import inspect +from support import test_main # @UnusedImport from support import StacklessTestCase diff --git a/Stackless/unittests/test_tstate.py b/Stackless/unittests/test_tstate.py index 36b64a259b4e33..0fc62f2c01f781 100644 --- a/Stackless/unittests/test_tstate.py +++ b/Stackless/unittests/test_tstate.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import import unittest import sys from pickle import Pickler, Unpickler from io import BytesIO from stackless import * +from support import test_main # @UnusedImport from support import StacklessTestCase # import os diff --git a/Stackless/unittests/test_watchdog.py b/Stackless/unittests/test_watchdog.py index 68533579da857b..08f47d763f0eab 100644 --- a/Stackless/unittests/test_watchdog.py +++ b/Stackless/unittests/test_watchdog.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import import sys import random import unittest import stackless +from support import test_main # @UnusedImport from support import StacklessTestCase, require_one_thread diff --git a/Stackless/unittests/test_weakref.py b/Stackless/unittests/test_weakref.py index 122fbac88090c0..831ef900134711 100644 --- a/Stackless/unittests/test_weakref.py +++ b/Stackless/unittests/test_weakref.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import import unittest import weakref from stackless import * +from support import test_main # @UnusedImport from support import StacklessTestCase