|
1 | | -from typing import List, Tuple |
| 1 | +from __future__ import annotations |
| 2 | + |
2 | 3 | from urllib.parse import parse_qsl, urlencode |
3 | 4 |
|
4 | 5 | import pytest |
|
7 | 8 |
|
8 | 9 |
|
9 | 10 | @pytest.mark.parametrize( |
10 | | - "qs, expected", |
| 11 | + ("qs", "expected"), |
11 | 12 | [ |
12 | 13 | ("", []), |
13 | 14 | ("&", []), |
|
19 | 20 | ("&a=b", [("a", "b")]), |
20 | 21 | ("a=a+b&b=b+c", [("a", "a b"), ("b", "b c")]), |
21 | 22 | ("a=1&a=2", [("a", "1"), ("a", "2")]), |
22 | | - ("", []), |
23 | | - ("&", []), |
24 | | - ("&&", []), |
25 | | - ("=", [("", "")]), |
26 | | - ("=a", [("", "a")]), |
27 | | - ("a", [("a", "")]), |
28 | | - ("a=", [("a", "")]), |
29 | | - ("&a=b", [("a", "b")]), |
30 | | - ("a=a+b&b=b+c", [("a", "a b"), ("b", "b c")]), |
31 | | - ("a=1&a=2", [("a", "1"), ("a", "2")]), |
32 | | - (";a=b", [(";a", "b")]), |
33 | | - ("a=a+b;b=b+c", [("a", "a b;b=b c")]), |
34 | 23 | (";a=b", [(";a", "b")]), |
35 | 24 | ("a=a+b;b=b+c", [("a", "a b;b=b c")]), |
36 | 25 | ], |
37 | 26 | ) |
38 | | -def test_parse_qsl_standard_separator(qs: str, expected: List[Tuple[str, str]]) -> None: |
| 27 | +def test_parse_qsl_standard_separator(qs: str, expected: list[tuple[str, str]]) -> None: |
39 | 28 | result = parse_query_string(qs.encode(), "&") |
40 | 29 | assert result == parse_qsl(qs, keep_blank_values=True) == expected |
41 | 30 |
|
42 | 31 |
|
43 | 32 | @pytest.mark.parametrize( |
44 | | - "qs, expected", |
| 33 | + ("qs", "expected"), |
45 | 34 | [ |
46 | 35 | (";", []), |
47 | 36 | (";;", []), |
48 | 37 | (";a=b", [("a", "b")]), |
49 | 38 | ("a=a+b;b=b+c", [("a", "a b"), ("b", "b c")]), |
50 | 39 | ("a=1;a=2", [("a", "1"), ("a", "2")]), |
51 | | - (";", []), |
52 | | - (";;", []), |
53 | | - (";a=b", [("a", "b")]), |
54 | | - ("a=a+b;b=b+c", [("a", "a b"), ("b", "b c")]), |
55 | | - ("a=1;a=2", [("a", "1"), ("a", "2")]), |
56 | 40 | ], |
57 | 41 | ) |
58 | | -def test_parse_qsl_semicolon_separator(qs: str, expected: List[Tuple[str, str]]) -> None: |
| 42 | +def test_parse_qsl_semicolon_separator(qs: str, expected: list[tuple[str, str]]) -> None: |
59 | 43 | result = parse_query_string(qs.encode(), ";") |
60 | 44 | assert result == parse_qsl(qs, separator=";", keep_blank_values=True) == expected |
61 | 45 |
|
62 | 46 |
|
63 | 47 | @pytest.mark.parametrize( |
64 | 48 | "values", |
65 | | - ( |
| 49 | + [ |
66 | 50 | (("first", "x@test.com"), ("second", "aaa")), |
67 | 51 | (("first", "&@A.ac"), ("second", "aaa")), |
68 | 52 | (("first", "a@A.ac&"), ("second", "aaa")), |
69 | 53 | (("first", "a@A&.ac"), ("second", "aaa")), |
70 | | - ), |
| 54 | + ], |
71 | 55 | ) |
72 | | -def test_query_parsing_of_escaped_values(values: Tuple[Tuple[str, str], Tuple[str, str]]) -> None: |
| 56 | +def test_query_parsing_of_escaped_values(values: tuple[tuple[str, str], tuple[str, str]]) -> None: |
73 | 57 | url_encoded = urlencode(values) |
74 | 58 | assert parse_query_string(url_encoded.encode(), "&") == list(values) |
75 | 59 |
|
76 | 60 |
|
77 | 61 | def test_parses_non_ascii_text() -> None: |
78 | 62 | assert parse_query_string("arabic_text=اختبار اللغة العربية".encode(), "&") == [ |
79 | | - ("arabic_text", "اختبار اللغة العربية") |
| 63 | + ("arabic_text", "اختبار اللغة العربية"), |
80 | 64 | ] |
81 | 65 |
|
82 | 66 |
|
|
0 commit comments