summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pydoc.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:42:12 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-07-15 20:42:12 (GMT)
commitf7f54759b5f81cc011e987746ed3edd7fcc96d21 (patch)
tree8a3604769f0eb3201955b90aa051fd4eb1da8e39 /Lib/test/test_pydoc.py
parenta6e81a23b36e61f4803cca059d55943f52b17b7f (diff)
downloadcpython-f7f54759b5f81cc011e987746ed3edd7fcc96d21.zip
cpython-f7f54759b5f81cc011e987746ed3edd7fcc96d21.tar.gz
cpython-f7f54759b5f81cc011e987746ed3edd7fcc96d21.tar.bz2
Use test.script_helper in test_pydoc
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r--Lib/test/test_pydoc.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index aaa6912..2a21a7e 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -15,11 +15,12 @@ import textwrap
from io import StringIO
from collections import namedtuple
from contextlib import contextmanager
+
+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:
@@ -201,14 +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 %s"
-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]
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- return output.strip()
+ 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"
@@ -307,19 +308,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)