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
|
# 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
"""Check deprecation across the codebase."""
from __future__ import annotations
from typing import Any
import pytest
from astroid import nodes
from pylint import lint
from pylint.checkers import BaseChecker
from pylint.checkers.mapreduce_checker import MapReduceMixin
from pylint.config import load_results, save_results
from pylint.interfaces import (
IAstroidChecker,
IChecker,
Interface,
IRawChecker,
IReporter,
ITokenChecker,
)
from pylint.lint import PyLinter
from pylint.message import MessageDefinitionStore
from pylint.reporters import BaseReporter
from pylint.reporters.ureports.nodes import Section
from pylint.utils import FileState
def test_mapreducemixin() -> None:
"""Test that MapReduceMixin has been deprecated correctly."""
class MyChecker(MapReduceMixin):
def get_map_data(self) -> Any:
...
def reduce_map_data(self, linter: PyLinter, data: list[Any]) -> None:
...
with pytest.warns(DeprecationWarning):
MyChecker()
def test_reporter_implements() -> None:
"""Test that __implements__ on BaseReporter has been deprecated correctly."""
class MyReporter(BaseReporter):
__implements__ = IReporter
def _display(self, layout: Section) -> None:
...
with pytest.warns(DeprecationWarning):
MyReporter()
def test_checker_implements() -> None:
"""Test that __implements__ on BaseChecker has been deprecated correctly."""
class MyChecker(BaseChecker):
__implements__ = IAstroidChecker
with pytest.warns(DeprecationWarning):
MyChecker(PyLinter())
def test_interfaces() -> None:
"""Test that all interfaces have been deprecated correctly."""
with pytest.warns(DeprecationWarning):
Interface()
with pytest.warns(DeprecationWarning):
IAstroidChecker()
with pytest.warns(DeprecationWarning):
IReporter()
with pytest.warns(DeprecationWarning):
IRawChecker()
with pytest.warns(DeprecationWarning):
IChecker()
with pytest.warns(DeprecationWarning):
ITokenChecker()
def test_load_and_save_results() -> None:
"""Test that load_results and save_results are deprecated."""
with pytest.warns(DeprecationWarning):
save_results(object(), "") # type: ignore[arg-type]
with pytest.warns(DeprecationWarning):
load_results("")
def test_filestate() -> None:
"""Test that FileState needs its arguments."""
with pytest.warns(DeprecationWarning):
FileState()
with pytest.warns(DeprecationWarning):
FileState("foo")
with pytest.warns(DeprecationWarning):
FileState(msg_store=MessageDefinitionStore())
FileState("foo", MessageDefinitionStore())
def test_collectblocklines() -> None:
"""Test FileState.collect_block_lines."""
state = FileState("foo", MessageDefinitionStore())
with pytest.warns(DeprecationWarning):
state.collect_block_lines(MessageDefinitionStore(), nodes.Module("foo"))
def test_patch_sys_path() -> None:
"""Test that _patch_sys_path() is deprecated"""
with pytest.deprecated_call():
lint._patch_sys_path([])
def test_fix_import_path() -> None:
"""Test that fix_import_path() is deprecated"""
with pytest.deprecated_call():
with lint.fix_import_path([]):
pass
|