diff options
author | Julien Palard <julien@palard.fr> | 2020-11-13 13:49:07 +0100 |
---|---|---|
committer | Julien Palard <julien@palard.fr> | 2020-11-13 13:49:07 +0100 |
commit | 48b57104cd7958bc483d143e217273ce3503884d (patch) | |
tree | 2b0723441d37788aaa1e3f8888d822485dcd44b6 | |
parent | bdd1a7eb11f79a5ae67c170e794aa256b8af645b (diff) | |
download | pylint-git-48b57104cd7958bc483d143e217273ce3503884d.tar.gz |
Refactor tests.
-rw-r--r-- | tests/checkers/unittest_typecheck.py | 80 |
1 files changed, 36 insertions, 44 deletions
diff --git a/tests/checkers/unittest_typecheck.py b/tests/checkers/unittest_typecheck.py index 011447fd4..688b3c3c0 100644 --- a/tests/checkers/unittest_typecheck.py +++ b/tests/checkers/unittest_typecheck.py @@ -287,7 +287,28 @@ class TestTypeChecker(CheckerTestCase): with self.assertNoMessages(): self.checker.visit_subscript(subscript) - def test_typing_option_object_is_subscriptable_issue3882(self): + def test_issue3882_class_decorators(self): + decorators = """ + class Unsubscriptable: + def __init__(self, f): + self.f = f + + class Subscriptable: + def __init__(self, f): + self.f = f + + def __getitem__(self, item): + return item + """ + self.typing_option_object_is_subscriptable(decorators) + + self.decorated_by_a_subscriptable_class(decorators) + self.decorated_by_an_unsubscriptable_class(decorators) + + self.decorated_by_subscriptable_then_unsubscriptable_class(decorators) + self.decorated_by_unsubscriptable_then_subscriptable_class(decorators) + + def typing_option_object_is_subscriptable(self, decorators): module = astroid.parse( """ import typing @@ -298,16 +319,11 @@ class TestTypeChecker(CheckerTestCase): with self.assertNoMessages(): self.checker.visit_subscript(subscript) - def test_decorated_by_a_subscriptable_class_issue3882(self): + def decorated_by_a_subscriptable_class(self, decorators): module = astroid.parse( - """ - class Deco: - def __init__(self, f): - self.f = f - - def __getitem__(self, item): - return item - @Deco + decorators + + """ + @Subscriptable def decorated(): ... @@ -318,27 +334,16 @@ class TestTypeChecker(CheckerTestCase): with self.assertNoMessages(): self.checker.visit_subscript(subscript) - def test_decorated_by_subscriptable_then_unsubscriptable_class_issue3882(self): + def decorated_by_subscriptable_then_unsubscriptable_class(self, decorators): module = astroid.parse( - """ - class Unsubscriptable: - def __init__(self, f): - self.f = f - - class Subscriptable: - def __init__(self, f): - self.f = f - - def __getitem__(self, item): - return item - + decorators + + """ @Unsubscriptable @Subscriptable def decorated(): ... test = decorated[None] - # TypeError: 'Unsubscriptable' object is not subscriptable """ ) subscript = module.body[-1].value @@ -352,20 +357,10 @@ class TestTypeChecker(CheckerTestCase): ): self.checker.visit_subscript(subscript) - def test_decorated_by_unsubscriptable_then_subscriptable_class_issue3882(self): + def decorated_by_unsubscriptable_then_subscriptable_class(self, decorators): module = astroid.parse( - """ - class Unsubscriptable: - def __init__(self, f): - self.f = f - - class Subscriptable: - def __init__(self, f): - self.f = f - - def __getitem__(self, item): - return item - + decorators + + """ @Subscriptable @Unsubscriptable def decorated(): @@ -378,14 +373,11 @@ class TestTypeChecker(CheckerTestCase): with self.assertNoMessages(): self.checker.visit_subscript(subscript) - def test_decorated_by_an_unsubscriptable_class_issue3882(self): + def decorated_by_an_unsubscriptable_class(self, decorators): module = astroid.parse( - """ - class Deco: - def __init__(self, f): - self.f = f - - @Deco + decorators + + """ + @Unsubscriptable def decorated(): ... |