blob: 9909b9ae535387c7d3ed5c8848cce326b839ae56 [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
Antoine Pitrou916fc7b2013-05-19 15:44:54 +02009import pkgutil
Nick Coghlan7bb30b72010-12-03 09:29:11 +000010import re
11import string
Georg Brandlb533e262008-05-25 18:19:30 +000012import test.support
Nick Coghlan7bb30b72010-12-03 09:29:11 +000013import time
Ethan Furmanb0c84cd2013-10-20 22:37:39 -070014import types
Nick Coghlan7bb30b72010-12-03 09:29:11 +000015import unittest
Brian Curtin49c284c2010-03-31 03:19:28 +000016import xml.etree
Georg Brandld80d5f42010-12-03 07:47:22 +000017import textwrap
18from io import StringIO
Raymond Hettinger1103d052011-03-25 14:15:24 -070019from collections import namedtuple
Antoine Pitrouf7f54752011-07-15 22:42:12 +020020from test.script_helper import assert_python_ok
Antoine Pitroua6e81a22011-07-15 22:32:25 +020021from test.support import (
Ned Deily92a81a12011-10-06 14:19:03 -070022 TESTFN, rmtree,
Antoine Pitrou916fc7b2013-05-19 15:44:54 +020023 reap_children, reap_threads, captured_output, captured_stdout,
Stefan Krah5de32782014-01-18 23:18:39 +010024 captured_stderr, unlink, requires_docstrings
Antoine Pitroua6e81a22011-07-15 22:32:25 +020025)
Georg Brandlb533e262008-05-25 18:19:30 +000026from test import pydoc_mod
27
Victor Stinner62a68f22011-05-20 02:29:13 +020028try:
29 import threading
30except ImportError:
31 threading = None
32
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020033if test.support.HAVE_DOCSTRINGS:
34 expected_data_docstrings = (
35 'dictionary for instance variables (if defined)',
36 'list of weak references to the object (if defined)',
37 ) * 2
38else:
39 expected_data_docstrings = ('', '', '', '')
40
Barry Warsaw28a691b2010-04-17 00:19:56 +000041expected_text_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +000042NAME
43 test.pydoc_mod - This is a test module for test_pydoc
Georg Brandlb533e262008-05-25 18:19:30 +000044%s
45CLASSES
46 builtins.object
47 A
48 B
49\x20\x20\x20\x20
50 class A(builtins.object)
51 | Hello and goodbye
52 |\x20\x20
53 | Methods defined here:
54 |\x20\x20
55 | __init__()
56 | Wow, I have no function!
57 |\x20\x20
58 | ----------------------------------------------------------------------
59 | Data descriptors defined here:
60 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020061 | __dict__%s
Georg Brandlb533e262008-05-25 18:19:30 +000062 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020063 | __weakref__%s
Georg Brandlb533e262008-05-25 18:19:30 +000064\x20\x20\x20\x20
65 class B(builtins.object)
66 | Data descriptors defined here:
67 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020068 | __dict__%s
Georg Brandlb533e262008-05-25 18:19:30 +000069 |\x20\x20
Serhiy Storchaka9d0add02013-01-27 19:47:45 +020070 | __weakref__%s
Georg Brandlb533e262008-05-25 18:19:30 +000071 |\x20\x20
72 | ----------------------------------------------------------------------
73 | Data and other attributes defined here:
74 |\x20\x20
75 | NO_MEANING = 'eggs'
76
77FUNCTIONS
78 doc_func()
79 This function solves all of the world's problems:
80 hunger
81 lack of Python
82 war
83\x20\x20\x20\x20
84 nodoc_func()
85
86DATA
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000087 __xyz__ = 'X, Y and Z'
Georg Brandlb533e262008-05-25 18:19:30 +000088
89VERSION
90 1.2.3.4
91
92AUTHOR
93 Benjamin Peterson
94
95CREDITS
96 Nobody
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000097
98FILE
99 %s
Georg Brandlb533e262008-05-25 18:19:30 +0000100""".strip()
101
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200102expected_text_data_docstrings = tuple('\n | ' + s if s else ''
103 for s in expected_data_docstrings)
104
Barry Warsaw28a691b2010-04-17 00:19:56 +0000105expected_html_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +0000106<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
107<tr bgcolor="#7799ee">
108<td valign=bottom>&nbsp;<br>
109<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
110><td align=right valign=bottom
111><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:%s">%s</a>%s</font></td></tr></table>
112 <p><tt>This&nbsp;is&nbsp;a&nbsp;test&nbsp;module&nbsp;for&nbsp;test_pydoc</tt></p>
113<p>
114<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
115<tr bgcolor="#ee77aa">
116<td colspan=3 valign=bottom>&nbsp;<br>
117<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
118\x20\x20\x20\x20
119<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
120<td width="100%%"><dl>
121<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
122</font></dt><dd>
123<dl>
124<dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#A">A</a>
125</font></dt><dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#B">B</a>
126</font></dt></dl>
127</dd>
128</dl>
129 <p>
130<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
131<tr bgcolor="#ffc8d8">
132<td colspan=3 valign=bottom>&nbsp;<br>
133<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>
134\x20\x20\x20\x20
135<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
136<td colspan=2><tt>Hello&nbsp;and&nbsp;goodbye<br>&nbsp;</tt></td></tr>
137<tr><td>&nbsp;</td>
138<td width="100%%">Methods defined here:<br>
139<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>
140
141<hr>
142Data descriptors defined here:<br>
143<dl><dt><strong>__dict__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200144<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000145</dl>
146<dl><dt><strong>__weakref__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200147<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000148</dl>
149</td></tr></table> <p>
150<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
151<tr bgcolor="#ffc8d8">
152<td colspan=3 valign=bottom>&nbsp;<br>
153<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>
154\x20\x20\x20\x20
155<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
156<td width="100%%">Data descriptors defined here:<br>
157<dl><dt><strong>__dict__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200158<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000159</dl>
160<dl><dt><strong>__weakref__</strong></dt>
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200161<dd><tt>%s</tt></dd>
Georg Brandlb533e262008-05-25 18:19:30 +0000162</dl>
163<hr>
164Data and other attributes defined here:<br>
165<dl><dt><strong>NO_MEANING</strong> = 'eggs'</dl>
166
167</td></tr></table></td></tr></table><p>
168<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
169<tr bgcolor="#eeaa77">
170<td colspan=3 valign=bottom>&nbsp;<br>
171<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
172\x20\x20\x20\x20
173<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
174<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>
175hunger<br>
176lack&nbsp;of&nbsp;Python<br>
177war</tt></dd></dl>
178 <dl><dt><a name="-nodoc_func"><strong>nodoc_func</strong></a>()</dt></dl>
179</td></tr></table><p>
180<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
181<tr bgcolor="#55aa55">
182<td colspan=3 valign=bottom>&nbsp;<br>
183<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
184\x20\x20\x20\x20
185<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Alexander Belopolskya47bbf52010-11-18 01:52:54 +0000186<td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'</td></tr></table><p>
Georg Brandlb533e262008-05-25 18:19:30 +0000187<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
188<tr bgcolor="#7799ee">
189<td colspan=3 valign=bottom>&nbsp;<br>
190<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
191\x20\x20\x20\x20
192<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
193<td width="100%%">Benjamin&nbsp;Peterson</td></tr></table><p>
194<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
195<tr bgcolor="#7799ee">
196<td colspan=3 valign=bottom>&nbsp;<br>
197<font color="#ffffff" face="helvetica, arial"><big><strong>Credits</strong></big></font></td></tr>
198\x20\x20\x20\x20
199<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
200<td width="100%%">Nobody</td></tr></table>
Barry Warsaw28a691b2010-04-17 00:19:56 +0000201""".strip() # ' <- emacs turd
Georg Brandlb533e262008-05-25 18:19:30 +0000202
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200203expected_html_data_docstrings = tuple(s.replace(' ', '&nbsp;')
204 for s in expected_data_docstrings)
Georg Brandlb533e262008-05-25 18:19:30 +0000205
206# output pattern for missing module
207missing_pattern = "no Python documentation found for '%s'"
208
Benjamin Peterson0289b152009-06-28 17:22:03 +0000209# output pattern for module with bad imports
Brett Cannon679ecb52013-07-04 17:51:50 -0400210badimport_pattern = "problem in %s - ImportError: No module named %r"
Benjamin Peterson0289b152009-06-28 17:22:03 +0000211
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700212expected_dynamicattribute_pattern = """
213Help on class DA in module %s:
214
215class DA(builtins.object)
216 | Data descriptors defined here:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200217 |\x20\x20
Ethan Furman3f2f1922013-10-22 07:30:24 -0700218 | __dict__%s
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200219 |\x20\x20
Ethan Furman3f2f1922013-10-22 07:30:24 -0700220 | __weakref__%s
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200221 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700222 | ham
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200223 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700224 | ----------------------------------------------------------------------
225 | Data and other attributes inherited from Meta:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200226 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700227 | ham = 'spam'
228""".strip()
229
230expected_virtualattribute_pattern1 = """
231Help on class Class in module %s:
232
233class Class(builtins.object)
234 | Data and other attributes inherited from Meta:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200235 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700236 | LIFE = 42
237""".strip()
238
239expected_virtualattribute_pattern2 = """
240Help on class Class1 in module %s:
241
242class Class1(builtins.object)
243 | Data and other attributes inherited from Meta1:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200244 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700245 | one = 1
246""".strip()
247
248expected_virtualattribute_pattern3 = """
249Help on class Class2 in module %s:
250
251class Class2(Class1)
252 | Method resolution order:
253 | Class2
254 | Class1
255 | builtins.object
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200256 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700257 | Data and other attributes inherited from Meta1:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200258 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700259 | one = 1
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200260 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700261 | ----------------------------------------------------------------------
262 | Data and other attributes inherited from Meta3:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200263 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700264 | three = 3
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200265 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700266 | ----------------------------------------------------------------------
267 | Data and other attributes inherited from Meta2:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200268 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700269 | two = 2
270""".strip()
271
272expected_missingattribute_pattern = """
273Help on class C in module %s:
274
275class C(builtins.object)
276 | Data and other attributes defined here:
Charles-François Natali1a82f7e2013-10-21 14:46:34 +0200277 |\x20\x20
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700278 | here = 'present!'
279""".strip()
280
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200281def run_pydoc(module_name, *args, **env):
Georg Brandlb533e262008-05-25 18:19:30 +0000282 """
283 Runs pydoc on the specified module. Returns the stripped
284 output of pydoc.
285 """
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200286 args = args + (module_name,)
Ned Deily92a81a12011-10-06 14:19:03 -0700287 # do not write bytecode files to avoid caching errors
288 rc, out, err = assert_python_ok('-B', pydoc.__file__, *args, **env)
Antoine Pitrouf7f54752011-07-15 22:42:12 +0200289 return out.strip()
Georg Brandlb533e262008-05-25 18:19:30 +0000290
291def get_pydoc_html(module):
292 "Returns pydoc generated output as html"
293 doc = pydoc.HTMLDoc()
294 output = doc.docmodule(module)
295 loc = doc.getdocloc(pydoc_mod) or ""
296 if loc:
297 loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
298 return output.strip(), loc
299
300def get_pydoc_text(module):
301 "Returns pydoc generated output as text"
302 doc = pydoc.TextDoc()
303 loc = doc.getdocloc(pydoc_mod) or ""
304 if loc:
305 loc = "\nMODULE DOCS\n " + loc + "\n"
306
307 output = doc.docmodule(module)
308
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000309 # clean up the extra text formatting that pydoc performs
Georg Brandlb533e262008-05-25 18:19:30 +0000310 patt = re.compile('\b.')
311 output = patt.sub('', output)
312 return output.strip(), loc
313
314def print_diffs(text1, text2):
315 "Prints unified diffs for two texts"
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000316 # XXX now obsolete, use unittest built-in support
Ezio Melottid8b509b2011-09-28 17:37:55 +0300317 lines1 = text1.splitlines(keepends=True)
318 lines2 = text2.splitlines(keepends=True)
Georg Brandlb533e262008-05-25 18:19:30 +0000319 diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected',
320 tofile='got')
321 print('\n' + ''.join(diffs))
322
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000323def get_html_title(text):
Nick Coghlanecace282010-12-03 16:08:46 +0000324 # Bit of hack, but good enough for test purposes
325 header, _, _ = text.partition("</head>")
326 _, _, title = header.partition("<title>")
327 title, _, _ = title.partition("</title>")
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000328 return title
329
Georg Brandlb533e262008-05-25 18:19:30 +0000330
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200331class PydocBaseTest(unittest.TestCase):
332
333 def _restricted_walk_packages(self, walk_packages, path=None):
334 """
335 A version of pkgutil.walk_packages() that will restrict itself to
336 a given path.
337 """
338 default_path = path or [os.path.dirname(__file__)]
339 def wrapper(path=None, prefix='', onerror=None):
340 return walk_packages(path or default_path, prefix, onerror)
341 return wrapper
342
343 @contextlib.contextmanager
344 def restrict_walk_packages(self, path=None):
345 walk_packages = pkgutil.walk_packages
346 pkgutil.walk_packages = self._restricted_walk_packages(walk_packages,
347 path)
348 try:
349 yield
350 finally:
351 pkgutil.walk_packages = walk_packages
352
353
Georg Brandld2f38572011-01-30 08:37:19 +0000354class PydocDocTest(unittest.TestCase):
Georg Brandlb533e262008-05-25 18:19:30 +0000355
R. David Murray378c0cf2010-02-24 01:46:21 +0000356 @unittest.skipIf(sys.flags.optimize >= 2,
357 "Docstrings are omitted with -O2 and above")
Brett Cannon7a540732011-02-22 03:04:06 +0000358 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
359 'trace function introduces __locals__ unexpectedly')
Georg Brandlb533e262008-05-25 18:19:30 +0000360 def test_html_doc(self):
361 result, doc_loc = get_pydoc_html(pydoc_mod)
362 mod_file = inspect.getabsfile(pydoc_mod)
Benjamin Petersonc5e94642008-06-14 23:04:46 +0000363 if sys.platform == 'win32':
364 import nturl2path
365 mod_url = nturl2path.pathname2url(mod_file)
366 else:
367 mod_url = mod_file
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200368 expected_html = expected_html_pattern % (
369 (mod_url, mod_file, doc_loc) +
370 expected_html_data_docstrings)
Georg Brandlb533e262008-05-25 18:19:30 +0000371 if result != expected_html:
372 print_diffs(expected_html, result)
373 self.fail("outputs are not equal, see diff above")
374
R. David Murray378c0cf2010-02-24 01:46:21 +0000375 @unittest.skipIf(sys.flags.optimize >= 2,
376 "Docstrings are omitted with -O2 and above")
Brett Cannon7a540732011-02-22 03:04:06 +0000377 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
378 'trace function introduces __locals__ unexpectedly')
Georg Brandlb533e262008-05-25 18:19:30 +0000379 def test_text_doc(self):
380 result, doc_loc = get_pydoc_text(pydoc_mod)
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200381 expected_text = expected_text_pattern % (
382 (doc_loc,) +
383 expected_text_data_docstrings +
384 (inspect.getabsfile(pydoc_mod),))
Georg Brandlb533e262008-05-25 18:19:30 +0000385 if result != expected_text:
386 print_diffs(expected_text, result)
387 self.fail("outputs are not equal, see diff above")
388
Serhiy Storchaka056eb022014-02-19 23:05:12 +0200389 def test_text_enum_member_with_value_zero(self):
390 # Test issue #20654 to ensure enum member with value 0 can be
391 # displayed. It used to throw KeyError: 'zero'.
392 import enum
393 class BinaryInteger(enum.IntEnum):
394 zero = 0
395 one = 1
396 doc = pydoc.render_doc(BinaryInteger)
397 self.assertIn('<BinaryInteger.zero: 0>', doc)
398
Brian Curtin49c284c2010-03-31 03:19:28 +0000399 def test_issue8225(self):
400 # Test issue8225 to ensure no doc link appears for xml.etree
401 result, doc_loc = get_pydoc_text(xml.etree)
402 self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
403
R David Murrayc43125a2012-04-23 13:23:57 -0400404 def test_non_str_name(self):
405 # issue14638
406 # Treat illegal (non-str) name like no name
407 class A:
408 __name__ = 42
409 class B:
410 pass
411 adoc = pydoc.render_doc(A())
412 bdoc = pydoc.render_doc(B())
413 self.assertEqual(adoc.replace("A", "B"), bdoc)
414
Georg Brandlb533e262008-05-25 18:19:30 +0000415 def test_not_here(self):
416 missing_module = "test.i_am_not_here"
417 result = str(run_pydoc(missing_module), 'ascii')
418 expected = missing_pattern % missing_module
419 self.assertEqual(expected, result,
420 "documentation for missing module found")
421
R. David Murray1f1b9d32009-05-27 20:56:59 +0000422 def test_input_strip(self):
423 missing_module = " test.i_am_not_here "
424 result = str(run_pydoc(missing_module), 'ascii')
425 expected = missing_pattern % missing_module.strip()
426 self.assertEqual(expected, result)
427
Ezio Melotti412c95a2010-02-16 23:31:04 +0000428 def test_stripid(self):
429 # test with strings, other implementations might have different repr()
430 stripid = pydoc.stripid
431 # strip the id
432 self.assertEqual(stripid('<function stripid at 0x88dcee4>'),
433 '<function stripid>')
434 self.assertEqual(stripid('<function stripid at 0x01F65390>'),
435 '<function stripid>')
436 # nothing to strip, return the same text
437 self.assertEqual(stripid('42'), '42')
438 self.assertEqual(stripid("<type 'exceptions.Exception'>"),
439 "<type 'exceptions.Exception'>")
440
Georg Brandld80d5f42010-12-03 07:47:22 +0000441 @unittest.skipIf(sys.flags.optimize >= 2,
442 'Docstrings are omitted with -O2 and above')
Brett Cannon7a540732011-02-22 03:04:06 +0000443 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
444 'trace function introduces __locals__ unexpectedly')
Georg Brandld80d5f42010-12-03 07:47:22 +0000445 def test_help_output_redirect(self):
446 # issue 940286, if output is set in Helper, then all output from
447 # Helper.help should be redirected
448 old_pattern = expected_text_pattern
449 getpager_old = pydoc.getpager
450 getpager_new = lambda: (lambda x: x)
451 self.maxDiff = None
452
453 buf = StringIO()
454 helper = pydoc.Helper(output=buf)
455 unused, doc_loc = get_pydoc_text(pydoc_mod)
456 module = "test.pydoc_mod"
457 help_header = """
458 Help on module test.pydoc_mod in test:
459
460 """.lstrip()
461 help_header = textwrap.dedent(help_header)
462 expected_help_pattern = help_header + expected_text_pattern
463
464 pydoc.getpager = getpager_new
465 try:
466 with captured_output('stdout') as output, \
467 captured_output('stderr') as err:
468 helper.help(module)
469 result = buf.getvalue().strip()
Serhiy Storchaka9d0add02013-01-27 19:47:45 +0200470 expected_text = expected_help_pattern % (
471 (doc_loc,) +
472 expected_text_data_docstrings +
473 (inspect.getabsfile(pydoc_mod),))
Georg Brandld80d5f42010-12-03 07:47:22 +0000474 self.assertEqual('', output.getvalue())
475 self.assertEqual('', err.getvalue())
476 self.assertEqual(expected_text, result)
477 finally:
478 pydoc.getpager = getpager_old
479
Raymond Hettinger1103d052011-03-25 14:15:24 -0700480 def test_namedtuple_public_underscore(self):
481 NT = namedtuple('NT', ['abc', 'def'], rename=True)
482 with captured_stdout() as help_io:
Terry Jan Reedy5c811642013-11-04 21:43:26 -0500483 pydoc.help(NT)
Raymond Hettinger1103d052011-03-25 14:15:24 -0700484 helptext = help_io.getvalue()
485 self.assertIn('_1', helptext)
486 self.assertIn('_replace', helptext)
487 self.assertIn('_asdict', helptext)
488
Victor Stinnere6c910e2011-06-30 15:55:43 +0200489 def test_synopsis(self):
490 self.addCleanup(unlink, TESTFN)
491 for encoding in ('ISO-8859-1', 'UTF-8'):
492 with open(TESTFN, 'w', encoding=encoding) as script:
493 if encoding != 'UTF-8':
494 print('#coding: {}'.format(encoding), file=script)
495 print('"""line 1: h\xe9', file=script)
496 print('line 2: hi"""', file=script)
497 synopsis = pydoc.synopsis(TESTFN, {})
498 self.assertEqual(synopsis, 'line 1: h\xe9')
499
Eric Snowaed5b222014-01-04 20:38:11 -0700500 def test_synopsis_sourceless(self):
501 expected = os.__doc__.splitlines()[0]
502 filename = os.__cached__
503 synopsis = pydoc.synopsis(filename)
504
505 self.assertEqual(synopsis, expected)
506
R David Murray455f2962013-03-19 00:00:33 -0400507 def test_splitdoc_with_description(self):
508 example_string = "I Am A Doc\n\n\nHere is my description"
509 self.assertEqual(pydoc.splitdoc(example_string),
510 ('I Am A Doc', '\nHere is my description'))
511
512 def test_is_object_or_method(self):
513 doc = pydoc.Doc()
514 # Bound Method
515 self.assertTrue(pydoc._is_some_method(doc.fail))
516 # Method Descriptor
517 self.assertTrue(pydoc._is_some_method(int.__add__))
518 # String
519 self.assertFalse(pydoc._is_some_method("I am not a method"))
520
521 def test_is_package_when_not_package(self):
522 with test.support.temp_cwd() as test_dir:
523 self.assertFalse(pydoc.ispackage(test_dir))
524
525 def test_is_package_when_is_package(self):
526 with test.support.temp_cwd() as test_dir:
527 init_path = os.path.join(test_dir, '__init__.py')
528 open(init_path, 'w').close()
529 self.assertTrue(pydoc.ispackage(test_dir))
530 os.remove(init_path)
531
R David Murrayac0cea52013-03-19 02:47:44 -0400532 def test_allmethods(self):
533 # issue 17476: allmethods was no longer returning unbound methods.
534 # This test is a bit fragile in the face of changes to object and type,
535 # but I can't think of a better way to do it without duplicating the
536 # logic of the function under test.
537
538 class TestClass(object):
539 def method_returning_true(self):
540 return True
541
542 # What we expect to get back: everything on object...
543 expected = dict(vars(object))
544 # ...plus our unbound method...
545 expected['method_returning_true'] = TestClass.method_returning_true
546 # ...but not the non-methods on object.
547 del expected['__doc__']
548 del expected['__class__']
549 # inspect resolves descriptors on type into methods, but vars doesn't,
550 # so we need to update __subclasshook__.
551 expected['__subclasshook__'] = TestClass.__subclasshook__
552
553 methods = pydoc.allmethods(TestClass)
554 self.assertDictEqual(methods, expected)
555
Georg Brandlb533e262008-05-25 18:19:30 +0000556
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200557class PydocImportTest(PydocBaseTest):
Ned Deily92a81a12011-10-06 14:19:03 -0700558
559 def setUp(self):
560 self.test_dir = os.mkdir(TESTFN)
561 self.addCleanup(rmtree, TESTFN)
562
563 def test_badimport(self):
564 # This tests the fix for issue 5230, where if pydoc found the module
565 # but the module had an internal import error pydoc would report no doc
566 # found.
567 modname = 'testmod_xyzzy'
568 testpairs = (
569 ('i_am_not_here', 'i_am_not_here'),
Brett Cannonfd074152012-04-14 14:10:13 -0400570 ('test.i_am_not_here_either', 'test.i_am_not_here_either'),
571 ('test.i_am_not_here.neither_am_i', 'test.i_am_not_here'),
572 ('i_am_not_here.{}'.format(modname), 'i_am_not_here'),
573 ('test.{}'.format(modname), 'test.{}'.format(modname)),
Ned Deily92a81a12011-10-06 14:19:03 -0700574 )
575
576 sourcefn = os.path.join(TESTFN, modname) + os.extsep + "py"
577 for importstring, expectedinmsg in testpairs:
578 with open(sourcefn, 'w') as f:
579 f.write("import {}\n".format(importstring))
580 result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii")
581 expected = badimport_pattern % (modname, expectedinmsg)
582 self.assertEqual(expected, result)
583
584 def test_apropos_with_bad_package(self):
585 # Issue 7425 - pydoc -k failed when bad package on path
586 pkgdir = os.path.join(TESTFN, "syntaxerr")
587 os.mkdir(pkgdir)
588 badsyntax = os.path.join(pkgdir, "__init__") + os.extsep + "py"
589 with open(badsyntax, 'w') as f:
590 f.write("invalid python syntax = $1\n")
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200591 with self.restrict_walk_packages(path=[TESTFN]):
592 with captured_stdout() as out:
593 with captured_stderr() as err:
594 pydoc.apropos('xyzzy')
595 # No result, no error
596 self.assertEqual(out.getvalue(), '')
597 self.assertEqual(err.getvalue(), '')
598 # The package name is still matched
599 with captured_stdout() as out:
600 with captured_stderr() as err:
601 pydoc.apropos('syntaxerr')
602 self.assertEqual(out.getvalue().strip(), 'syntaxerr')
603 self.assertEqual(err.getvalue(), '')
Ned Deily92a81a12011-10-06 14:19:03 -0700604
605 def test_apropos_with_unreadable_dir(self):
606 # Issue 7367 - pydoc -k failed when unreadable dir on path
607 self.unreadable_dir = os.path.join(TESTFN, "unreadable")
608 os.mkdir(self.unreadable_dir, 0)
609 self.addCleanup(os.rmdir, self.unreadable_dir)
610 # Note, on Windows the directory appears to be still
611 # readable so this is not really testing the issue there
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200612 with self.restrict_walk_packages(path=[TESTFN]):
613 with captured_stdout() as out:
614 with captured_stderr() as err:
615 pydoc.apropos('SOMEKEY')
616 # No result, no error
617 self.assertEqual(out.getvalue(), '')
618 self.assertEqual(err.getvalue(), '')
Ned Deily92a81a12011-10-06 14:19:03 -0700619
Eric Snowaed5b222014-01-04 20:38:11 -0700620 def test_modules(self):
621 # See Helper.listmodules().
622 num_header_lines = 2
623 num_module_lines_min = 5 # Playing it safe.
624 num_footer_lines = 3
625 expected = num_header_lines + num_module_lines_min + num_footer_lines
626
627 output = StringIO()
628 helper = pydoc.Helper(output=output)
629 helper('modules')
630 result = output.getvalue().strip()
631 num_lines = len(result.splitlines())
632
633 self.assertGreaterEqual(num_lines, expected)
634
635 def test_modules_search(self):
636 # See Helper.listmodules().
637 expected = 'pydoc - '
638
639 output = StringIO()
640 helper = pydoc.Helper(output=output)
641 with captured_stdout() as help_io:
642 helper('modules pydoc')
643 result = help_io.getvalue()
644
645 self.assertIn(expected, result)
646
Eric Snow5ea97502014-01-04 23:04:27 -0700647 @unittest.skip('some buildbots are not cooperating (#20123)')
Eric Snowaed5b222014-01-04 20:38:11 -0700648 def test_modules_search_builtin(self):
Eric Snow5ea97502014-01-04 23:04:27 -0700649 expected = 'gc - '
Eric Snowaed5b222014-01-04 20:38:11 -0700650
651 output = StringIO()
652 helper = pydoc.Helper(output=output)
653 with captured_stdout() as help_io:
Eric Snow5ea97502014-01-04 23:04:27 -0700654 helper('modules garbage')
Eric Snowaed5b222014-01-04 20:38:11 -0700655 result = help_io.getvalue()
656
657 self.assertTrue(result.startswith(expected))
658
659 def test_importfile(self):
660 loaded_pydoc = pydoc.importfile(pydoc.__file__)
661
Eric Snow3a62d142014-01-06 20:42:59 -0700662 self.assertIsNot(loaded_pydoc, pydoc)
Eric Snowaed5b222014-01-04 20:38:11 -0700663 self.assertEqual(loaded_pydoc.__name__, 'pydoc')
664 self.assertEqual(loaded_pydoc.__file__, pydoc.__file__)
Eric Snow3a62d142014-01-06 20:42:59 -0700665 self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
Eric Snowaed5b222014-01-04 20:38:11 -0700666
Ned Deily92a81a12011-10-06 14:19:03 -0700667
Georg Brandlb533e262008-05-25 18:19:30 +0000668class TestDescriptions(unittest.TestCase):
669
670 def test_module(self):
671 # Check that pydocfodder module can be described
672 from test import pydocfodder
673 doc = pydoc.render_doc(pydocfodder)
Benjamin Peterson577473f2010-01-19 00:09:57 +0000674 self.assertIn("pydocfodder", doc)
Georg Brandlb533e262008-05-25 18:19:30 +0000675
Georg Brandlb533e262008-05-25 18:19:30 +0000676 def test_class(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000677 class C: "New-style class"
Georg Brandlb533e262008-05-25 18:19:30 +0000678 c = C()
679
680 self.assertEqual(pydoc.describe(C), 'class C')
681 self.assertEqual(pydoc.describe(c), 'C')
682 expected = 'C in module %s object' % __name__
Benjamin Peterson577473f2010-01-19 00:09:57 +0000683 self.assertIn(expected, pydoc.render_doc(c))
Georg Brandlb533e262008-05-25 18:19:30 +0000684
Éric Araujoe64e51b2011-07-29 17:03:55 +0200685 def test_builtin(self):
686 for name in ('str', 'str.translate', 'builtins.str',
687 'builtins.str.translate'):
688 # test low-level function
689 self.assertIsNotNone(pydoc.locate(name))
690 # test high-level function
691 try:
692 pydoc.render_doc(name)
693 except ImportError:
694 self.fail('finding the doc of {!r} failed'.format(o))
695
696 for name in ('notbuiltins', 'strrr', 'strr.translate',
697 'str.trrrranslate', 'builtins.strrr',
698 'builtins.str.trrranslate'):
699 self.assertIsNone(pydoc.locate(name))
700 self.assertRaises(ImportError, pydoc.render_doc, name)
701
Stefan Krah5de32782014-01-18 23:18:39 +0100702 @requires_docstrings
703 def test_builtin_signatures(self):
Larry Hastings1abd7082014-01-16 14:15:03 -0800704 # test producing signatures from builtins
705 stat_sig = pydoc.render_doc(os.stat)
706 self.assertEqual(pydoc.plain(stat_sig).splitlines()[2],
707 'stat(path, *, dir_fd=None, follow_symlinks=True)')
708
Georg Brandlb533e262008-05-25 18:19:30 +0000709
Victor Stinner62a68f22011-05-20 02:29:13 +0200710@unittest.skipUnless(threading, 'Threading required for this test.')
Georg Brandld2f38572011-01-30 08:37:19 +0000711class PydocServerTest(unittest.TestCase):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000712 """Tests for pydoc._start_server"""
713
714 def test_server(self):
715
716 # Minimal test that starts the server, then stops it.
717 def my_url_handler(url, content_type):
718 text = 'the URL sent was: (%s, %s)' % (url, content_type)
719 return text
720
721 serverthread = pydoc._start_server(my_url_handler, port=0)
722 starttime = time.time()
723 timeout = 1 #seconds
724
725 while serverthread.serving:
726 time.sleep(.01)
727 if serverthread.serving and time.time() - starttime > timeout:
728 serverthread.stop()
729 break
730
731 self.assertEqual(serverthread.error, None)
732
733
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200734class PydocUrlHandlerTest(PydocBaseTest):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000735 """Tests for pydoc._url_handler"""
736
737 def test_content_type_err(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000738 f = pydoc._url_handler
Georg Brandld2f38572011-01-30 08:37:19 +0000739 self.assertRaises(TypeError, f, 'A', '')
740 self.assertRaises(TypeError, f, 'B', 'foobar')
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000741
742 def test_url_requests(self):
743 # Test for the correct title in the html pages returned.
744 # This tests the different parts of the URL handler without
745 # getting too picky about the exact html.
746 requests = [
Georg Brandld2f38572011-01-30 08:37:19 +0000747 ("", "Pydoc: Index of Modules"),
748 ("get?key=", "Pydoc: Index of Modules"),
749 ("index", "Pydoc: Index of Modules"),
750 ("topics", "Pydoc: Topics"),
751 ("keywords", "Pydoc: Keywords"),
752 ("pydoc", "Pydoc: module pydoc"),
753 ("get?key=pydoc", "Pydoc: module pydoc"),
754 ("search?key=pydoc", "Pydoc: Search Results"),
755 ("topic?key=def", "Pydoc: KEYWORD def"),
756 ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
757 ("foobar", "Pydoc: Error - foobar"),
758 ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000759 ]
760
Antoine Pitrou916fc7b2013-05-19 15:44:54 +0200761 with self.restrict_walk_packages():
762 for url, title in requests:
763 text = pydoc._url_handler(url, "text/html")
764 result = get_html_title(text)
765 self.assertEqual(result, title, text)
766
767 path = string.__file__
768 title = "Pydoc: getfile " + path
769 url = "getfile?key=" + path
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000770 text = pydoc._url_handler(url, "text/html")
771 result = get_html_title(text)
772 self.assertEqual(result, title)
773
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000774
Ezio Melottib185a042011-04-28 07:42:55 +0300775class TestHelper(unittest.TestCase):
776 def test_keywords(self):
777 self.assertEqual(sorted(pydoc.Helper.keywords),
778 sorted(keyword.kwlist))
779
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700780class PydocWithMetaClasses(unittest.TestCase):
Ethan Furman3f2f1922013-10-22 07:30:24 -0700781 @unittest.skipIf(sys.flags.optimize >= 2,
782 "Docstrings are omitted with -O2 and above")
783 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
784 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700785 def test_DynamicClassAttribute(self):
786 class Meta(type):
787 def __getattr__(self, name):
788 if name == 'ham':
789 return 'spam'
790 return super().__getattr__(name)
791 class DA(metaclass=Meta):
792 @types.DynamicClassAttribute
793 def ham(self):
794 return 'eggs'
Ethan Furman3f2f1922013-10-22 07:30:24 -0700795 expected_text_data_docstrings = tuple('\n | ' + s if s else ''
796 for s in expected_data_docstrings)
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700797 output = StringIO()
798 helper = pydoc.Helper(output=output)
799 helper(DA)
Ethan Furman3f2f1922013-10-22 07:30:24 -0700800 expected_text = expected_dynamicattribute_pattern % (
801 (__name__,) + expected_text_data_docstrings[:2])
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700802 result = output.getvalue().strip()
803 if result != expected_text:
804 print_diffs(expected_text, result)
805 self.fail("outputs are not equal, see diff above")
806
Ethan Furman3f2f1922013-10-22 07:30:24 -0700807 @unittest.skipIf(sys.flags.optimize >= 2,
808 "Docstrings are omitted with -O2 and above")
809 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
810 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700811 def test_virtualClassAttributeWithOneMeta(self):
812 class Meta(type):
813 def __dir__(cls):
814 return ['__class__', '__module__', '__name__', 'LIFE']
815 def __getattr__(self, name):
816 if name =='LIFE':
817 return 42
818 return super().__getattr(name)
819 class Class(metaclass=Meta):
820 pass
821 output = StringIO()
822 helper = pydoc.Helper(output=output)
823 helper(Class)
824 expected_text = expected_virtualattribute_pattern1 % __name__
825 result = output.getvalue().strip()
826 if result != expected_text:
827 print_diffs(expected_text, result)
828 self.fail("outputs are not equal, see diff above")
829
Ethan Furman3f2f1922013-10-22 07:30:24 -0700830 @unittest.skipIf(sys.flags.optimize >= 2,
831 "Docstrings are omitted with -O2 and above")
832 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
833 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700834 def test_virtualClassAttributeWithTwoMeta(self):
835 class Meta1(type):
836 def __dir__(cls):
837 return ['__class__', '__module__', '__name__', 'one']
838 def __getattr__(self, name):
839 if name =='one':
840 return 1
841 return super().__getattr__(name)
842 class Meta2(type):
843 def __dir__(cls):
844 return ['__class__', '__module__', '__name__', 'two']
845 def __getattr__(self, name):
846 if name =='two':
847 return 2
848 return super().__getattr__(name)
849 class Meta3(Meta1, Meta2):
850 def __dir__(cls):
851 return list(sorted(set(
852 ['__class__', '__module__', '__name__', 'three'] +
853 Meta1.__dir__(cls) + Meta2.__dir__(cls))))
854 def __getattr__(self, name):
855 if name =='three':
856 return 3
857 return super().__getattr__(name)
858 class Class1(metaclass=Meta1):
859 pass
860 class Class2(Class1, metaclass=Meta3):
861 pass
862 fail1 = fail2 = False
863 output = StringIO()
864 helper = pydoc.Helper(output=output)
865 helper(Class1)
866 expected_text1 = expected_virtualattribute_pattern2 % __name__
867 result1 = output.getvalue().strip()
868 if result1 != expected_text1:
869 print_diffs(expected_text1, result1)
870 fail1 = True
871 output = StringIO()
872 helper = pydoc.Helper(output=output)
873 helper(Class2)
874 expected_text2 = expected_virtualattribute_pattern3 % __name__
875 result2 = output.getvalue().strip()
876 if result2 != expected_text2:
877 print_diffs(expected_text2, result2)
878 fail2 = True
879 if fail1 or fail2:
880 self.fail("outputs are not equal, see diff above")
881
Ethan Furman3f2f1922013-10-22 07:30:24 -0700882 @unittest.skipIf(sys.flags.optimize >= 2,
883 "Docstrings are omitted with -O2 and above")
884 @unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
885 'trace function introduces __locals__ unexpectedly')
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700886 def test_buggy_dir(self):
887 class M(type):
888 def __dir__(cls):
889 return ['__class__', '__name__', 'missing', 'here']
890 class C(metaclass=M):
891 here = 'present!'
892 output = StringIO()
893 helper = pydoc.Helper(output=output)
894 helper(C)
895 expected_text = expected_missingattribute_pattern % __name__
896 result = output.getvalue().strip()
897 if result != expected_text:
898 print_diffs(expected_text, result)
899 self.fail("outputs are not equal, see diff above")
900
Eric Snowaed5b222014-01-04 20:38:11 -0700901
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200902@reap_threads
Georg Brandlb533e262008-05-25 18:19:30 +0000903def test_main():
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200904 try:
905 test.support.run_unittest(PydocDocTest,
Ned Deily92a81a12011-10-06 14:19:03 -0700906 PydocImportTest,
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200907 TestDescriptions,
908 PydocServerTest,
909 PydocUrlHandlerTest,
910 TestHelper,
Ethan Furmanb0c84cd2013-10-20 22:37:39 -0700911 PydocWithMetaClasses,
Antoine Pitroua6e81a22011-07-15 22:32:25 +0200912 )
913 finally:
914 reap_children()
Georg Brandlb533e262008-05-25 18:19:30 +0000915
916if __name__ == "__main__":
917 test_main()