Skip to content

Commit 1298727

Browse files
author
Anselm Kruis
committed
Stackless issue python#86: Modernize the unittest support classes
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)
1 parent 3ac4a0d commit 1298727

10 files changed

Lines changed: 332 additions & 128 deletions

Stackless/unittests/picklebug.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
import sys
88
import gc
99
import pickle as pickle
10+
import os
1011
from stackless import *
1112

1213
try:
1314
genschedoutertest # @UndefinedVariable
1415
except NameError:
1516
try:
16-
exec(open("test_pickle.py").read())
17+
exec(open(os.path.join(os.path.dirname(__file__), "test_pickle.py")).read())
1718
except SystemExit:
1819
pass
1920

Stackless/unittests/runAll.py

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,15 @@
55
Should be run in the folder Stackless/unittests.
66
"""
77

8-
98
import os
10-
import sys
11-
import glob
129
import unittest
13-
import stackless
14-
15-
16-
def getsoft():
17-
hold = stackless.enable_softswitch(False)
18-
stackless.enable_softswitch(hold)
19-
return hold
20-
21-
22-
def makeSuite(target, path=None):
23-
"Build a test suite of all available test files."
24-
25-
suite = unittest.TestSuite()
26-
if '.' not in sys.path:
27-
sys.path.insert(0, '.')
28-
29-
pattern = "test_*.py"
30-
if path:
31-
pattern = os.path.join(path, pattern)
32-
for idx, filename in enumerate(glob.glob(pattern)):
33-
modname = os.path.splitext(os.path.basename(filename))[0]
34-
module = __import__(modname)
35-
tests = unittest.TestLoader().loadTestsFromModule(module)
36-
use_it = target == 0 or idx + 1 == target
37-
if use_it:
38-
suite.addTest(tests)
39-
if target > 0:
40-
print("single test of '%s', switch=%s" %
41-
(filename, ("hard", "soft")[getsoft()]))
42-
43-
return suite
4410

4511

4612
def main():
4713
path = os.path.split(__file__)[0]
48-
hold = stackless.enable_softswitch(True)
49-
try:
50-
target = int(sys.argv[1])
51-
except IndexError:
52-
try:
53-
target = TARGET # @UndefinedVariable
54-
except NameError:
55-
target = 0
56-
try:
57-
flags = True, False
58-
if target:
59-
flags = (flags[target > 0],)
60-
if abs(target) == 42:
61-
target = 0
62-
for switch in flags:
63-
stackless.enable_softswitch(switch)
64-
testSuite = makeSuite(abs(target), path)
65-
verbosity = 1
66-
# verbosity = 2 # to turn on verbose mode
67-
unittest.TextTestRunner(verbosity=verbosity).run(testSuite)
68-
finally:
69-
stackless.enable_softswitch(hold)
14+
print(path)
15+
testSuite = unittest.TestLoader().discover(path)
16+
unittest.TextTestRunner(verbosity=2).run(testSuite)
7017

7118
if __name__ == '__main__':
7219
main()

0 commit comments

Comments
 (0)