blob: f6aae122e0bfe82af60b44d200659e855125ffe9 [file] [log] [blame]
Georg Brandlb533e262008-05-25 18:19:30 +00001import os
Nick Coghlan7bb30b72010-12-03 09:29:11 +00002import sys
Éric Araujoe64e51b2011-07-29 17:03:55 +02003import builtins
Antoine Pitrou916fc7b2013-05-19 15:44:54 +02004import contextlib
Georg Brandlb533e262008-05-25 18:19:30 +00005import difflib
Georg Brandlb533e262008-05-25 18:19:30 +00006import inspect
Nick Coghlan7bb30b72010-12-03 09:29:11 +00007import pydoc
Ezio Melottib185a042011-04-28 07:42:55 +03008import keyword
Larry Hastings13da6a12014-02-20 23:34:46 -08009import _pickle
Antoine Pitrou916fc7b2013-05-19 15:44:54 +020010import pkgutil
Nick Coghlan7bb30b72010-12-03 09:29:11 +000011import re
12import string
Georg Brandlb533e262008-05-25 18:19:30 +000013import test.support
Nick Coghlan7bb30b72010-12-03 09:29:11 +000014import time
Ethan Furmanb0c84cd2013-10-20 22:37:39 -070015import types
Nick Coghlan7bb30b72010-12-03 09:29:11 +000016import unittest
Brian Curtin49c284c2010-03-31 03:19:28 +000017import xml.etree
Georg Brandld80d5f42010-12-03 07:47:22 +000018import textwrap
19from io import StringIO
Raymond Hettinger1103d052011-03-25 14:15:24 -070020from collections import namedtuple
Antoine Pitrouf7f54752011-07-15 22:42:12 +020021from test.script_helper import assert_python_ok
Antoine Pitroua6e81a22011-07-15 22:32:25 +020022from test.support import (
Ned Deily92a81a12011-10-06 14:19:03 -070023 TESTFN, rmtree,
Antoine Pitrou916fc7b2013-05-19 15:44:54 +020024 reap_children, reap_threads, captured_output, captured_stdout,
Stefan Krah5de32782014-01-18 23:18:39 +010025 captured_stderr, unlink, requires_docstrings
Antoine Pitroua6e81a22011-07-15 22:32:25 +020026)
Georg Brandlb533e262008-05-25 18:19:30 +000027from test import pydoc_mod
28
Victor Stinner62a68f22011-05-20 02:29:13 +020029try:
30 import threading
31except ImportError:
32 threading = None
33
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020034if test.support.HAVE_DOCSTRINGS:
35 expected_data_docstrings = (
36 'dictionary for instance variables (if defined)',
37 'list of weak references to the object (if defined)',
38 ) * 2
39else:
40 expected_data_docstrings = ('', '', '', '')
41
Barry Warsaw28a691b2010-04-17 00:19:56 +000042expected_text_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +000043NAME
44 test.pydoc_mod - This is a test module for test_pydoc
Georg Brandlb533e262008-05-25 18:19:30 +000045%s
46CLASSES
47 builtins.object
48 A
49 B
50\x20\x20\x20\x20
51 class A(builtins.object)
52 | Hello and goodbye
53 |\x20\x20
54 | Methods defined here:
55 |\x20\x20
56 | __init__()
57 | Wow, I have no function!
58 |\x20\x20
59 | ----------------------------------------------------------------------
60 | Data descriptors defined here:
61 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020062 | __dict__%s
Georg Brandlb533e262008-05-25 18:19:30 +000063 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020064 | __weakref__%s
Georg Brandlb533e262008-05-25 18:19:30 +000065\x20\x20\x20\x20
66 class B(builtins.object)
67 | Data descriptors defined here:
68 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020069 | __dict__%s
Georg Brandlb533e262008-05-25 18:19:30 +000070 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020071 | __weakref__%s
Georg Brandlb533e262008-05-25 18:19:30 +000072 |\x20\x20
73 | ----------------------------------------------------------------------
74 | Data and other attributes defined here:
75 |\x20\x20
76 | NO_MEANING = 'eggs'
77
78FUNCTIONS
79 doc_func()
80 This function solves all of the world's problems:
81 hunger
82 lack of Python
83 war
84\x20\x20\x20\x20
85 nodoc_func()
86
87DATA
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000088 __xyz__ = 'X, Y and Z'
Georg Brandlb533e262008-05-25 18:19:30 +000089
90VERSION
91 1.2.3.4
92
93AUTHOR
94 Benjamin Peterson
95
96CREDITS
97 Nobody
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000098
99FILE
100 %s
Georg Brandlb533e262008-05-25 18:19:30 +0000101""".strip()
102
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200103expected_text_data_docstrings = tuple('\n | ' + s if s else ''
104 for s in expected_data_docstrings)
105
Barry Warsaw28a691b2010-04-17 00:19:56 +0000106expected_html_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +0000107<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
108<tr bgcolor="#7799ee">
109<td valign=bottom>&nbsp;<br>
110<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="test.html"><font color="#ffffff">test</font></a>.pydoc_mod</strong></big></big> (version 1.2.3.4)</font></td
111><td align=right valign=bottom
112><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:%s">%s</a>%s</font></td></tr></table>
113 <p><tt>This&nbsp;is&nbsp;a&nbsp;test&nbsp;module&nbsp;for&nbsp;test_pydoc</tt></p>
114<p>
115<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
116<tr bgcolor="#ee77aa">
117<td colspan=3 valign=bottom>&nbsp;<br>
118<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
119\x20\x20\x20\x20
120<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
121<td width="100%%"><dl>
122<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
123</font></dt><dd>
124<dl>
125<dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#A">A</a>
126</font></dt><dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#B">B</a>
127</font></dt></dl>
128</dd>
129</dl>
130 <p>
131<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
132<tr bgcolor="#ffc8d8">
133<td colspan=3 valign=bottom>&nbsp;<br>
134<font color="#000000" face="helvetica, arial"><a name="A">class <strong>A</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
135\x20\x20\x20\x20
136<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
137<td colspan=2><tt>Hello&nbsp;and&nbsp;goodbye<br>&nbsp;</tt></td></tr>
138<tr><td>&nbsp;</td>
139<td width="100%%">Methods defined here:<br>
140<dl><dt><a name="A-__init__"><strong>__init__</strong></a>()</dt><dd><tt>Wow,&nbsp;I&nbsp;have&nbsp;no&nbsp;function!</tt></dd></dl>
141
142<hr>
143Data descriptors defined here:<br>
144<dl><dt><strong>__dict__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200145<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000146</dl>
147<dl><dt><strong>__weakref__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200148<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000149</dl>
150</td></tr></table> <p>
151<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
152<tr bgcolor="#ffc8d8">
153<td colspan=3 valign=bottom>&nbsp;<br>
154<font color="#000000" face="helvetica, arial"><a name="B">class <strong>B</strong></a>(<a href="builtins.html#object">builtins.object</a>)</font></td></tr>
155\x20\x20\x20\x20
156<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
157<td width="100%%">Data descriptors defined here:<br>
158<dl><dt><strong>__dict__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200159<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000160</dl>
161<dl><dt><strong>__weakref__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200162<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000163</dl>
164<hr>
165Data and other attributes defined here:<br>
166<dl><dt><strong>NO_MEANING</strong> = 'eggs'</dl>
167
168</td></tr></table></td></tr></table><p>
169<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
170<tr bgcolor="#eeaa77">
171<td colspan=3 valign=bottom>&nbsp;<br>
172<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
173\x20\x20\x20\x20
174<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
175<td width="100%%"><dl><dt><a name="-doc_func"><strong>doc_func</strong></a>()</dt><dd><tt>This&nbsp;function&nbsp;solves&nbsp;all&nbsp;of&nbsp;the&nbsp;world's&nbsp;problems:<br>
176hunger<br>
177lack&nbsp;of&nbsp;Python<br>
178war</tt></dd></dl>
179 <dl><dt><a name="-nodoc_func"><strong>nodoc_func</strong></a>()</dt></dl>
180</td></tr></table><p>
181<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
182<tr bgcolor="#55aa55">
183<td colspan=3 valign=bottom>&nbsp;<br>
184<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
185\x20\x20\x20\x20
186<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Alexander Belopolskya47bbf52010-11-18 01:52:54 +0000187<td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'</td></tr></table><p>
Georg Brandlb533e262008-05-25 18:19:30 +0000188<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
189<tr bgcolor="#7799ee">
190<td colspan=3 valign=bottom>&nbsp;<br>
191<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
192\x20\x20\x20\x20
193<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
194<td width="100%%">Benjamin&nbsp;Peterson</td></tr></table><p>
195<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
196<tr bgcolor="#7799ee">
197<td colspan=3 valign=bottom>&nbsp;<br>
198<font color="#ffffff" face="helvetica, arial"><big><strong>Credits</strong></big></font></td></tr>
199\x20\x20\x20\x20
200<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
201<td width="100%%">Nobody</td></tr></table>
Barry Warsaw28a691b2010-04-17 00:19:56 +0000202""".strip() # ' <- emacs turd
Georg Brandlb533e262008-05-25 18:19:30 +0000203
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200204expected_html_data_docstrings = tuple(s.replace(' ', '&nbsp;')
205 for s in expected_data_docstrings)
Georg Brandlb533e262008-05-25 18:19:30 +0000206
207# output pattern for missing module
208missing_pattern = "no Python documentation found for '%s'"
209
Benjamin Peterson0289b152009-06-28 17:22:03 +0000210# output pattern for module with bad imports
Brett Cannon679ecb52013-07-04 17:51:50 -0400211badimport_pattern = "problem in %s - ImportError: No module named %r"
Benjamin Peterson0289b152009-06-28 17:22:03 +0000212
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700213expected_dynamicattribute_pattern = """
214Help on class DA in module %s:
215
216class DA(builtins.object)
217 | Data descriptors defined here:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200218 |\x20\x20
Ethan Furman3f2f1922013-10-22 07:30:24 -0700219 | __dict__%s
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200220 |\x20\x20
Ethan Furman3f2f1922013-10-22 07:30:24 -0700221 | __weakref__%s
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200222 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700223 | ham
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200224 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700225 | ----------------------------------------------------------------------
226 | Data and other attributes inherited from Meta:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200227 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700228 | ham = 'spam'
229""".strip()
230
231expected_virtualattribute_pattern1 = """
232Help on class Class in module %s:
233
234class Class(builtins.object)
235 | Data and other attributes inherited from Meta:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200236 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700237 | LIFE = 42
238""".strip()
239
240expected_virtualattribute_pattern2 = """
241Help on class Class1 in module %s:
242
243class Class1(builtins.object)
244 | Data and other attributes inherited from Meta1:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200245 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700246 | one = 1
247""".strip()
248
249expected_virtualattribute_pattern3 = """
250Help on class Class2 in module %s:
251
252class Class2(Class1)
253 | Method resolution order:
254 | Class2
255 | Class1
256 | builtins.object
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200257 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700258 | Data and other attributes inherited from Meta1:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200259 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700260 | one = 1
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200261 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700262 | ----------------------------------------------------------------------
263 | Data and other attributes inherited from Meta3:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200264 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700265 | three = 3
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200266 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700267 | ----------------------------------------------------------------------
268 | Data and other attributes inherited from Meta2:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200269 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700270 | two = 2
271""".strip()
272
273expected_missingattribute_pattern = """
274Help on class C in module %s:
275
276class C(builtins.object)
277 | Data and other attributes defined here:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200278 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700279 | here = 'present!'
280""".strip()
281
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200282def run_pydoc(module_name, *args, **env):
Georg Brandlb533e262008-05-25 18:19:30 +0000283 """
284 Runs pydoc on the specified module. Returns the stripped
285 output of pydoc.
286 """
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200287 args = args + (module_name,)
Ned Deily92a81a12011-10-06 14:19:03 -0700288 # do not write bytecode files to avoid caching errors
289 rc, out, err = assert_python_ok('-B', pydoc.__file__, *args, **env)
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200290 return out.strip()
Georg Brandlb533e262008-05-25 18:19:30 +0000291
292def get_pydoc_html(module):
293 "Returns pydoc generated output as html"
294 doc = pydoc.HTMLDoc()
295 output = doc.docmodule(module)
296 loc = doc.getdocloc(pydoc_mod) or ""
297 if loc:
298 loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
299 return output.strip(), loc
300
301def get_pydoc_text(module):
302 "Returns pydoc generated output as text"
303 doc = pydoc.TextDoc()
304 loc = doc.getdocloc(pydoc_mod) or ""
305 if loc:
306 loc = "\nMODULE DOCS\n " + loc + "\n"
307
308 output = doc.docmodule(module)
309
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000310 # clean up the extra text formatting that pydoc performs
Georg Brandlb533e262008-05-25 18:19:30 +0000311 patt = re.compile('\b.')
312 output = patt.sub('', output)
313 return output.strip(), loc
314
315def print_diffs(text1, text2):
316 "Prints unified diffs for two texts"
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000317 # XXX now obsolete, use unittest built-in support
Ezio Melottid8b509b2011-09-28 17:37:55 +0300318 lines1 = text1.splitlines(keepends=True)
319 lines2 = text2.splitlines(keepends=True)
Georg Brandlb533e262008-05-25 18:19:30 +0000320 diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected',
321 tofile='got')
322 print('\n' + ''.join(diffs))
323
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000324def get_html_title(text):
Nick Coghlanecace282010-12-03 16:08:46 +0000325 # Bit of hack, but good enough for test purposes
326 header, _, _ = text.partition("</head>")
327 _, _, title = header.partition("<title>")
328 title, _, _ = title.partition("</title>")
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000329 return title
330
Georg Brandlb533e262008-05-25 18:19:30 +0000331
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200332class PydocBaseTest(unittest.TestCase):
333
334 def _restricted_walk_packages(self, walk_packages, path=None):
335 """
336 A version of pkgutil.walk_packages() that will restrict itself to
337 a given path.
338 """
339 default_path = path or [os.path.dirname(__file__)]
340 def wrapper(path=None, prefix='', onerror=None):
341 return walk_packages(path or default_path, prefix, onerror)
342 return wrapper
343
344 @contextlib.contextmanager
345 def restrict_walk_packages(self, path=None):
346 walk_packages = pkgutil.walk_packages
347 pkgutil.walk_packages = self._restricted_walk_packages(walk_packages,
348 path)
349 try:
350 yield
351 finally:
352 pkgutil.walk_packages = walk_packages
353
354
Georg Brandld2f38572011-01-30 08:37:19 +0000355class PydocDocTest(unittest.TestCase):
Georg Brandlb533e262008-05-25 18:19:30 +0000356
R. David Murray378c0cf2010-02-24 01:46:21 +0000357 @unittest.skipIf(sys.flags.optimize >= 2,
358 "Docstrings are omitted with -O2 and above")
Brett Cannon7a540732011-02-22 03:04:06 +0000359 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
360 'trace function introduces __locals__ unexpectedly')
Georg Brandlb533e262008-05-25 18:19:30 +0000361 def test_html_doc(self):
362 result, doc_loc = get_pydoc_html(pydoc_mod)
363 mod_file = inspect.getabsfile(pydoc_mod)
Benjamin Petersonc5e94642008-06-14 23:04:46 +0000364 if sys.platform == 'win32':
365 import nturl2path
366 mod_url = nturl2path.pathname2url(mod_file)
367 else:
368 mod_url = mod_file
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200369 expected_html = expected_html_pattern % (
370 (mod_url, mod_file, doc_loc) +
371 expected_html_data_docstrings)
Georg Brandlb533e262008-05-25 18:19:30 +0000372 if result != expected_html:
373 print_diffs(expected_html, result)
374 self.fail("outputs are not equal, see diff above")
375
R. David Murray378c0cf2010-02-24 01:46:21 +0000376 @unittest.skipIf(sys.flags.optimize >= 2,
377 "Docstrings are omitted with -O2 and above")
Brett Cannon7a540732011-02-22 03:04:06 +0000378 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
379 'trace function introduces __locals__ unexpectedly')
Georg Brandlb533e262008-05-25 18:19:30 +0000380 def test_text_doc(self):
381 result, doc_loc = get_pydoc_text(pydoc_mod)
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200382 expected_text = expected_text_pattern % (
383 (doc_loc,) +
384 expected_text_data_docstrings +
385 (inspect.getabsfile(pydoc_mod),))
Georg Brandlb533e262008-05-25 18:19:30 +0000386 if result != expected_text:
387 print_diffs(expected_text, result)
388 self.fail("outputs are not equal, see diff above")
389
Brian Curtin49c284c2010-03-31 03:19:28 +0000390 def test_issue8225(self):
391 # Test issue8225 to ensure no doc link appears for xml.etree
392 result, doc_loc = get_pydoc_text(xml.etree)
393 self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
394
R David Murrayc43125a2012-04-23 13:23:57 -0400395 def test_non_str_name(self):
396 # issue14638
397 # Treat illegal (non-str) name like no name
398 class A:
399 __name__ = 42
400 class B:
401 pass
402 adoc = pydoc.render_doc(A())
403 bdoc = pydoc.render_doc(B())
404 self.assertEqual(adoc.replace("A", "B"), bdoc)
405
Georg Brandlb533e262008-05-25 18:19:30 +0000406 def test_not_here(self):
407 missing_module = "test.i_am_not_here"
408 result = str(run_pydoc(missing_module), 'ascii')
409 expected = missing_pattern % missing_module
410 self.assertEqual(expected, result,
411 "documentation for missing module found")
412
R. David Murray1f1b9d32009-05-27 20:56:59 +0000413 def test_input_strip(self):
414 missing_module = " test.i_am_not_here "
415 result = str(run_pydoc(missing_module), 'ascii')
416 expected = missing_pattern % missing_module.strip()
417 self.assertEqual(expected, result)
418
Ezio Melotti412c95a2010-02-16 23:31:04 +0000419 def test_stripid(self):
420 # test with strings, other implementations might have different repr()
421 stripid = pydoc.stripid
422 # strip the id
423 self.assertEqual(stripid('<function stripid at 0x88dcee4>'),
424 '<function stripid>')
425 self.assertEqual(stripid('<function stripid at 0x01F65390>'),
426 '<function stripid>')
427 # nothing to strip, return the same text
428 self.assertEqual(stripid('42'), '42')
429 self.assertEqual(stripid("<type 'exceptions.Exception'>"),
430 "<type 'exceptions.Exception'>")
431
Georg Brandld80d5f42010-12-03 07:47:22 +0000432 @unittest.skipIf(sys.flags.optimize >= 2,
433 'Docstrings are omitted with -O2 and above')
Brett Cannon7a540732011-02-22 03:04:06 +0000434 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
435 'trace function introduces __locals__ unexpectedly')
Georg Brandld80d5f42010-12-03 07:47:22 +0000436 def test_help_output_redirect(self):
437 # issue 940286, if output is set in Helper, then all output from
438 # Helper.help should be redirected
439 old_pattern = expected_text_pattern
440 getpager_old = pydoc.getpager
441 getpager_new = lambda: (lambda x: x)
442 self.maxDiff = None
443
444 buf = StringIO()
445 helper = pydoc.Helper(output=buf)
446 unused, doc_loc = get_pydoc_text(pydoc_mod)
447 module = "test.pydoc_mod"
448 help_header = """
449 Help on module test.pydoc_mod in test:
450
451 """.lstrip()
452 help_header = textwrap.dedent(help_header)
453 expected_help_pattern = help_header + expected_text_pattern
454
455 pydoc.getpager = getpager_new
456 try:
457 with captured_output('stdout') as output, \
458 captured_output('stderr') as err:
459 helper.help(module)
460 result = buf.getvalue().strip()
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200461 expected_text = expected_help_pattern % (
462 (doc_loc,) +
463 expected_text_data_docstrings +
464 (inspect.getabsfile(pydoc_mod),))
Georg Brandld80d5f42010-12-03 07:47:22 +0000465 self.assertEqual('', output.getvalue())
466 self.assertEqual('', err.getvalue())
467 self.assertEqual(expected_text, result)
468 finally:
469 pydoc.getpager = getpager_old
470
Raymond Hettinger1103d052011-03-25 14:15:24 -0700471 def test_namedtuple_public_underscore(self):
472 NT = namedtuple('NT', ['abc', 'def'], rename=True)
473 with captured_stdout() as help_io:
Terry Jan Reedy5c811642013-11-04 21:43:26 -0500474 pydoc.help(NT)
Raymond Hettinger1103d052011-03-25 14:15:24 -0700475 helptext = help_io.getvalue()
476 self.assertIn('_1', helptext)
477 self.assertIn('_replace', helptext)
478 self.assertIn('_asdict', helptext)
479
Victor Stinnere6c910e2011-06-30 15:55:43 +0200480 def test_synopsis(self):
481 self.addCleanup(unlink, TESTFN)
482 for encoding in ('ISO-8859-1', 'UTF-8'):
483 with open(TESTFN, 'w', encoding=encoding) as script:
484 if encoding != 'UTF-8':
485 print('#coding: {}'.format(encoding), file=script)
486 print('"""line 1: h\xe9', file=script)
487 print('line 2: hi"""', file=script)
488 synopsis = pydoc.synopsis(TESTFN, {})
489 self.assertEqual(synopsis, 'line 1: h\xe9')
490
Eric Snowaed5b222014-01-04 20:38:11 -0700491 def test_synopsis_sourceless(self):
492 expected = os.__doc__.splitlines()[0]
493 filename = os.__cached__
494 synopsis = pydoc.synopsis(filename)
495
496 self.assertEqual(synopsis, expected)
497
R David Murray455f2962013-03-19 00:00:33 -0400498 def test_splitdoc_with_description(self):
499 example_string = "I Am A Doc\n\n\nHere is my description"
500 self.assertEqual(pydoc.splitdoc(example_string),
501 ('I Am A Doc', '\nHere is my description'))
502
503 def test_is_object_or_method(self):
504 doc = pydoc.Doc()
505 # Bound Method
506 self.assertTrue(pydoc._is_some_method(doc.fail))
507 # Method Descriptor
508 self.assertTrue(pydoc._is_some_method(int.__add__))
509 # String
510 self.assertFalse(pydoc._is_some_method("I am not a method"))
511
512 def test_is_package_when_not_package(self):
513 with test.support.temp_cwd() as test_dir:
514 self.assertFalse(pydoc.ispackage(test_dir))
515
516 def test_is_package_when_is_package(self):
517 with test.support.temp_cwd() as test_dir:
518 init_path = os.path.join(test_dir, '__init__.py')
519 open(init_path, 'w').close()
520 self.assertTrue(pydoc.ispackage(test_dir))
521 os.remove(init_path)
522
R David Murrayac0cea52013-03-19 02:47:44 -0400523 def test_allmethods(self):
524 # issue 17476: allmethods was no longer returning unbound methods.
525 # This test is a bit fragile in the face of changes to object and type,
526 # but I can't think of a better way to do it without duplicating the
527 # logic of the function under test.
528
529 class TestClass(object):
530 def method_returning_true(self):
531 return True
532
533 # What we expect to get back: everything on object...
534 expected = dict(vars(object))
535 # ...plus our unbound method...
536 expected['method_returning_true'] = TestClass.method_returning_true
537 # ...but not the non-methods on object.
538 del expected['__doc__']
539 del expected['__class__']
540 # inspect resolves descriptors on type into methods, but vars doesn't,
541 # so we need to update __subclasshook__.
542 expected['__subclasshook__'] = TestClass.__subclasshook__
543
544 methods = pydoc.allmethods(TestClass)
545 self.assertDictEqual(methods, expected)
546
Georg Brandlb533e262008-05-25 18:19:30 +0000547
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200548class PydocImportTest(PydocBaseTest):
Ned Deily92a81a12011-10-06 14:19:03 -0700549
550 def setUp(self):
551 self.test_dir = os.mkdir(TESTFN)
552 self.addCleanup(rmtree, TESTFN)
553
554 def test_badimport(self):
555 # This tests the fix for issue 5230, where if pydoc found the module
556 # but the module had an internal import error pydoc would report no doc
557 # found.
558 modname = 'testmod_xyzzy'
559 testpairs = (
560 ('i_am_not_here', 'i_am_not_here'),
Brett Cannonfd074152012-04-14 14:10:13 -0400561 ('test.i_am_not_here_either', 'test.i_am_not_here_either'),
562 ('test.i_am_not_here.neither_am_i', 'test.i_am_not_here'),
563 ('i_am_not_here.{}'.format(modname), 'i_am_not_here'),
564 ('test.{}'.format(modname), 'test.{}'.format(modname)),
Ned Deily92a81a12011-10-06 14:19:03 -0700565 )
566
567 sourcefn = os.path.join(TESTFN, modname) + os.extsep + "py"
568 for importstring, expectedinmsg in testpairs:
569 with open(sourcefn, 'w') as f:
570 f.write("import {}\n".format(importstring))
571 result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
572 expected = badimport_pattern % (modname, expectedinmsg)
573 self.assertEqual(expected, result)
574
575 def test_apropos_with_bad_package(self):
576 # Issue 7425 - pydoc -k failed when bad package on path
577 pkgdir = os.path.join(TESTFN, "syntaxerr")
578 os.mkdir(pkgdir)
579 badsyntax = os.path.join(pkgdir, "__init__") + os.extsep + "py"
580 with open(badsyntax, 'w') as f:
581 f.write("invalid python syntax = $1\n")
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200582 with self.restrict_walk_packages(path=[TESTFN]):
583 with captured_stdout() as out:
584 with captured_stderr() as err:
585 pydoc.apropos('xyzzy')
586 # No result, no error
587 self.assertEqual(out.getvalue(), '')
588 self.assertEqual(err.getvalue(), '')
589 # The package name is still matched
590 with captured_stdout() as out:
591 with captured_stderr() as err:
592 pydoc.apropos('syntaxerr')
593 self.assertEqual(out.getvalue().strip(), 'syntaxerr')
594 self.assertEqual(err.getvalue(), '')
Ned Deily92a81a12011-10-06 14:19:03 -0700595
596 def test_apropos_with_unreadable_dir(self):
597 # Issue 7367 - pydoc -k failed when unreadable dir on path
598 self.unreadable_dir = os.path.join(TESTFN, "unreadable")
599 os.mkdir(self.unreadable_dir, 0)
600 self.addCleanup(os.rmdir, self.unreadable_dir)
601 # Note, on Windows the directory appears to be still
602 # readable so this is not really testing the issue there
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200603 with self.restrict_walk_packages(path=[TESTFN]):
604 with captured_stdout() as out:
605 with captured_stderr() as err:
606 pydoc.apropos('SOMEKEY')
607 # No result, no error
608 self.assertEqual(out.getvalue(), '')
609 self.assertEqual(err.getvalue(), '')
Ned Deily92a81a12011-10-06 14:19:03 -0700610
Eric Snowaed5b222014-01-04 20:38:11 -0700611 def test_modules(self):
612 # See Helper.listmodules().
613 num_header_lines = 2
614 num_module_lines_min = 5 # Playing it safe.
615 num_footer_lines = 3
616 expected = num_header_lines + num_module_lines_min + num_footer_lines
617
618 output = StringIO()
619 helper = pydoc.Helper(output=output)
620 helper('modules')
621 result = output.getvalue().strip()
622 num_lines = len(result.splitlines())
623
624 self.assertGreaterEqual(num_lines, expected)
625
626 def test_modules_search(self):
627 # See Helper.listmodules().
628 expected = 'pydoc - '
629
630 output = StringIO()
631 helper = pydoc.Helper(output=output)
632 with captured_stdout() as help_io:
633 helper('modules pydoc')
634 result = help_io.getvalue()
635
636 self.assertIn(expected, result)
637
Eric Snow5ea97502014-01-04 23:04:27 -0700638 @unittest.skip('some buildbots are not cooperating (#20123)')
Eric Snowaed5b222014-01-04 20:38:11 -0700639 def test_modules_search_builtin(self):
Eric Snow5ea97502014-01-04 23:04:27 -0700640 expected = 'gc - '
Eric Snowaed5b222014-01-04 20:38:11 -0700641
642 output = StringIO()
643 helper = pydoc.Helper(output=output)
644 with captured_stdout() as help_io:
Eric Snow5ea97502014-01-04 23:04:27 -0700645 helper('modules garbage')
Eric Snowaed5b222014-01-04 20:38:11 -0700646 result = help_io.getvalue()
647
648 self.assertTrue(result.startswith(expected))
649
650 def test_importfile(self):
651 loaded_pydoc = pydoc.importfile(pydoc.__file__)
652
Eric Snow3a62d142014-01-06 20:42:59 -0700653 self.assertIsNot(loaded_pydoc, pydoc)
Eric Snowaed5b222014-01-04 20:38:11 -0700654 self.assertEqual(loaded_pydoc.__name__, 'pydoc')
655 self.assertEqual(loaded_pydoc.__file__, pydoc.__file__)
Eric Snow3a62d142014-01-06 20:42:59 -0700656 self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
Eric Snowaed5b222014-01-04 20:38:11 -0700657
Ned Deily92a81a12011-10-06 14:19:03 -0700658
Georg Brandlb533e262008-05-25 18:19:30 +0000659class TestDescriptions(unittest.TestCase):
660
661 def test_module(self):
662 # Check that pydocfodder module can be described
663 from test import pydocfodder
664 doc = pydoc.render_doc(pydocfodder)
Benjamin Peterson577473f2010-01-19 00:09:57 +0000665 self.assertIn("pydocfodder", doc)
Georg Brandlb533e262008-05-25 18:19:30 +0000666
Georg Brandlb533e262008-05-25 18:19:30 +0000667 def test_class(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000668 class C: "New-style class"
Georg Brandlb533e262008-05-25 18:19:30 +0000669 c = C()
670
671 self.assertEqual(pydoc.describe(C), 'class C')
672 self.assertEqual(pydoc.describe(c), 'C')
673 expected = 'C in module %s object' % __name__
Benjamin Peterson577473f2010-01-19 00:09:57 +0000674 self.assertIn(expected, pydoc.render_doc(c))
Georg Brandlb533e262008-05-25 18:19:30 +0000675
Éric Araujoe64e51b2011-07-29 17:03:55 +0200676 def test_builtin(self):
677 for name in ('str', 'str.translate', 'builtins.str',
678 'builtins.str.translate'):
679 # test low-level function
680 self.assertIsNotNone(pydoc.locate(name))
681 # test high-level function
682 try:
683 pydoc.render_doc(name)
684 except ImportError:
685 self.fail('finding the doc of {!r} failed'.format(o))
686
687 for name in ('notbuiltins', 'strrr', 'strr.translate',
688 'str.trrrranslate', 'builtins.strrr',
689 'builtins.str.trrranslate'):
690 self.assertIsNone(pydoc.locate(name))
691 self.assertRaises(ImportError, pydoc.render_doc, name)
692
Larry Hastings13da6a12014-02-20 23:34:46 -0800693 @staticmethod
694 def _get_summary_line(o):
695 text = pydoc.plain(pydoc.render_doc(o))
696 lines = text.split('\n')
697 assert len(lines) >= 2
698 return lines[2]
699
700 # these should include "self"
701 def test_unbound_python_method(self):
702 self.assertEqual(self._get_summary_line(textwrap.TextWrapper.wrap),
703 "wrap(self, text)")
704
Stefan Krah5de32782014-01-18 23:18:39 +0100705 @requires_docstrings
Larry Hastings13da6a12014-02-20 23:34:46 -0800706 def test_unbound_builtin_method(self):
707 self.assertEqual(self._get_summary_line(_pickle.Pickler.dump),
708 "dump(self, obj, /)")
709
710 # these no longer include "self"
711 def test_bound_python_method(self):
712 t = textwrap.TextWrapper()
713 self.assertEqual(self._get_summary_line(t.wrap),
714 "wrap(text) method of textwrap.TextWrapper instance")
715
716 @requires_docstrings
717 def test_bound_builtin_method(self):
718 s = StringIO()
719 p = _pickle.Pickler(s)
720 self.assertEqual(self._get_summary_line(p.dump),
721 "dump(obj, /) method of _pickle.Pickler instance")
722
723 # this should *never* include self!
724 @requires_docstrings
725 def test_module_level_callable(self):
726 self.assertEqual(self._get_summary_line(os.stat),
727 "stat(path, *, dir_fd=None, follow_symlinks=True)")
Larry Hastings1abd7082014-01-16 14:15:03 -0800728
Georg Brandlb533e262008-05-25 18:19:30 +0000729
Victor Stinner62a68f22011-05-20 02:29:13 +0200730@unittest.skipUnless(threading, 'Threading required for this test.')
Georg Brandld2f38572011-01-30 08:37:19 +0000731class PydocServerTest(unittest.TestCase):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000732 """Tests for pydoc._start_server"""
733
734 def test_server(self):
735
736 # Minimal test that starts the server, then stops it.
737 def my_url_handler(url, content_type):
738 text = 'the URL sent was: (%s, %s)' % (url, content_type)
739 return text
740
741 serverthread = pydoc._start_server(my_url_handler, port=0)
742 starttime = time.time()
743 timeout = 1 #seconds
744
745 while serverthread.serving:
746 time.sleep(.01)
747 if serverthread.serving and time.time() - starttime > timeout:
748 serverthread.stop()
749 break
750
751 self.assertEqual(serverthread.error, None)
752
753
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200754class PydocUrlHandlerTest(PydocBaseTest):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000755 """Tests for pydoc._url_handler"""
756
757 def test_content_type_err(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000758 f = pydoc._url_handler
Georg Brandld2f38572011-01-30 08:37:19 +0000759 self.assertRaises(TypeError, f, 'A', '')
760 self.assertRaises(TypeError, f, 'B', 'foobar')
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000761
762 def test_url_requests(self):
763 # Test for the correct title in the html pages returned.
764 # This tests the different parts of the URL handler without
765 # getting too picky about the exact html.
766 requests = [
Georg Brandld2f38572011-01-30 08:37:19 +0000767 ("", "Pydoc: Index of Modules"),
768 ("get?key=", "Pydoc: Index of Modules"),
769 ("index", "Pydoc: Index of Modules"),
770 ("topics", "Pydoc: Topics"),
771 ("keywords", "Pydoc: Keywords"),
772 ("pydoc", "Pydoc: module pydoc"),
773 ("get?key=pydoc", "Pydoc: module pydoc"),
774 ("search?key=pydoc", "Pydoc: Search Results"),
775 ("topic?key=def", "Pydoc: KEYWORD def"),
776 ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
777 ("foobar", "Pydoc: Error - foobar"),
778 ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000779 ]
780
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200781 with self.restrict_walk_packages():
782 for url, title in requests:
783 text = pydoc._url_handler(url, "text/html")
784 result = get_html_title(text)
785 self.assertEqual(result, title, text)
786
787 path = string.__file__
788 title = "Pydoc: getfile " + path
789 url = "getfile?key=" + path
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000790 text = pydoc._url_handler(url, "text/html")
791 result = get_html_title(text)
792 self.assertEqual(result, title)
793
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000794
Ezio Melottib185a042011-04-28 07:42:55 +0300795class TestHelper(unittest.TestCase):
796 def test_keywords(self):
797 self.assertEqual(sorted(pydoc.Helper.keywords),
798 sorted(keyword.kwlist))
799
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700800class PydocWithMetaClasses(unittest.TestCase):
Ethan Furman3f2f1922013-10-22 07:30:24 -0700801 @unittest.skipIf(sys.flags.optimize >= 2,
802 "Docstrings are omitted with -O2 and above")
803 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
804 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700805 def test_DynamicClassAttribute(self):
806 class Meta(type):
807 def __getattr__(self, name):
808 if name == 'ham':
809 return 'spam'
810 return super().__getattr__(name)
811 class DA(metaclass=Meta):
812 @types.DynamicClassAttribute
813 def ham(self):
814 return 'eggs'
Ethan Furman3f2f1922013-10-22 07:30:24 -0700815 expected_text_data_docstrings = tuple('\n | ' + s if s else ''
816 for s in expected_data_docstrings)
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700817 output = StringIO()
818 helper = pydoc.Helper(output=output)
819 helper(DA)
Ethan Furman3f2f1922013-10-22 07:30:24 -0700820 expected_text = expected_dynamicattribute_pattern % (
821 (__name__,) + expected_text_data_docstrings[:2])
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700822 result = output.getvalue().strip()
823 if result != expected_text:
824 print_diffs(expected_text, result)
825 self.fail("outputs are not equal, see diff above")
826
Ethan Furman3f2f1922013-10-22 07:30:24 -0700827 @unittest.skipIf(sys.flags.optimize >= 2,
828 "Docstrings are omitted with -O2 and above")
829 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
830 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700831 def test_virtualClassAttributeWithOneMeta(self):
832 class Meta(type):
833 def __dir__(cls):
834 return ['__class__', '__module__', '__name__', 'LIFE']
835 def __getattr__(self, name):
836 if name =='LIFE':
837 return 42
838 return super().__getattr(name)
839 class Class(metaclass=Meta):
840 pass
841 output = StringIO()
842 helper = pydoc.Helper(output=output)
843 helper(Class)
844 expected_text = expected_virtualattribute_pattern1 % __name__
845 result = output.getvalue().strip()
846 if result != expected_text:
847 print_diffs(expected_text, result)
848 self.fail("outputs are not equal, see diff above")
849
Ethan Furman3f2f1922013-10-22 07:30:24 -0700850 @unittest.skipIf(sys.flags.optimize >= 2,
851 "Docstrings are omitted with -O2 and above")
852 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
853 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700854 def test_virtualClassAttributeWithTwoMeta(self):
855 class Meta1(type):
856 def __dir__(cls):
857 return ['__class__', '__module__', '__name__', 'one']
858 def __getattr__(self, name):
859 if name =='one':
860 return 1
861 return super().__getattr__(name)
862 class Meta2(type):
863 def __dir__(cls):
864 return ['__class__', '__module__', '__name__', 'two']
865 def __getattr__(self, name):
866 if name =='two':
867 return 2
868 return super().__getattr__(name)
869 class Meta3(Meta1, Meta2):
870 def __dir__(cls):
871 return list(sorted(set(
872 ['__class__', '__module__', '__name__', 'three'] +
873 Meta1.__dir__(cls) + Meta2.__dir__(cls))))
874 def __getattr__(self, name):
875 if name =='three':
876 return 3
877 return super().__getattr__(name)
878 class Class1(metaclass=Meta1):
879 pass
880 class Class2(Class1, metaclass=Meta3):
881 pass
882 fail1 = fail2 = False
883 output = StringIO()
884 helper = pydoc.Helper(output=output)
885 helper(Class1)
886 expected_text1 = expected_virtualattribute_pattern2 % __name__
887 result1 = output.getvalue().strip()
888 if result1 != expected_text1:
889 print_diffs(expected_text1, result1)
890 fail1 = True
891 output = StringIO()
892 helper = pydoc.Helper(output=output)
893 helper(Class2)
894 expected_text2 = expected_virtualattribute_pattern3 % __name__
895 result2 = output.getvalue().strip()
896 if result2 != expected_text2:
897 print_diffs(expected_text2, result2)
898 fail2 = True
899 if fail1 or fail2:
900 self.fail("outputs are not equal, see diff above")
901
Ethan Furman3f2f1922013-10-22 07:30:24 -0700902 @unittest.skipIf(sys.flags.optimize >= 2,
903 "Docstrings are omitted with -O2 and above")
904 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
905 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700906 def test_buggy_dir(self):
907 class M(type):
908 def __dir__(cls):
909 return ['__class__', '__name__', 'missing', 'here']
910 class C(metaclass=M):
911 here = 'present!'
912 output = StringIO()
913 helper = pydoc.Helper(output=output)
914 helper(C)
915 expected_text = expected_missingattribute_pattern % __name__
916 result = output.getvalue().strip()
917 if result != expected_text:
918 print_diffs(expected_text, result)
919 self.fail("outputs are not equal, see diff above")
920
Eric Snowaed5b222014-01-04 20:38:11 -0700921
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200922@reap_threads
Georg Brandlb533e262008-05-25 18:19:30 +0000923def test_main():
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200924 try:
925 test.support.run_unittest(PydocDocTest,
Ned Deily92a81a12011-10-06 14:19:03 -0700926 PydocImportTest,
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200927 TestDescriptions,
928 PydocServerTest,
929 PydocUrlHandlerTest,
930 TestHelper,
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700931 PydocWithMetaClasses,
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200932 )
933 finally:
934 reap_children()
Georg Brandlb533e262008-05-25 18:19:30 +0000935
936if __name__ == "__main__":
937 test_main()