summaryrefslogtreecommitdiff
path: root/tests/message/conftest.py
blob: e410578350624b864b4d94bdc1a524f7fa1d16da (plain)
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
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt

# pylint: disable=redefined-outer-name

from __future__ import annotations

from collections.abc import ValuesView

import pytest

from pylint.checkers import BaseChecker
from pylint.lint.pylinter import PyLinter
from pylint.message import MessageDefinition, MessageDefinitionStore, MessageIdStore


@pytest.fixture
def msgid():
    return "W1234"


@pytest.fixture
def symbol():
    return "msg-symbol"


@pytest.fixture
def empty_store() -> MessageDefinitionStore:
    return MessageDefinitionStore()


@pytest.fixture
def store() -> MessageDefinitionStore:
    store_ = MessageDefinitionStore()

    class Checker(BaseChecker):
        def __init__(self) -> None:
            super().__init__(PyLinter())

        name = "achecker"
        msgs = {
            "W1234": (
                "message",
                "msg-symbol",
                "msg description.",
                {"old_names": [("W0001", "old-symbol")]},
            ),
            "E1234": (
                "Duplicate keyword argument %r in %s call",
                "duplicate-keyword-arg",
                "Used when a function call passes the same keyword argument multiple times.",
                {"maxversion": (2, 6)},
            ),
        }

    store_.register_messages_from_checker(Checker())
    return store_


@pytest.fixture
def message_definitions(store: MessageDefinitionStore) -> ValuesView[MessageDefinition]:
    return store.messages


@pytest.fixture
def msgids() -> dict[str, str]:
    return {
        "W1234": "warning-symbol",
        "W1235": "warning-symbol-two",
        "C1234": "convention-symbol",
        "E1234": "error-symbol",
    }


@pytest.fixture
def empty_msgid_store() -> MessageIdStore:
    return MessageIdStore()


@pytest.fixture
def msgid_store(msgids: dict[str, str]) -> MessageIdStore:
    msgid_store = MessageIdStore()
    for msgid, symbol in msgids.items():
        msgid_store.add_msgid_and_symbol(msgid, symbol)
    return msgid_store