summaryrefslogtreecommitdiff
path: root/tests/checkers/unittest_deprecated.py
diff options
context:
space:
mode:
authorMatus Valo <matusvalo@users.noreply.github.com>2021-05-08 22:10:21 +0200
committerGitHub <noreply@github.com>2021-05-08 22:10:21 +0200
commit9528500f8a4f9927350a7b62c87f634f3ec26722 (patch)
tree45c1e87d80996580da43f26491d0e810aa32f6db /tests/checkers/unittest_deprecated.py
parent6f246a03346ea4f592c4d70002382eab1e89d219 (diff)
downloadpylint-git-9528500f8a4f9927350a7b62c87f634f3ec26722.tar.gz
Add Deprecated Class unittests (#4448)
* Add Deprecated Class unittests
Diffstat (limited to 'tests/checkers/unittest_deprecated.py')
-rw-r--r--tests/checkers/unittest_deprecated.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py
index a15596abc..f2a51aa05 100644
--- a/tests/checkers/unittest_deprecated.py
+++ b/tests/checkers/unittest_deprecated.py
@@ -15,6 +15,9 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker):
def deprecated_modules(self):
return {"deprecated_module"}
+ def deprecated_classes(self, module):
+ return ["DeprecatedClass"] if module == "deprecated" else []
+
def deprecated_arguments(self, method):
if method == "myfunction1":
# def myfunction1(arg1, deprecated_arg1='spam')
@@ -416,3 +419,55 @@ class TestDeprecatedChecker(CheckerTestCase):
)
):
self.checker.visit_importfrom(node)
+
+ def test_deprecated_class_import_from(self):
+ # Tests detecting deprecated class via import from
+ node = astroid.extract_node(
+ """
+ from .deprecated import DeprecatedClass
+ """
+ )
+ with self.assertAddsMessages(
+ Message(
+ msg_id="deprecated-class",
+ args=("DeprecatedClass", "deprecated"),
+ node=node,
+ confidence=UNDEFINED,
+ )
+ ):
+ self.checker.visit_importfrom(node)
+
+ def test_deprecated_class_import(self):
+ # Tests detecting deprecated class via import
+ node = astroid.extract_node(
+ """
+ import deprecated.DeprecatedClass
+ """
+ )
+ with self.assertAddsMessages(
+ Message(
+ msg_id="deprecated-class",
+ args=("DeprecatedClass", "deprecated"),
+ node=node,
+ confidence=UNDEFINED,
+ )
+ ):
+ self.checker.visit_import(node)
+
+ def test_deprecated_class_call(self):
+ # Tests detecting deprecated class via call
+ node = astroid.extract_node(
+ """
+ import deprecated
+ deprecated.DeprecatedClass()
+ """
+ )
+ with self.assertAddsMessages(
+ Message(
+ msg_id="deprecated-class",
+ args=("DeprecatedClass", "deprecated"),
+ node=node,
+ confidence=UNDEFINED,
+ )
+ ):
+ self.checker.visit_call(node)