Skip to content

bpo-47042: Fix testing the HTML output in test_pydoc #31959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,10 @@ def html2text(html):

Tailored for pydoc tests only.
"""
return pydoc.replace(
re.sub("<.*?>", "", html),
"&nbsp;", " ", "&gt;", ">", "&lt;", "<")
html = html.replace("<dd>", "\n")
html = re.sub("<.*?>", "", html)
html = pydoc.replace(html, "&nbsp;", " ", "&gt;", ">", "&lt;", "<")
return html


class PydocBaseTest(unittest.TestCase):
Expand Down Expand Up @@ -384,9 +385,12 @@ class PydocDocTest(unittest.TestCase):
def test_html_doc(self):
result, doc_loc = get_pydoc_html(pydoc_mod)
text_result = html2text(result)
expected_lines = [line.strip() for line in html2text_of_expected if line]
for line in expected_lines:
self.assertIn(line, text_result)
text_lines = [line.strip() for line in text_result.splitlines()]
text_lines = [line for line in text_lines if line]
del text_lines[1]
expected_lines = html2text_of_expected.splitlines()
expected_lines = [line.strip() for line in expected_lines if line]
self.assertEqual(text_lines, expected_lines)
mod_file = inspect.getabsfile(pydoc_mod)
mod_url = urllib.parse.quote(mod_file)
self.assertIn(mod_url, result)
Expand Down