summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pydoc.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2015-11-06 00:51:38 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2015-11-06 00:51:38 (GMT)
commit98da9d0e0de8300e1362aacb213e450c977d28dc (patch)
tree910b479dfe85ebc23dc32630c47a3bd7452c4a8f /Lib/test/test_pydoc.py
parent7931be403d6f616777e4a46cf43ee0bd21374889 (diff)
parent9ad0aae6566311c6982a20955381cda5a2954519 (diff)
downloadcpython-98da9d0e0de8300e1362aacb213e450c977d28dc.zip
cpython-98da9d0e0de8300e1362aacb213e450c977d28dc.tar.gz
cpython-98da9d0e0de8300e1362aacb213e450c977d28dc.tar.bz2
Issue #18010: Merge pydoc web search fix from 3.4 into 3.5
Diffstat (limited to 'Lib/test/test_pydoc.py')
-rw-r--r--Lib/test/test_pydoc.py38
1 files changed, 32 insertions, 6 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index ec5c31b..8ad5706 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -396,6 +396,13 @@ class PydocBaseTest(unittest.TestCase):
finally:
pkgutil.walk_packages = walk_packages
+ def call_url_handler(self, url, expected_title):
+ text = pydoc._url_handler(url, "text/html")
+ result = get_html_title(text)
+ # Check the title to ensure an unexpected error page was not returned
+ self.assertEqual(result, expected_title, text)
+ return text
+
class PydocDocTest(unittest.TestCase):
@@ -704,6 +711,29 @@ class PydocImportTest(PydocBaseTest):
finally:
os.chmod(pkgdir, current_mode)
+ def test_url_search_package_error(self):
+ # URL handler search should cope with packages that raise exceptions
+ pkgdir = os.path.join(TESTFN, "test_error_package")
+ os.mkdir(pkgdir)
+ init = os.path.join(pkgdir, "__init__.py")
+ with open(init, "wt", encoding="ascii") as f:
+ f.write("""raise ValueError("ouch")\n""")
+ with self.restrict_walk_packages(path=[TESTFN]):
+ # Package has to be importable for the error to have any effect
+ saved_paths = tuple(sys.path)
+ sys.path.insert(0, TESTFN)
+ try:
+ with self.assertRaisesRegex(ValueError, "ouch"):
+ import test_error_package # Sanity check
+
+ text = self.call_url_handler("search?key=test_error_package",
+ "Pydoc: Search Results")
+ found = ('<a href="test_error_package.html">'
+ 'test_error_package</a>')
+ self.assertIn(found, text)
+ finally:
+ sys.path[:] = saved_paths
+
@unittest.skip('causes undesireable side-effects (#20128)')
def test_modules(self):
# See Helper.listmodules().
@@ -880,16 +910,12 @@ class PydocUrlHandlerTest(PydocBaseTest):
with self.restrict_walk_packages():
for url, title in requests:
- text = pydoc._url_handler(url, "text/html")
- result = get_html_title(text)
- self.assertEqual(result, title, text)
+ self.call_url_handler(url, title)
path = string.__file__
title = "Pydoc: getfile " + path
url = "getfile?key=" + path
- text = pydoc._url_handler(url, "text/html")
- result = get_html_title(text)
- self.assertEqual(result, title)
+ self.call_url_handler(url, title)
class TestHelper(unittest.TestCase):