24
24
from io import StringIO
25
25
from collections import namedtuple
26
26
from test .support import os_helper
27
- from test .support .script_helper import assert_python_ok
27
+ from test .support .script_helper import assert_python_ok , assert_python_failure
28
28
from test .support import threading_helper
29
29
from test .support import (reap_children , captured_output , captured_stdout ,
30
30
captured_stderr , requires_docstrings )
@@ -345,6 +345,14 @@ def run_pydoc(module_name, *args, **env):
345
345
rc , out , err = assert_python_ok ('-B' , pydoc .__file__ , * args , ** env )
346
346
return out .strip ()
347
347
348
+ def run_pydoc_fail (module_name , * args , ** env ):
349
+ """
350
+ Runs pydoc on the specified module expecting a failure.
351
+ """
352
+ args = args + (module_name ,)
353
+ rc , out , err = assert_python_failure ('-B' , pydoc .__file__ , * args , ** env )
354
+ return out .strip ()
355
+
348
356
def get_pydoc_html (module ):
349
357
"Returns pydoc generated output as html"
350
358
doc = pydoc .HTMLDoc ()
@@ -487,7 +495,7 @@ class B:
487
495
488
496
def test_not_here (self ):
489
497
missing_module = "test.i_am_not_here"
490
- result = str (run_pydoc (missing_module ), 'ascii' )
498
+ result = str (run_pydoc_fail (missing_module ), 'ascii' )
491
499
expected = missing_pattern % missing_module
492
500
self .assertEqual (expected , result ,
493
501
"documentation for missing module found" )
@@ -501,7 +509,7 @@ def test_not_ascii(self):
501
509
502
510
def test_input_strip (self ):
503
511
missing_module = " test.i_am_not_here "
504
- result = str (run_pydoc (missing_module ), 'ascii' )
512
+ result = str (run_pydoc_fail (missing_module ), 'ascii' )
505
513
expected = missing_pattern % missing_module .strip ()
506
514
self .assertEqual (expected , result )
507
515
@@ -902,7 +910,7 @@ def test_badimport(self):
902
910
for importstring , expectedinmsg in testpairs :
903
911
with open (sourcefn , 'w' ) as f :
904
912
f .write ("import {}\n " .format (importstring ))
905
- result = run_pydoc (modname , PYTHONPATH = TESTFN ).decode ("ascii" )
913
+ result = run_pydoc_fail (modname , PYTHONPATH = TESTFN ).decode ("ascii" )
906
914
expected = badimport_pattern % (modname , expectedinmsg )
907
915
self .assertEqual (expected , result )
908
916
0 commit comments