Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_pydoc.PydocDocTest Class Reference

List of all members.

Public Member Functions

def test_html_doc
def test_text_doc
def test_issue8225
def test_not_here
def test_badimport
def test_input_strip
def test_stripid
def test_help_output_redirect
def test_namedtuple_public_underscore
def test_synopsis

Public Attributes

 maxDiff

Detailed Description

Definition at line 255 of file test_pydoc.py.


Member Function Documentation

Definition at line 294 of file test_pydoc.py.

00294 
00295     def test_badimport(self):
00296         # This tests the fix for issue 5230, where if pydoc found the module
00297         # but the module had an internal import error pydoc would report no doc
00298         # found.
00299         modname = 'testmod_xyzzy'
00300         testpairs = (
00301             ('i_am_not_here', 'i_am_not_here'),
00302             ('test.i_am_not_here_either', 'i_am_not_here_either'),
00303             ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
00304             ('i_am_not_here.{}'.format(modname),
00305              'i_am_not_here.{}'.format(modname)),
00306             ('test.{}'.format(modname), modname),
00307             )
00308 
00309         @contextmanager
00310         def newdirinpath(dir):
00311             os.mkdir(dir)
00312             sys.path.insert(0, dir)
00313             try:
00314                 yield
00315             finally:
00316                 sys.path.pop(0)
00317                 rmtree(dir)
00318 
00319         with newdirinpath(TESTFN):
00320             fullmodname = os.path.join(TESTFN, modname)
00321             sourcefn = fullmodname + os.extsep + "py"
00322             for importstring, expectedinmsg in testpairs:
00323                 with open(sourcefn, 'w') as f:
00324                     f.write("import {}\n".format(importstring))
00325                 try:
00326                     result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
00327                 finally:
00328                     forget(modname)
00329                 expected = badimport_pattern % (modname, expectedinmsg)
00330                 self.assertEqual(expected, result)

Here is the call graph for this function:

Definition at line 352 of file test_pydoc.py.

00352 
00353     def test_help_output_redirect(self):
00354         # issue 940286, if output is set in Helper, then all output from
00355         # Helper.help should be redirected
00356         old_pattern = expected_text_pattern
00357         getpager_old = pydoc.getpager
00358         getpager_new = lambda: (lambda x: x)
00359         self.maxDiff = None
00360 
00361         buf = StringIO()
00362         helper = pydoc.Helper(output=buf)
00363         unused, doc_loc = get_pydoc_text(pydoc_mod)
00364         module = "test.pydoc_mod"
00365         help_header = """
00366         Help on module test.pydoc_mod in test:
00367 
00368         """.lstrip()
00369         help_header = textwrap.dedent(help_header)
00370         expected_help_pattern = help_header + expected_text_pattern
00371 
00372         pydoc.getpager = getpager_new
00373         try:
00374             with captured_output('stdout') as output, \
00375                  captured_output('stderr') as err:
00376                 helper.help(module)
00377                 result = buf.getvalue().strip()
00378                 expected_text = expected_help_pattern % \
00379                                 (doc_loc, inspect.getabsfile(pydoc_mod))
00380                 self.assertEqual('', output.getvalue())
00381                 self.assertEqual('', err.getvalue())
00382                 self.assertEqual(expected_text, result)
00383         finally:
00384             pydoc.getpager = getpager_old

Definition at line 259 of file test_pydoc.py.

00259 
00260     def test_html_doc(self):
00261         result, doc_loc = get_pydoc_html(pydoc_mod)
00262         mod_file = inspect.getabsfile(pydoc_mod)
00263         if sys.platform == 'win32':
00264             import nturl2path
00265             mod_url = nturl2path.pathname2url(mod_file)
00266         else:
00267             mod_url = mod_file
00268         expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc)
00269         if result != expected_html:
00270             print_diffs(expected_html, result)
00271             self.fail("outputs are not equal, see diff above")

Here is the call graph for this function:

Definition at line 331 of file test_pydoc.py.

00331 
00332     def test_input_strip(self):
00333         missing_module = " test.i_am_not_here "
00334         result = str(run_pydoc(missing_module), 'ascii')
00335         expected = missing_pattern % missing_module.strip()
00336         self.assertEqual(expected, result)

Here is the call graph for this function:

Definition at line 282 of file test_pydoc.py.

00282 
00283     def test_issue8225(self):
00284         # Test issue8225 to ensure no doc link appears for xml.etree
00285         result, doc_loc = get_pydoc_text(xml.etree)
00286         self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")

Here is the call graph for this function:

Definition at line 385 of file test_pydoc.py.

00385 
00386     def test_namedtuple_public_underscore(self):
00387         NT = namedtuple('NT', ['abc', 'def'], rename=True)
00388         with captured_stdout() as help_io:
00389             help(NT)
00390         helptext = help_io.getvalue()
00391         self.assertIn('_1', helptext)
00392         self.assertIn('_replace', helptext)
00393         self.assertIn('_asdict', helptext)

Here is the call graph for this function:

Definition at line 287 of file test_pydoc.py.

00287 
00288     def test_not_here(self):
00289         missing_module = "test.i_am_not_here"
00290         result = str(run_pydoc(missing_module), 'ascii')
00291         expected = missing_pattern % missing_module
00292         self.assertEqual(expected, result,
00293             "documentation for missing module found")

Here is the call graph for this function:

Definition at line 337 of file test_pydoc.py.

00337 
00338     def test_stripid(self):
00339         # test with strings, other implementations might have different repr()
00340         stripid = pydoc.stripid
00341         # strip the id
00342         self.assertEqual(stripid('<function stripid at 0x88dcee4>'),
00343                          '<function stripid>')
00344         self.assertEqual(stripid('<function stripid at 0x01F65390>'),
00345                          '<function stripid>')
00346         # nothing to strip, return the same text
00347         self.assertEqual(stripid('42'), '42')
00348         self.assertEqual(stripid("<type 'exceptions.Exception'>"),
00349                          "<type 'exceptions.Exception'>")

Here is the call graph for this function:

Definition at line 394 of file test_pydoc.py.

00394 
00395     def test_synopsis(self):
00396         self.addCleanup(unlink, TESTFN)
00397         for encoding in ('ISO-8859-1', 'UTF-8'):
00398             with open(TESTFN, 'w', encoding=encoding) as script:
00399                 if encoding != 'UTF-8':
00400                     print('#coding: {}'.format(encoding), file=script)
00401                 print('"""line 1: h\xe9', file=script)
00402                 print('line 2: hi"""', file=script)
00403             synopsis = pydoc.synopsis(TESTFN, {})
00404             self.assertEqual(synopsis, 'line 1: h\xe9')
00405 

Here is the call graph for this function:

Definition at line 274 of file test_pydoc.py.

00274 
00275     def test_text_doc(self):
00276         result, doc_loc = get_pydoc_text(pydoc_mod)
00277         expected_text = expected_text_pattern % \
00278                         (doc_loc, inspect.getabsfile(pydoc_mod))
00279         if result != expected_text:
00280             print_diffs(expected_text, result)
00281             self.fail("outputs are not equal, see diff above")

Here is the call graph for this function:


Member Data Documentation

Definition at line 358 of file test_pydoc.py.


The documentation for this class was generated from the following file: