Skip to content

Commit a5d2460

Browse files
bpo-47042: Fix testing the HTML output in test_pydoc (GH-31959)
Previously it tested that that the actual output contains every non-whitespace character from the expected output (ignoring order and repetitions). Now it will test that the actual output contains the same lines as the expected output, in the same order, ignoring indentation and empty lines.
1 parent 3011a09 commit a5d2460

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Lib/test/test_pydoc.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,10 @@ def html2text(html):
340340
341341
Tailored for pydoc tests only.
342342
"""
343-
return pydoc.replace(
344-
re.sub("<.*?>", "", html),
345-
"&nbsp;", " ", "&gt;", ">", "&lt;", "<")
343+
html = html.replace("<dd>", "\n")
344+
html = re.sub("<.*?>", "", html)
345+
html = pydoc.replace(html, "&nbsp;", " ", "&gt;", ">", "&lt;", "<")
346+
return html
346347

347348

348349
class PydocBaseTest(unittest.TestCase):
@@ -384,9 +385,12 @@ class PydocDocTest(unittest.TestCase):
384385
def test_html_doc(self):
385386
result, doc_loc = get_pydoc_html(pydoc_mod)
386387
text_result = html2text(result)
387-
expected_lines = [line.strip() for line in html2text_of_expected if line]
388-
for line in expected_lines:
389-
self.assertIn(line, text_result)
388+
text_lines = [line.strip() for line in text_result.splitlines()]
389+
text_lines = [line for line in text_lines if line]
390+
del text_lines[1]
391+
expected_lines = html2text_of_expected.splitlines()
392+
expected_lines = [line.strip() for line in expected_lines if line]
393+
self.assertEqual(text_lines, expected_lines)
390394
mod_file = inspect.getabsfile(pydoc_mod)
391395
mod_url = urllib.parse.quote(mod_file)
392396
self.assertIn(mod_url, result)

0 commit comments

Comments
 (0)