aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/multidict/tests/test_incorrect_args.py
blob: 280204c8d097135b7741ac52162619ea85d1d61b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""Test passing invalid arguments to the methods of the MultiDict class."""

from dataclasses import dataclass
from typing import cast

import pytest

from multidict import MultiDict


@dataclass(frozen=True)
class InvalidTestedMethodArgs:
    """A set of arguments passed to methods under test."""

    test_id: str
    positional: tuple[object, ...]
    keyword: dict[str, object]

    def __str__(self) -> str:
        """Render a test identifier as a string."""
        return self.test_id


@pytest.fixture(
    scope="module",
    params=(
        InvalidTestedMethodArgs("no_args", (), {}),
        InvalidTestedMethodArgs("too_many_args", ("a", "b", "c"), {}),
        InvalidTestedMethodArgs("wrong_kwarg", (), {"wrong": 1}),
        InvalidTestedMethodArgs(
            "wrong_kwarg_and_too_many_args",
            ("a",),
            {"wrong": 1},
        ),
    ),
    ids=str,
)
def tested_method_args(
    request: pytest.FixtureRequest,
) -> InvalidTestedMethodArgs:
    """Return an instance of a parameter set."""
    return cast(InvalidTestedMethodArgs, request.param)


@pytest.fixture(scope="module")
def multidict_object(
    any_multidict_class: type[MultiDict[int]],
) -> MultiDict[int]:
    return any_multidict_class([("a", 1), ("a", 2)])


def test_getall_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.getall(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_getone_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.getone(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_get_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.get(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_setdefault_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.setdefault(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_popone_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.popone(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_pop_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.pop(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )


def test_popall_args(
    multidict_object: MultiDict[int],
    tested_method_args: InvalidTestedMethodArgs,
) -> None:
    with pytest.raises(TypeError, match=r".*argument.*"):
        multidict_object.popall(
            *tested_method_args.positional,
            **tested_method_args.keyword,
        )