Skip to content

Commit

Permalink
Stackless issue python#86: Modernize the unittest support classes
Browse files Browse the repository at this point in the history
Reimplement Stackless/unittests/support.py. The new implementation
is more IDE friendly and requires only a single pass to run all
test with and without soft switching.

Base all tests on StacklessTestCase.
Remove a second call of unittest.main from ```if __name__ ==
"__main__"```-blocks

https://bitbucket.org/stackless-dev/stackless/issues/86
(grafted from 8237bba0d27ab1bdd2cdbfa52c7bdb6f468119a7, 719923b5c638,
06295530c672, 65cff13662f2)
  • Loading branch information
Anselm Kruis committed Aug 26, 2016
1 parent 3ac4a0d commit 1298727
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 128 deletions.
3 changes: 2 additions & 1 deletion Stackless/unittests/picklebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import sys
import gc
import pickle as pickle
import os
from stackless import *

try:
genschedoutertest # @UndefinedVariable
except NameError:
try:
exec(open("test_pickle.py").read())
exec(open(os.path.join(os.path.dirname(__file__), "test_pickle.py")).read())
except SystemExit:
pass

Expand Down
59 changes: 3 additions & 56 deletions Stackless/unittests/runAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,15 @@
Should be run in the folder Stackless/unittests.
"""


import os
import sys
import glob
import unittest
import stackless


def getsoft():
hold = stackless.enable_softswitch(False)
stackless.enable_softswitch(hold)
return hold


def makeSuite(target, path=None):
"Build a test suite of all available test files."

suite = unittest.TestSuite()
if '.' not in sys.path:
sys.path.insert(0, '.')

pattern = "test_*.py"
if path:
pattern = os.path.join(path, pattern)
for idx, filename in enumerate(glob.glob(pattern)):
modname = os.path.splitext(os.path.basename(filename))[0]
module = __import__(modname)
tests = unittest.TestLoader().loadTestsFromModule(module)
use_it = target == 0 or idx + 1 == target
if use_it:
suite.addTest(tests)
if target > 0:
print("single test of '%s', switch=%s" %
(filename, ("hard", "soft")[getsoft()]))

return suite


def main():
path = os.path.split(__file__)[0]
hold = stackless.enable_softswitch(True)
try:
target = int(sys.argv[1])
except IndexError:
try:
target = TARGET # @UndefinedVariable
except NameError:
target = 0
try:
flags = True, False
if target:
flags = (flags[target > 0],)
if abs(target) == 42:
target = 0
for switch in flags:
stackless.enable_softswitch(switch)
testSuite = makeSuite(abs(target), path)
verbosity = 1
# verbosity = 2 # to turn on verbose mode
unittest.TextTestRunner(verbosity=verbosity).run(testSuite)
finally:
stackless.enable_softswitch(hold)
print(path)
testSuite = unittest.TestLoader().discover(path)
unittest.TextTestRunner(verbosity=2).run(testSuite)

if __name__ == '__main__':
main()
Expand Down
Loading

0 comments on commit 1298727

Please sign in to comment.