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
|
# 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
"""Test for deprecation warnings in the config module."""
import warnings
import pytest
from pylint.checkers import BaseChecker
from pylint.lint import PyLinter
from pylint.utils import get_global_option
class SampleChecker(BaseChecker):
options = (("test-opt", {"action": "store_true", "help": "help message"}),)
class SampleCheckerTwo(BaseChecker):
options = (
("test-opt-two", {"action": "store", "type": "string", "help": "help message"}),
)
class SampleCheckerThree(BaseChecker):
options = (
(
"test-opt-three",
{"action": "store_true", "level": 1, "help": "help message"},
),
)
class TestDeprecationArgumentsManager:
"""Tests for deprecation warnings in the ArgumentsManager class."""
linter = PyLinter()
@classmethod
def setup_class(cls) -> None:
checker = SampleChecker(cls.linter)
cls.linter.register_checker(checker)
with pytest.warns(DeprecationWarning):
cls.linter.register_options_provider(checker)
def test_load_configuration(self) -> None:
"""Test that load_configuration emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.load_configuration(test_opt=True)
def test_load_configuration_from_config(self) -> None:
"""Test that load_configuration_from_config emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.load_configuration_from_config({"test_opt": True})
def test_help_with_level(self) -> None:
"""Test that help with a level argument raises a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.help(1)
with pytest.warns(DeprecationWarning):
self.linter.help(level=1)
with warnings.catch_warnings():
warnings.simplefilter("error")
self.linter.help()
def test_register_options_provider_load_defaults(self) -> None:
"""Test that register_options_provider and load_defaults emits a DeprecationWarning."""
checker = BaseChecker(self.linter)
with pytest.warns(DeprecationWarning):
self.linter.register_options_provider(checker)
with pytest.warns(DeprecationWarning):
self.linter.load_defaults()
def test_get_global_option(self) -> None:
"""Test that get_global_option emits a DeprecationWarning."""
checker = BaseChecker(self.linter)
with pytest.warns(DeprecationWarning):
get_global_option(checker, "test-opt") # type: ignore[call-overload]
def test_read_config_file(self) -> None:
"""Test that read_config_file emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.read_config_file()
def test_load_config_file(self) -> None:
"""Test that load_config_file emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.load_config_file()
def test_load_command_line_configuration(self) -> None:
"""Test that load_command_line_configuration emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.load_command_line_configuration([])
def test_cb_set_provider_option(self) -> None:
"""Test that cb_set_provider_option emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.cb_set_provider_option(None, "--test-opt", True, None)
def test_level_attribute(self) -> None:
"""Test that the level attribute emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
self.linter.level = 1
with pytest.warns(DeprecationWarning):
assert self.linter.level is not None
def test_no_default_in_optdict(self) -> None:
"""Test that not having a default value in a optiondict emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
SampleCheckerTwo(self.linter)
def test_no_level_in_optdict(self) -> None:
"""Test that not having a level value in a optiondict emits a DeprecationWarning."""
with pytest.warns(DeprecationWarning):
SampleCheckerThree(self.linter)
|