Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cd1b1dd

Browse files
committed
Just import sys at the top instead of inside lots of functions.
Add some helpers for supporting PyUNIT-based unit testing.
1 parent 0253820 commit cd1b1dd

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

Lib/test/test_support.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Supporting definitions for the Python regression test."""
22

3+
import sys
4+
35

46
class Error(Exception):
57
"""Base class for regression test exceptions."""
@@ -21,15 +23,14 @@ class TestSkipped(Error):
2123
use_large_resources = 1 # Flag set to 0 by regrtest.py
2224

2325
def unload(name):
24-
import sys
2526
try:
2627
del sys.modules[name]
2728
except KeyError:
2829
pass
2930

3031
def forget(modname):
3132
unload(modname)
32-
import sys, os
33+
import os
3334
for dirname in sys.path:
3435
try:
3536
os.unlink(os.path.join(dirname, modname + '.pyc'))
@@ -68,7 +69,6 @@ def findfile(file, here=__file__):
6869
import os
6970
if os.path.isabs(file):
7071
return file
71-
import sys
7272
path = sys.path
7373
path = [os.path.dirname(here)] + path
7474
for dn in path:
@@ -93,3 +93,35 @@ def check_syntax(statement):
9393
pass
9494
else:
9595
print 'Missing SyntaxError: "%s"' % statement
96+
97+
98+
99+
#=======================================================================
100+
# Preliminary PyUNIT integration.
101+
102+
import unittest
103+
104+
105+
class BasicTestRunner(unittest.VerboseTextTestRunner):
106+
def __init__(self, stream=sys.stderr):
107+
unittest.VerboseTextTestRunner.__init__(self, stream, descriptions=0)
108+
109+
def run(self, test):
110+
result = unittest._VerboseTextTestResult(self.stream, descriptions=0)
111+
test(result)
112+
return result
113+
114+
115+
def run_unittest(testclass):
116+
"""Run tests from a unittest.TestCase-derived class."""
117+
if verbose:
118+
f = sys.stdout
119+
else:
120+
import StringIO
121+
f = StringIO.StringIO()
122+
123+
suite = unittest.makeSuite(testclass)
124+
result = BasicTestRunner(stream=f).run(suite)
125+
if result.errors or result.failures:
126+
raise TestFailed("errors occurred in %s.%s"
127+
% (testclass.__module__, testclass.__name__))

0 commit comments

Comments
 (0)