blob: bcddff3ec7be1402094801bc501af7e46cdb225d [file] [log] [blame]
Georg Brandlb533e262008-05-25 18:19:30 +00001import os
Nick Coghlan7bb30b72010-12-03 09:29:11 +00002import sys
Georg Brandlb533e262008-05-25 18:19:30 +00003import difflib
Georg Brandlb533e262008-05-25 18:19:30 +00004import inspect
Nick Coghlan7bb30b72010-12-03 09:29:11 +00005import pydoc
Ezio Melottib185a042011-04-28 07:42:55 +03006import keyword
Nick Coghlan7bb30b72010-12-03 09:29:11 +00007import re
8import string
9import subprocess
Georg Brandlb533e262008-05-25 18:19:30 +000010import test.support
Nick Coghlan7bb30b72010-12-03 09:29:11 +000011import time
12import unittest
Brian Curtin49c284c2010-03-31 03:19:28 +000013import xml.etree
Georg Brandld80d5f42010-12-03 07:47:22 +000014import textwrap
15from io import StringIO
Raymond Hettinger1103d052011-03-25 14:15:24 -070016from collections import namedtuple
Benjamin Peterson0289b152009-06-28 17:22:03 +000017from contextlib import contextmanager
Georg Brandld80d5f42010-12-03 07:47:22 +000018from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard, \
Raymond Hettinger1103d052011-03-25 14:15:24 -070019 reap_children, captured_output, captured_stdout
Georg Brandlb533e262008-05-25 18:19:30 +000020
21from test import pydoc_mod
22
Florent Xicluna085a6562010-03-06 14:04:16 +000023# Just in case sys.modules["test"] has the optional attribute __loader__.
24if hasattr(pydoc_mod, "__loader__"):
25 del pydoc_mod.__loader__
26
Barry Warsaw28a691b2010-04-17 00:19:56 +000027expected_text_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +000028NAME
29 test.pydoc_mod - This is a test module for test_pydoc
Georg Brandlb533e262008-05-25 18:19:30 +000030%s
31CLASSES
32 builtins.object
33 A
34 B
35\x20\x20\x20\x20
36 class A(builtins.object)
37 | Hello and goodbye
38 |\x20\x20
39 | Methods defined here:
40 |\x20\x20
41 | __init__()
42 | Wow, I have no function!
43 |\x20\x20
44 | ----------------------------------------------------------------------
45 | Data descriptors defined here:
46 |\x20\x20
47 | __dict__
48 | dictionary for instance variables (if defined)
49 |\x20\x20
50 | __weakref__
51 | list of weak references to the object (if defined)
52\x20\x20\x20\x20
53 class B(builtins.object)
54 | Data descriptors defined here:
55 |\x20\x20
56 | __dict__
57 | dictionary for instance variables (if defined)
58 |\x20\x20
59 | __weakref__
60 | list of weak references to the object (if defined)
61 |\x20\x20
62 | ----------------------------------------------------------------------
63 | Data and other attributes defined here:
64 |\x20\x20
65 | NO_MEANING = 'eggs'
66
67FUNCTIONS
68 doc_func()
69 This function solves all of the world's problems:
70 hunger
71 lack of Python
72 war
73\x20\x20\x20\x20
74 nodoc_func()
75
76DATA
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000077 __xyz__ = 'X, Y and Z'
Georg Brandlb533e262008-05-25 18:19:30 +000078
79VERSION
80 1.2.3.4
81
82AUTHOR
83 Benjamin Peterson
84
85CREDITS
86 Nobody
Alexander Belopolskya47bbf52010-11-18 01:52:54 +000087
88FILE
89 %s
Georg Brandlb533e262008-05-25 18:19:30 +000090""".strip()
91
Barry Warsaw28a691b2010-04-17 00:19:56 +000092expected_html_pattern = """
Georg Brandlb533e262008-05-25 18:19:30 +000093<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
94<tr bgcolor="#7799ee">
95<td valign=bottom>&nbsp;<br>
96<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
97><td align=right valign=bottom
98><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:%s">%s</a>%s</font></td></tr></table>
99 <p><tt>This&nbsp;is&nbsp;a&nbsp;test&nbsp;module&nbsp;for&nbsp;test_pydoc</tt></p>
100<p>
101<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
102<tr bgcolor="#ee77aa">
103<td colspan=3 valign=bottom>&nbsp;<br>
104<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
105\x20\x20\x20\x20
106<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
107<td width="100%%"><dl>
108<dt><font face="helvetica, arial"><a href="builtins.html#object">builtins.object</a>
109</font></dt><dd>
110<dl>
111<dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#A">A</a>
112</font></dt><dt><font face="helvetica, arial"><a href="test.pydoc_mod.html#B">B</a>
113</font></dt></dl>
114</dd>
115</dl>
116 <p>
117<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
118<tr bgcolor="#ffc8d8">
119<td colspan=3 valign=bottom>&nbsp;<br>
120<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>
121\x20\x20\x20\x20
122<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
123<td colspan=2><tt>Hello&nbsp;and&nbsp;goodbye<br>&nbsp;</tt></td></tr>
124<tr><td>&nbsp;</td>
125<td width="100%%">Methods defined here:<br>
126<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>
127
128<hr>
129Data descriptors defined here:<br>
130<dl><dt><strong>__dict__</strong></dt>
131<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
132</dl>
133<dl><dt><strong>__weakref__</strong></dt>
134<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
135</dl>
136</td></tr></table> <p>
137<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
138<tr bgcolor="#ffc8d8">
139<td colspan=3 valign=bottom>&nbsp;<br>
140<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>
141\x20\x20\x20\x20
142<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
143<td width="100%%">Data descriptors defined here:<br>
144<dl><dt><strong>__dict__</strong></dt>
145<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
146</dl>
147<dl><dt><strong>__weakref__</strong></dt>
148<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
149</dl>
150<hr>
151Data and other attributes defined here:<br>
152<dl><dt><strong>NO_MEANING</strong> = 'eggs'</dl>
153
154</td></tr></table></td></tr></table><p>
155<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
156<tr bgcolor="#eeaa77">
157<td colspan=3 valign=bottom>&nbsp;<br>
158<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
159\x20\x20\x20\x20
160<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
161<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>
162hunger<br>
163lack&nbsp;of&nbsp;Python<br>
164war</tt></dd></dl>
165 <dl><dt><a name="-nodoc_func"><strong>nodoc_func</strong></a>()</dt></dl>
166</td></tr></table><p>
167<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
168<tr bgcolor="#55aa55">
169<td colspan=3 valign=bottom>&nbsp;<br>
170<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
171\x20\x20\x20\x20
172<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
Alexander Belopolskya47bbf52010-11-18 01:52:54 +0000173<td width="100%%"><strong>__xyz__</strong> = 'X, Y and Z'</td></tr></table><p>
Georg Brandlb533e262008-05-25 18:19:30 +0000174<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
175<tr bgcolor="#7799ee">
176<td colspan=3 valign=bottom>&nbsp;<br>
177<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
178\x20\x20\x20\x20
179<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
180<td width="100%%">Benjamin&nbsp;Peterson</td></tr></table><p>
181<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
182<tr bgcolor="#7799ee">
183<td colspan=3 valign=bottom>&nbsp;<br>
184<font color="#ffffff" face="helvetica, arial"><big><strong>Credits</strong></big></font></td></tr>
185\x20\x20\x20\x20
186<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
187<td width="100%%">Nobody</td></tr></table>
Barry Warsaw28a691b2010-04-17 00:19:56 +0000188""".strip() # ' <- emacs turd
Georg Brandlb533e262008-05-25 18:19:30 +0000189
190
191# output pattern for missing module
192missing_pattern = "no Python documentation found for '%s'"
193
Benjamin Peterson0289b152009-06-28 17:22:03 +0000194# output pattern for module with bad imports
195badimport_pattern = "problem in %s - ImportError: No module named %s"
196
Georg Brandlb533e262008-05-25 18:19:30 +0000197def run_pydoc(module_name, *args):
198 """
199 Runs pydoc on the specified module. Returns the stripped
200 output of pydoc.
201 """
202 cmd = [sys.executable, pydoc.__file__, " ".join(args), module_name]
Antoine Pitrouaecd3b72009-10-30 21:45:40 +0000203 try:
204 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
205 return output.strip()
206 finally:
207 reap_children()
Georg Brandlb533e262008-05-25 18:19:30 +0000208
209def get_pydoc_html(module):
210 "Returns pydoc generated output as html"
211 doc = pydoc.HTMLDoc()
212 output = doc.docmodule(module)
213 loc = doc.getdocloc(pydoc_mod) or ""
214 if loc:
215 loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
216 return output.strip(), loc
217
218def get_pydoc_text(module):
219 "Returns pydoc generated output as text"
220 doc = pydoc.TextDoc()
221 loc = doc.getdocloc(pydoc_mod) or ""
222 if loc:
223 loc = "\nMODULE DOCS\n " + loc + "\n"
224
225 output = doc.docmodule(module)
226
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000227 # clean up the extra text formatting that pydoc performs
Georg Brandlb533e262008-05-25 18:19:30 +0000228 patt = re.compile('\b.')
229 output = patt.sub('', output)
230 return output.strip(), loc
231
232def print_diffs(text1, text2):
233 "Prints unified diffs for two texts"
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000234 # XXX now obsolete, use unittest built-in support
Georg Brandlb533e262008-05-25 18:19:30 +0000235 lines1 = text1.splitlines(True)
236 lines2 = text2.splitlines(True)
237 diffs = difflib.unified_diff(lines1, lines2, n=0, fromfile='expected',
238 tofile='got')
239 print('\n' + ''.join(diffs))
240
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000241def get_html_title(text):
Nick Coghlanecace282010-12-03 16:08:46 +0000242 # Bit of hack, but good enough for test purposes
243 header, _, _ = text.partition("</head>")
244 _, _, title = header.partition("<title>")
245 title, _, _ = title.partition("</title>")
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000246 return title
247
Georg Brandlb533e262008-05-25 18:19:30 +0000248
Georg Brandld2f38572011-01-30 08:37:19 +0000249class PydocDocTest(unittest.TestCase):
Georg Brandlb533e262008-05-25 18:19:30 +0000250
R. David Murray378c0cf2010-02-24 01:46:21 +0000251 @unittest.skipIf(sys.flags.optimize >= 2,
252 "Docstrings are omitted with -O2 and above")
Georg Brandlb533e262008-05-25 18:19:30 +0000253 def test_html_doc(self):
254 result, doc_loc = get_pydoc_html(pydoc_mod)
255 mod_file = inspect.getabsfile(pydoc_mod)
Benjamin Petersonc5e94642008-06-14 23:04:46 +0000256 if sys.platform == 'win32':
257 import nturl2path
258 mod_url = nturl2path.pathname2url(mod_file)
259 else:
260 mod_url = mod_file
261 expected_html = expected_html_pattern % (mod_url, mod_file, doc_loc)
Georg Brandlb533e262008-05-25 18:19:30 +0000262 if result != expected_html:
263 print_diffs(expected_html, result)
264 self.fail("outputs are not equal, see diff above")
265
R. David Murray378c0cf2010-02-24 01:46:21 +0000266 @unittest.skipIf(sys.flags.optimize >= 2,
267 "Docstrings are omitted with -O2 and above")
Georg Brandlb533e262008-05-25 18:19:30 +0000268 def test_text_doc(self):
269 result, doc_loc = get_pydoc_text(pydoc_mod)
270 expected_text = expected_text_pattern % \
Alexander Belopolskya47bbf52010-11-18 01:52:54 +0000271 (doc_loc, inspect.getabsfile(pydoc_mod))
Georg Brandlb533e262008-05-25 18:19:30 +0000272 if result != expected_text:
273 print_diffs(expected_text, result)
274 self.fail("outputs are not equal, see diff above")
275
Brian Curtin49c284c2010-03-31 03:19:28 +0000276 def test_issue8225(self):
277 # Test issue8225 to ensure no doc link appears for xml.etree
278 result, doc_loc = get_pydoc_text(xml.etree)
279 self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")
280
Georg Brandlb533e262008-05-25 18:19:30 +0000281 def test_not_here(self):
282 missing_module = "test.i_am_not_here"
283 result = str(run_pydoc(missing_module), 'ascii')
284 expected = missing_pattern % missing_module
285 self.assertEqual(expected, result,
286 "documentation for missing module found")
287
Benjamin Peterson0289b152009-06-28 17:22:03 +0000288 def test_badimport(self):
289 # This tests the fix for issue 5230, where if pydoc found the module
290 # but the module had an internal import error pydoc would report no doc
291 # found.
292 modname = 'testmod_xyzzy'
293 testpairs = (
294 ('i_am_not_here', 'i_am_not_here'),
295 ('test.i_am_not_here_either', 'i_am_not_here_either'),
296 ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
Barry Warsaw28a691b2010-04-17 00:19:56 +0000297 ('i_am_not_here.{}'.format(modname),
298 'i_am_not_here.{}'.format(modname)),
Benjamin Peterson0289b152009-06-28 17:22:03 +0000299 ('test.{}'.format(modname), modname),
300 )
301
302 @contextmanager
303 def newdirinpath(dir):
304 os.mkdir(dir)
305 sys.path.insert(0, dir)
306 yield
307 sys.path.pop(0)
308 rmtree(dir)
309
310 with newdirinpath(TESTFN), EnvironmentVarGuard() as env:
311 env['PYTHONPATH'] = TESTFN
312 fullmodname = os.path.join(TESTFN, modname)
313 sourcefn = fullmodname + os.extsep + "py"
314 for importstring, expectedinmsg in testpairs:
Barry Warsaw28a691b2010-04-17 00:19:56 +0000315 with open(sourcefn, 'w') as f:
316 f.write("import {}\n".format(importstring))
Benjamin Peterson0289b152009-06-28 17:22:03 +0000317 try:
318 result = run_pydoc(modname).decode("ascii")
319 finally:
320 forget(modname)
321 expected = badimport_pattern % (modname, expectedinmsg)
322 self.assertEqual(expected, result)
323
R. David Murray1f1b9d32009-05-27 20:56:59 +0000324 def test_input_strip(self):
325 missing_module = " test.i_am_not_here "
326 result = str(run_pydoc(missing_module), 'ascii')
327 expected = missing_pattern % missing_module.strip()
328 self.assertEqual(expected, result)
329
Ezio Melotti412c95a2010-02-16 23:31:04 +0000330 def test_stripid(self):
331 # test with strings, other implementations might have different repr()
332 stripid = pydoc.stripid
333 # strip the id
334 self.assertEqual(stripid('<function stripid at 0x88dcee4>'),
335 '<function stripid>')
336 self.assertEqual(stripid('<function stripid at 0x01F65390>'),
337 '<function stripid>')
338 # nothing to strip, return the same text
339 self.assertEqual(stripid('42'), '42')
340 self.assertEqual(stripid("<type 'exceptions.Exception'>"),
341 "<type 'exceptions.Exception'>")
342
Georg Brandld80d5f42010-12-03 07:47:22 +0000343 @unittest.skipIf(sys.flags.optimize >= 2,
344 'Docstrings are omitted with -O2 and above')
345 def test_help_output_redirect(self):
346 # issue 940286, if output is set in Helper, then all output from
347 # Helper.help should be redirected
348 old_pattern = expected_text_pattern
349 getpager_old = pydoc.getpager
350 getpager_new = lambda: (lambda x: x)
351 self.maxDiff = None
352
353 buf = StringIO()
354 helper = pydoc.Helper(output=buf)
355 unused, doc_loc = get_pydoc_text(pydoc_mod)
356 module = "test.pydoc_mod"
357 help_header = """
358 Help on module test.pydoc_mod in test:
359
360 """.lstrip()
361 help_header = textwrap.dedent(help_header)
362 expected_help_pattern = help_header + expected_text_pattern
363
364 pydoc.getpager = getpager_new
365 try:
366 with captured_output('stdout') as output, \
367 captured_output('stderr') as err:
368 helper.help(module)
369 result = buf.getvalue().strip()
370 expected_text = expected_help_pattern % \
371 (doc_loc, inspect.getabsfile(pydoc_mod))
372 self.assertEqual('', output.getvalue())
373 self.assertEqual('', err.getvalue())
374 self.assertEqual(expected_text, result)
375 finally:
376 pydoc.getpager = getpager_old
377
Raymond Hettinger1103d052011-03-25 14:15:24 -0700378 def test_namedtuple_public_underscore(self):
379 NT = namedtuple('NT', ['abc', 'def'], rename=True)
380 with captured_stdout() as help_io:
381 help(NT)
382 helptext = help_io.getvalue()
383 self.assertIn('_1', helptext)
384 self.assertIn('_replace', helptext)
385 self.assertIn('_asdict', helptext)
386
Georg Brandlb533e262008-05-25 18:19:30 +0000387
388class TestDescriptions(unittest.TestCase):
389
390 def test_module(self):
391 # Check that pydocfodder module can be described
392 from test import pydocfodder
393 doc = pydoc.render_doc(pydocfodder)
Benjamin Peterson577473f2010-01-19 00:09:57 +0000394 self.assertIn("pydocfodder", doc)
Georg Brandlb533e262008-05-25 18:19:30 +0000395
Georg Brandlb533e262008-05-25 18:19:30 +0000396 def test_class(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000397 class C: "New-style class"
Georg Brandlb533e262008-05-25 18:19:30 +0000398 c = C()
399
400 self.assertEqual(pydoc.describe(C), 'class C')
401 self.assertEqual(pydoc.describe(c), 'C')
402 expected = 'C in module %s object' % __name__
Benjamin Peterson577473f2010-01-19 00:09:57 +0000403 self.assertIn(expected, pydoc.render_doc(c))
Georg Brandlb533e262008-05-25 18:19:30 +0000404
405
Georg Brandld2f38572011-01-30 08:37:19 +0000406class PydocServerTest(unittest.TestCase):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000407 """Tests for pydoc._start_server"""
408
409 def test_server(self):
410
411 # Minimal test that starts the server, then stops it.
412 def my_url_handler(url, content_type):
413 text = 'the URL sent was: (%s, %s)' % (url, content_type)
414 return text
415
416 serverthread = pydoc._start_server(my_url_handler, port=0)
417 starttime = time.time()
418 timeout = 1 #seconds
419
420 while serverthread.serving:
421 time.sleep(.01)
422 if serverthread.serving and time.time() - starttime > timeout:
423 serverthread.stop()
424 break
425
426 self.assertEqual(serverthread.error, None)
427
428
Georg Brandld2f38572011-01-30 08:37:19 +0000429class PydocUrlHandlerTest(unittest.TestCase):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000430 """Tests for pydoc._url_handler"""
431
432 def test_content_type_err(self):
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000433 f = pydoc._url_handler
Georg Brandld2f38572011-01-30 08:37:19 +0000434 self.assertRaises(TypeError, f, 'A', '')
435 self.assertRaises(TypeError, f, 'B', 'foobar')
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000436
437 def test_url_requests(self):
438 # Test for the correct title in the html pages returned.
439 # This tests the different parts of the URL handler without
440 # getting too picky about the exact html.
441 requests = [
Georg Brandld2f38572011-01-30 08:37:19 +0000442 ("", "Pydoc: Index of Modules"),
443 ("get?key=", "Pydoc: Index of Modules"),
444 ("index", "Pydoc: Index of Modules"),
445 ("topics", "Pydoc: Topics"),
446 ("keywords", "Pydoc: Keywords"),
447 ("pydoc", "Pydoc: module pydoc"),
448 ("get?key=pydoc", "Pydoc: module pydoc"),
449 ("search?key=pydoc", "Pydoc: Search Results"),
450 ("topic?key=def", "Pydoc: KEYWORD def"),
451 ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
452 ("foobar", "Pydoc: Error - foobar"),
453 ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000454 ]
455
456 for url, title in requests:
457 text = pydoc._url_handler(url, "text/html")
458 result = get_html_title(text)
459 self.assertEqual(result, title)
460
461 path = string.__file__
Georg Brandld2f38572011-01-30 08:37:19 +0000462 title = "Pydoc: getfile " + path
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000463 url = "getfile?key=" + path
464 text = pydoc._url_handler(url, "text/html")
465 result = get_html_title(text)
466 self.assertEqual(result, title)
467
468
Ezio Melottib185a042011-04-28 07:42:55 +0300469class TestHelper(unittest.TestCase):
470 def test_keywords(self):
471 self.assertEqual(sorted(pydoc.Helper.keywords),
472 sorted(keyword.kwlist))
473
Georg Brandlb533e262008-05-25 18:19:30 +0000474def test_main():
Georg Brandld2f38572011-01-30 08:37:19 +0000475 test.support.run_unittest(PydocDocTest,
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000476 TestDescriptions,
Georg Brandld2f38572011-01-30 08:37:19 +0000477 PydocServerTest,
478 PydocUrlHandlerTest,
Ezio Melotti44aad852011-04-28 07:51:14 +0300479 TestHelper,
Nick Coghlan7bb30b72010-12-03 09:29:11 +0000480 )
Georg Brandlb533e262008-05-25 18:19:30 +0000481
482if __name__ == "__main__":
483 test_main()