Skip to content

Commit 06b8c7e

Browse files
q0wpradyunsg
authored andcommitted
Adapt doctype tests
1 parent 792f851 commit 06b8c7e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/unit/test_collector.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,44 @@ def test_parse_link_handles_deprecated_usage_properly() -> None:
551551
assert "pkg1-2.0" in parsed_links[1].url
552552

553553

554+
def test_parse_links_no_warning_on_missing_doctype(
555+
caplog: pytest.LogCaptureFixture,
556+
) -> None:
557+
html = b'<a href="/pkg1-1.0.tar.gz"></a><a href="/pkg1-2.0.tar.gz"></a>'
558+
url = "https://example.com/simple/"
559+
page = HTMLPage(html, encoding=None, url=url, cache_link_parsing=False)
560+
561+
with caplog.at_level(logging.WARN):
562+
parsed_links = list(parse_links(page, use_deprecated_html5lib=False))
563+
564+
assert len(parsed_links) == 2, parsed_links
565+
assert "pkg1-1.0" in parsed_links[0].url
566+
assert "pkg1-2.0" in parsed_links[1].url
567+
568+
assert len(caplog.records) == 0
569+
570+
571+
def test_parse_links_no_warning_on_html4_doctype(
572+
caplog: pytest.LogCaptureFixture,
573+
) -> None:
574+
html = (
575+
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" '
576+
b'"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
577+
b'<a href="/pkg1-1.0.tar.gz"></a><a href="/pkg1-2.0.tar.gz"></a>'
578+
)
579+
url = "https://example.com/simple/"
580+
page = HTMLPage(html, encoding=None, url=url, cache_link_parsing=False)
581+
582+
with caplog.at_level(logging.WARN):
583+
parsed_links = list(parse_links(page, use_deprecated_html5lib=False))
584+
585+
assert len(parsed_links) == 2, parsed_links
586+
assert "pkg1-1.0" in parsed_links[0].url
587+
assert "pkg1-2.0" in parsed_links[1].url
588+
589+
assert len(caplog.records) == 0
590+
591+
554592
@mock.patch("pip._internal.index.collector.raise_for_status")
555593
def test_request_http_error(
556594
mock_raise_for_status: mock.Mock, caplog: pytest.LogCaptureFixture

0 commit comments

Comments
 (0)