Commit d2f3857c authored by Georg Brandl's avatar Georg Brandl

#10961: fix exception handling in new pydoc server code.

Patch by Ron Adam, reviewed by Eric Araujo.
parent ce227e35
This diff is collapsed.
...@@ -244,7 +244,7 @@ def get_html_title(text): ...@@ -244,7 +244,7 @@ def get_html_title(text):
return title return title
class PyDocDocTest(unittest.TestCase): class PydocDocTest(unittest.TestCase):
@unittest.skipIf(sys.flags.optimize >= 2, @unittest.skipIf(sys.flags.optimize >= 2,
"Docstrings are omitted with -O2 and above") "Docstrings are omitted with -O2 and above")
...@@ -392,7 +392,7 @@ class TestDescriptions(unittest.TestCase): ...@@ -392,7 +392,7 @@ class TestDescriptions(unittest.TestCase):
self.assertIn(expected, pydoc.render_doc(c)) self.assertIn(expected, pydoc.render_doc(c))
class PyDocServerTest(unittest.TestCase): class PydocServerTest(unittest.TestCase):
"""Tests for pydoc._start_server""" """Tests for pydoc._start_server"""
def test_server(self): def test_server(self):
...@@ -415,34 +415,31 @@ class PyDocServerTest(unittest.TestCase): ...@@ -415,34 +415,31 @@ class PyDocServerTest(unittest.TestCase):
self.assertEqual(serverthread.error, None) self.assertEqual(serverthread.error, None)
class PyDocUrlHandlerTest(unittest.TestCase): class PydocUrlHandlerTest(unittest.TestCase):
"""Tests for pydoc._url_handler""" """Tests for pydoc._url_handler"""
def test_content_type_err(self): def test_content_type_err(self):
err = 'Error: unknown content type '
f = pydoc._url_handler f = pydoc._url_handler
result = f("", "") self.assertRaises(TypeError, f, 'A', '')
self.assertEqual(result, err + "''") self.assertRaises(TypeError, f, 'B', 'foobar')
result = f("", "foobar")
self.assertEqual(result, err + "'foobar'")
def test_url_requests(self): def test_url_requests(self):
# Test for the correct title in the html pages returned. # Test for the correct title in the html pages returned.
# This tests the different parts of the URL handler without # This tests the different parts of the URL handler without
# getting too picky about the exact html. # getting too picky about the exact html.
requests = [ requests = [
("", "Python: Index of Modules"), ("", "Pydoc: Index of Modules"),
("get?key=", "Python: Index of Modules"), ("get?key=", "Pydoc: Index of Modules"),
("index", "Python: Index of Modules"), ("index", "Pydoc: Index of Modules"),
("topics", "Python: Topics"), ("topics", "Pydoc: Topics"),
("keywords", "Python: Keywords"), ("keywords", "Pydoc: Keywords"),
("pydoc", "Python: module pydoc"), ("pydoc", "Pydoc: module pydoc"),
("get?key=pydoc", "Python: module pydoc"), ("get?key=pydoc", "Pydoc: module pydoc"),
("search?key=pydoc", "Python: Search Results"), ("search?key=pydoc", "Pydoc: Search Results"),
("def", "Python: KEYWORD def"), ("topic?key=def", "Pydoc: KEYWORD def"),
("STRINGS", "Python: TOPIC STRINGS"), ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"),
("foobar", "Python: Error"), ("foobar", "Pydoc: Error - foobar"),
("getfile?key=foobar", "Python: Read Error"), ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"),
] ]
for url, title in requests: for url, title in requests:
...@@ -451,7 +448,7 @@ class PyDocUrlHandlerTest(unittest.TestCase): ...@@ -451,7 +448,7 @@ class PyDocUrlHandlerTest(unittest.TestCase):
self.assertEqual(result, title) self.assertEqual(result, title)
path = string.__file__ path = string.__file__
title = "Python: getfile " + path title = "Pydoc: getfile " + path
url = "getfile?key=" + path url = "getfile?key=" + path
text = pydoc._url_handler(url, "text/html") text = pydoc._url_handler(url, "text/html")
result = get_html_title(text) result = get_html_title(text)
...@@ -459,10 +456,10 @@ class PyDocUrlHandlerTest(unittest.TestCase): ...@@ -459,10 +456,10 @@ class PyDocUrlHandlerTest(unittest.TestCase):
def test_main(): def test_main():
test.support.run_unittest(PyDocDocTest, test.support.run_unittest(PydocDocTest,
TestDescriptions, TestDescriptions,
PyDocServerTest, PydocServerTest,
PyDocUrlHandlerTest, PydocUrlHandlerTest,
) )
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -88,6 +88,9 @@ Library ...@@ -88,6 +88,9 @@ Library
- Issue #9509: argparse now properly handles IOErrors raised by - Issue #9509: argparse now properly handles IOErrors raised by
argparse.FileType. argparse.FileType.
- Issue #10961: The new pydoc server now better handles exceptions raised
during request handling.
Build Build
----- -----
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment