Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move no-member tests from TestTypeChecker #5453

Merged
merged 11 commits into from Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 0 additions & 115 deletions tests/checkers/unittest_typecheck.py
Expand Up @@ -49,121 +49,6 @@ class TestTypeChecker(CheckerTestCase):
"Tests for pylint.checkers.typecheck"
CHECKER_CLASS = typecheck.TypeChecker

def test_no_member_in_getattr(self) -> None:
"""Make sure that a module attribute access is checked by pylint."""

node = astroid.extract_node(
"""
import optparse
optparse.THIS_does_not_EXIST
"""
)
with self.assertAddsMessages(
MessageTest(
"no-member",
node=node,
args=("Module", "optparse", "THIS_does_not_EXIST", ""),
confidence=INFERENCE,
)
):
self.checker.visit_attribute(node)

@set_config(ignored_modules=("argparse",))
def test_no_member_in_getattr_ignored(self) -> None:
"""Make sure that a module attribute access check is omitted with a
module that is configured to be ignored.
"""

node = astroid.extract_node(
"""
import argparse
argparse.THIS_does_not_EXIST
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)

@set_config(ignored_modules=("xml.etree.",))
def test_ignored_modules_invalid_pattern(self) -> None:
node = astroid.extract_node(
"""
import xml
xml.etree.Lala
"""
)
message = MessageTest(
"no-member",
node=node,
args=("Module", "xml.etree", "Lala", ""),
confidence=INFERENCE,
)
with self.assertAddsMessages(message):
self.checker.visit_attribute(node)

@set_config(ignored_modules=("xml",))
def test_ignored_modules_root_one_applies_as_well(self) -> None:
# Check that when a root module is completely ignored, submodules are skipped.
node = astroid.extract_node(
"""
import xml
xml.etree.Lala
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)

@set_config(ignored_modules=("xml.etree*",))
def test_ignored_modules_patterns(self) -> None:
node = astroid.extract_node(
"""
import xml
xml.etree.portocola #@
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)

@set_config(ignored_classes=("xml.*",))
def test_ignored_classes_no_recursive_pattern(self) -> None:
node = astroid.extract_node(
"""
import xml
xml.etree.ElementTree.Test
"""
)
message = MessageTest(
"no-member",
node=node,
args=("Module", "xml.etree.ElementTree", "Test", ""),
confidence=INFERENCE,
)
with self.assertAddsMessages(message):
self.checker.visit_attribute(node)

@set_config(ignored_classes=("optparse.Values",))
def test_ignored_classes_qualified_name(self) -> None:
"""Test that ignored-classes supports qualified name for ignoring."""
node = astroid.extract_node(
"""
import optparse
optparse.Values.lala
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)

@set_config(ignored_classes=("Values",))
def test_ignored_classes_only_name(self) -> None:
"""Test that ignored_classes works with the name only."""
node = astroid.extract_node(
"""
import optparse
optparse.Values.lala
"""
)
with self.assertNoMessages():
self.checker.visit_attribute(node)

@set_config(suggestion_mode=False)
@needs_c_extension
def test_nomember_on_c_extension_error_msg(self) -> None:
Expand Down
59 changes: 59 additions & 0 deletions tests/functional/n/no/no_member_imports.py
@@ -0,0 +1,59 @@
"""Tests for no-member on imported modules"""
# pylint: disable=import-outside-toplevel, pointless-statement, missing-function-docstring
# pylint: disable=deprecated-module


def test_no_member_in_getattr():
"""Make sure that a module attribute access is checked by pylint."""
import math

math.THIS_does_not_EXIST # [no-member]


def test_no_member_in_getattr_ignored() -> None:
"""Make sure that a module attribute access check is omitted with a
module that is configured to be ignored.
"""
import argparse

argparse.THIS_does_not_EXIST


def test_ignored_modules_invalid_pattern() -> None:
import xml

xml.etree.THIS_does_not_EXIST # [no-member]


def test_ignored_modules_root_one_applies_as_well() -> None:
"""Check that when a root module is completely ignored, submodules are skipped."""
import argparse

argparse.submodule.THIS_does_not_EXIST


def test_ignored_modules_patterns() -> None:
import collections

collections.abc.THIS_does_not_EXIST


def test_ignored_classes_no_recursive_pattern() -> None:
import sys

sys.THIS_does_not_EXIST # [no-member]


def test_ignored_classes_qualified_name() -> None:
"""Test that ignored-classes supports qualified name for ignoring."""

import optparse

optparse.Values.THIS_does_not_EXIST


def test_ignored_classes_only_name() -> None:
"""Test that ignored_classes works with the name only."""
import optparse

optparse.Option.THIS_does_not_EXIST
3 changes: 3 additions & 0 deletions tests/functional/n/no/no_member_imports.rc
@@ -0,0 +1,3 @@
[TYPECHECK]
ignored-modules=argparse,xml.etree.,collections.abc*
ignored-classes=sys*,optparse.Values,Option
3 changes: 3 additions & 0 deletions tests/functional/n/no/no_member_imports.txt
@@ -0,0 +1,3 @@
no-member:10:4:10:28:test_no_member_in_getattr:Module 'math' has no 'THIS_does_not_EXIST' member:INFERENCE
no-member:25:4:25:33:test_ignored_modules_invalid_pattern:Module 'xml.etree' has no 'THIS_does_not_EXIST' member:INFERENCE
no-member:44:4:44:27:test_ignored_classes_no_recursive_pattern:Module 'sys' has no 'THIS_does_not_EXIST' member:INFERENCE