Skip to content

Commit e4a63ff

Browse files
authored
Backport 3.9: Add tests, accidentally dropped before (#8088) (#8372)
Cherry picked from commit 0016004 (#8088)
1 parent 2c64c8a commit e4a63ff

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

CHANGES/8088.contrib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enabled HTTP parser tests originally intended for 3.9.2 release -- by :user:`pajod`.

tests/test_http_parser.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ def test_parse_headers_longline(parser: Any) -> None:
294294
parser.feed_data(text)
295295

296296

297+
@pytest.fixture
298+
def xfail_c_parser_status(request) -> None:
299+
if isinstance(request.getfixturevalue("parser"), HttpRequestParserPy):
300+
return
301+
request.node.add_marker(
302+
pytest.mark.xfail(
303+
reason="Regression test for Py parser. May match C behaviour later.",
304+
raises=http_exceptions.BadStatusLine,
305+
)
306+
)
307+
308+
309+
@pytest.mark.usefixtures("xfail_c_parser_status")
297310
def test_parse_unusual_request_line(parser) -> None:
298311
if not isinstance(response, HttpResponseParserPy):
299312
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
@@ -632,9 +645,6 @@ def test_invalid_header_spacing(parser, pad1: bytes, pad2: bytes, hdr: bytes) ->
632645
if pad1 == pad2 == b"" and hdr != b"":
633646
# one entry in param matrix is correct: non-empty name, not padded
634647
expectation = nullcontext()
635-
if pad1 == pad2 == hdr == b"":
636-
if not isinstance(response, HttpResponseParserPy):
637-
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
638648
with expectation:
639649
parser.feed_data(text)
640650

@@ -815,9 +825,20 @@ def test_http_request_upgrade(parser: Any) -> None:
815825
assert tail == b"some raw data"
816826

817827

828+
@pytest.fixture
829+
def xfail_c_parser_url(request) -> None:
830+
if isinstance(request.getfixturevalue("parser"), HttpRequestParserPy):
831+
return
832+
request.node.add_marker(
833+
pytest.mark.xfail(
834+
reason="Regression test for Py parser. May match C behaviour later.",
835+
raises=http_exceptions.InvalidURLError,
836+
)
837+
)
838+
839+
840+
@pytest.mark.usefixtures("xfail_c_parser_url")
818841
def test_http_request_parser_utf8_request_line(parser) -> None:
819-
if not isinstance(response, HttpResponseParserPy):
820-
pytest.xfail("Regression test for Py parser. May match C behaviour later.")
821842
messages, upgrade, tail = parser.feed_data(
822843
# note the truncated unicode sequence
823844
b"GET /P\xc3\xbcnktchen\xa0\xef\xb7 HTTP/1.1\r\n" +
@@ -837,7 +858,9 @@ def test_http_request_parser_utf8_request_line(parser) -> None:
837858
assert msg.compression is None
838859
assert not msg.upgrade
839860
assert not msg.chunked
840-
assert msg.url.path == URL("/P%C3%BCnktchen\udca0\udcef\udcb7").path
861+
# python HTTP parser depends on Cython and CPython URL to match
862+
# .. but yarl.URL("/abs") is not equal to URL.build(path="/abs"), see #6409
863+
assert msg.url == URL.build(path="/Pünktchen\udca0\udcef\udcb7", encoded=True)
841864

842865

843866
def test_http_request_parser_utf8(parser) -> None:

0 commit comments

Comments
 (0)