From e14596ef44db6efd55c783fc5bffd61d020edc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 3 Dec 2021 13:45:08 +0100 Subject: Move ``no-member`` tests from ``TestTypeChecker`` (#5453) * Do not use collections or dataclasses for check --- tests/functional/n/no/no_member_imports.py | 59 +++++++++++++++++++++++++++++ tests/functional/n/no/no_member_imports.rc | 3 ++ tests/functional/n/no/no_member_imports.txt | 3 ++ 3 files changed, 65 insertions(+) create mode 100644 tests/functional/n/no/no_member_imports.py create mode 100644 tests/functional/n/no/no_member_imports.rc create mode 100644 tests/functional/n/no/no_member_imports.txt (limited to 'tests/functional/n/no') diff --git a/tests/functional/n/no/no_member_imports.py b/tests/functional/n/no/no_member_imports.py new file mode 100644 index 000000000..ead6d9335 --- /dev/null +++ b/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 diff --git a/tests/functional/n/no/no_member_imports.rc b/tests/functional/n/no/no_member_imports.rc new file mode 100644 index 000000000..59db427c2 --- /dev/null +++ b/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 diff --git a/tests/functional/n/no/no_member_imports.txt b/tests/functional/n/no/no_member_imports.txt new file mode 100644 index 000000000..477558597 --- /dev/null +++ b/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 -- cgit v1.2.1