summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:43:33 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:43:33 (GMT)
commitafed6ecf218c498ecded76fd03519ea9644737f2 (patch)
treea1ba17cc771a7bad78cff0802f5822127f396b87 /Lib
parente720725c12e37a1081e2f493b67254096f6d5aa3 (diff)
parentf7f54759b5f81cc011e987746ed3edd7fcc96d21 (diff)
downloadcpython-afed6ecf218c498ecded76fd03519ea9644737f2.zip
cpython-afed6ecf218c498ecded76fd03519ea9644737f2.tar.gz
cpython-afed6ecf218c498ecded76fd03519ea9644737f2.tar.bz2
Merge from 3.2
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/support.py19
-rw-r--r--Lib/test/test_pydoc.py47
2 files changed, 39 insertions, 27 deletions
diff --git a/Lib/test/support.py b/Lib/test/support.py
index 3dc4bfb..89ace45 100644
--- a/Lib/test/support.py
+++ b/Lib/test/support.py
@@ -24,9 +24,15 @@ import sysconfig
import logging.handlers
try:
- import _thread
+ import _thread, threading
except ImportError:
_thread = None
+ threading = None
+try:
+ import multiprocessing.process
+except ImportError:
+ multiprocessing = None
+
try:
import zlib
@@ -1358,19 +1364,20 @@ def modules_cleanup(oldmodules):
def threading_setup():
if _thread:
- return _thread._count(),
+ return _thread._count(), threading._dangling.copy()
else:
- return 1,
+ return 1, ()
-def threading_cleanup(nb_threads):
+def threading_cleanup(*original_values):
if not _thread:
return
_MAX_COUNT = 10
for count in range(_MAX_COUNT):
- n = _thread._count()
- if n == nb_threads:
+ values = _thread._count(), threading._dangling
+ if values == original_values:
break
time.sleep(0.1)
+ gc_collect()
# XXX print a warning in case of failure?
def reap_threads(func):
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index db118ca..7591303 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -15,9 +15,12 @@ import textwrap
from io import StringIO
from collections import namedtuple
from contextlib import contextmanager
-from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard, \
- reap_children, captured_output, captured_stdout, unlink
+from test.script_helper import assert_python_ok
+from test.support import (
+ TESTFN, forget, rmtree, EnvironmentVarGuard,
+ reap_children, reap_threads, captured_output, captured_stdout, unlink
+)
from test import pydoc_mod
try:
@@ -199,17 +202,14 @@ missing_pattern = "no Python documentation found for '%s'"
# output pattern for module with bad imports
badimport_pattern = "problem in %s - ImportError: No module named %r"
-def run_pydoc(module_name, *args):
+def run_pydoc(module_name, *args, **env):
"""
Runs pydoc on the specified module. Returns the stripped
output of pydoc.
"""
- cmd = [sys.executable, pydoc.__file__, " ".join(args), module_name]
- try:
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- return output.strip()
- finally:
- reap_children()
+ args = args + (module_name,)
+ rc, out, err = assert_python_ok(pydoc.__file__, *args, **env)
+ return out.strip()
def get_pydoc_html(module):
"Returns pydoc generated output as html"
@@ -312,19 +312,20 @@ class PydocDocTest(unittest.TestCase):
def newdirinpath(dir):
os.mkdir(dir)
sys.path.insert(0, dir)
- yield
- sys.path.pop(0)
- rmtree(dir)
+ try:
+ yield
+ finally:
+ sys.path.pop(0)
+ rmtree(dir)
- with newdirinpath(TESTFN), EnvironmentVarGuard() as env:
- env['PYTHONPATH'] = TESTFN
+ with newdirinpath(TESTFN):
fullmodname = os.path.join(TESTFN, modname)
sourcefn = fullmodname + os.extsep + "py"
for importstring, expectedinmsg in testpairs:
with open(sourcefn, 'w') as f:
f.write("import {}\n".format(importstring))
try:
- result = run_pydoc(modname).decode("ascii")
+ result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
finally:
forget(modname)
expected = badimport_pattern % (modname, expectedinmsg)
@@ -494,13 +495,17 @@ class TestHelper(unittest.TestCase):
self.assertEqual(sorted(pydoc.Helper.keywords),
sorted(keyword.kwlist))
+@reap_threads
def test_main():
- test.support.run_unittest(PydocDocTest,
- TestDescriptions,
- PydocServerTest,
- PydocUrlHandlerTest,
- TestHelper,
- )
+ try:
+ test.support.run_unittest(PydocDocTest,
+ TestDescriptions,
+ PydocServerTest,
+ PydocUrlHandlerTest,
+ TestHelper,
+ )
+ finally:
+ reap_children()
if __name__ == "__main__":
test_main()