MCPcopy
hub / github.com/encode/httpx / test_urlparse

Function test_urlparse

tests/models/test_whatwg.py:23–52  ·  view source on GitHub ↗
(test_case)

Source from the content-addressed store, hash-verified

21
22@pytest.mark.parametrize("test_case", test_cases)
23def test_urlparse(test_case):
24 if test_case["href"] in ("a: foo.com", "lolscheme:x x#x%20x"):
25 # Skip these two test cases.
26 # WHATWG cases where are not using percent-encoding for the space character.
27 # Anyone know what's going on here?
28 return
29
30 p = urlparse(test_case["href"])
31
32 # Test cases include the protocol with the trailing ":"
33 protocol = p.scheme + ":"
34 # Include the square brackets for IPv6 addresses.
35 hostname = f"[{p.host}]" if ":" in p.host else p.host
36 # The test cases use a string representation of the port.
37 port = "" if p.port is None else str(p.port)
38 # I have nothing to say about this one.
39 path = p.path
40 # The 'search' and 'hash' components in the whatwg tests are semantic, not literal.
41 # Our parsing differentiates between no query/hash and empty-string query/hash.
42 search = "" if p.query in (None, "") else "?" + str(p.query)
43 hash = "" if p.fragment in (None, "") else "#" + str(p.fragment)
44
45 # URL hostnames are case-insensitive.
46 # We normalize these, unlike the WHATWG test cases.
47 assert protocol == test_case["protocol"]
48 assert hostname.lower() == test_case["hostname"].lower()
49 assert port == test_case["port"]
50 assert path == test_case["pathname"]
51 assert search == test_case["search"]
52 assert hash == test_case["hash"]

Callers

nothing calls this directly

Calls 1

urlparseFunction · 0.90

Tested by

no test coverage detected