diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-03-17 16:32:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-17 16:32:53 (GMT) |
commit | a5d246066b5352a7d72e70ec0acb643e7c0861fa (patch) | |
tree | d1a67e22563a9c431d1ed0eaf9a9705b81996a05 | |
parent | 3011a097bd9500c007bd8b8d005edeea895f6b44 (diff) | |
download | cpython-a5d246066b5352a7d72e70ec0acb643e7c0861fa.zip cpython-a5d246066b5352a7d72e70ec0acb643e7c0861fa.tar.gz cpython-a5d246066b5352a7d72e70ec0acb643e7c0861fa.tar.bz2 |
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.
-rw-r--r-- | Lib/test/test_pydoc.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 057780d..4f18af3 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -340,9 +340,10 @@ def html2text(html): Tailored for pydoc tests only. """ - return pydoc.replace( - re.sub("<.*?>", "", html), - " ", " ", ">", ">", "<", "<") + html = html.replace("<dd>", "\n") + html = re.sub("<.*?>", "", html) + html = pydoc.replace(html, " ", " ", ">", ">", "<", "<") + return html class PydocBaseTest(unittest.TestCase): @@ -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) |