diff options
Diffstat (limited to 'tests/functional/w')
36 files changed, 277 insertions, 0 deletions
diff --git a/tests/functional/w/__init__.py b/tests/functional/w/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/functional/w/__init__.py diff --git a/tests/functional/w/wildcard_import.py b/tests/functional/w/wildcard_import.py new file mode 100644 index 000000000..4034162e0 --- /dev/null +++ b/tests/functional/w/wildcard_import.py @@ -0,0 +1,5 @@ +# pylint: disable=missing-docstring,import-error,unused-wildcard-import +from indirect1 import * # [wildcard-import] +# This is an unresolved import which still generates the wildcard-import +# warning. +from unknown.package import * # [wildcard-import] diff --git a/tests/functional/w/wildcard_import.txt b/tests/functional/w/wildcard_import.txt new file mode 100644 index 000000000..67721a6e5 --- /dev/null +++ b/tests/functional/w/wildcard_import.txt @@ -0,0 +1,2 @@ +wildcard-import:2:0::Wildcard import indirect1 +wildcard-import:5:0::Wildcard import unknown.package diff --git a/tests/functional/w/wildcard_import_allowed.py b/tests/functional/w/wildcard_import_allowed.py new file mode 100644 index 000000000..21fea4738 --- /dev/null +++ b/tests/functional/w/wildcard_import_allowed.py @@ -0,0 +1,4 @@ +# pylint: disable=missing-docstring,unused-wildcard-import,redefined-builtin,import-error +from csv import * +from abc import * # [wildcard-import] +from UNINFERABLE import * # [wildcard-import] diff --git a/tests/functional/w/wildcard_import_allowed.rc b/tests/functional/w/wildcard_import_allowed.rc new file mode 100644 index 000000000..c46d828f6 --- /dev/null +++ b/tests/functional/w/wildcard_import_allowed.rc @@ -0,0 +1,2 @@ +[IMPORTS] +allow-wildcard-with-all=yes diff --git a/tests/functional/w/wildcard_import_allowed.txt b/tests/functional/w/wildcard_import_allowed.txt new file mode 100644 index 000000000..6413af27a --- /dev/null +++ b/tests/functional/w/wildcard_import_allowed.txt @@ -0,0 +1,2 @@ +wildcard-import:3:0::Wildcard import abc +wildcard-import:4:0::Wildcard import UNINFERABLE diff --git a/tests/functional/w/with_used_before_assign.py b/tests/functional/w/with_used_before_assign.py new file mode 100644 index 000000000..ebe7d3093 --- /dev/null +++ b/tests/functional/w/with_used_before_assign.py @@ -0,0 +1,12 @@ +""" +Regression test for +https://bitbucket.org/logilab/pylint/issue/128/attributeerror-when-parsing +""" +from __future__ import with_statement + + +def do_nothing(): + """ empty """ + with open("", encoding="utf-8") as ctx.obj: # [undefined-variable] + context.do() # [used-before-assignment] + context = None diff --git a/tests/functional/w/with_used_before_assign.txt b/tests/functional/w/with_used_before_assign.txt new file mode 100644 index 000000000..8e1fe1be8 --- /dev/null +++ b/tests/functional/w/with_used_before_assign.txt @@ -0,0 +1,2 @@ +undefined-variable:10:39:do_nothing:Undefined variable 'ctx' +used-before-assignment:11:8:do_nothing:Using variable 'context' before assignment diff --git a/tests/functional/w/with_using_generator.py b/tests/functional/w/with_using_generator.py new file mode 100644 index 000000000..187bdcfea --- /dev/null +++ b/tests/functional/w/with_using_generator.py @@ -0,0 +1,15 @@ +""" Testing with statements that use generators. This should not crash. """ +# pylint: disable=useless-object-inheritance + +class Base(object): + """ Base class. """ + val = 0 + + def gen(self): + """ A generator. """ + yield self.val + + def fun(self): + """ With statement using a generator. """ + with self.gen(): # [not-context-manager] + pass diff --git a/tests/functional/w/with_using_generator.txt b/tests/functional/w/with_using_generator.txt new file mode 100644 index 000000000..6bd65fbe7 --- /dev/null +++ b/tests/functional/w/with_using_generator.txt @@ -0,0 +1 @@ +not-context-manager:14:8:Base.fun:Context manager 'generator' doesn't implement __enter__ and __exit__. diff --git a/tests/functional/w/wrong_exception_operation.py b/tests/functional/w/wrong_exception_operation.py new file mode 100644 index 000000000..1c3c4e380 --- /dev/null +++ b/tests/functional/w/wrong_exception_operation.py @@ -0,0 +1,18 @@ +# pylint: disable=missing-docstring, superfluous-parens + + +try: + 1/0 +except (ValueError | TypeError): # [wrong-exception-operation] + pass + +try: + 1/0 +except (ValueError + TypeError): # [wrong-exception-operation] + pass + + +try: + 1/0 +except (ValueError < TypeError): # [wrong-exception-operation] + pass diff --git a/tests/functional/w/wrong_exception_operation.txt b/tests/functional/w/wrong_exception_operation.txt new file mode 100644 index 000000000..05624a3a0 --- /dev/null +++ b/tests/functional/w/wrong_exception_operation.txt @@ -0,0 +1,3 @@ +wrong-exception-operation:6:8::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead? +wrong-exception-operation:11:8::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead? +wrong-exception-operation:17:8::Invalid exception operation. Did you mean '(ValueError, TypeError)' instead? diff --git a/tests/functional/w/wrong_import_order.py b/tests/functional/w/wrong_import_order.py new file mode 100644 index 000000000..ed0615b0c --- /dev/null +++ b/tests/functional/w/wrong_import_order.py @@ -0,0 +1,43 @@ +"""Checks import order rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level +from __future__ import absolute_import +try: + from six.moves import configparser +except ImportError: + import configparser + +import logging + +import six +import os.path # [wrong-import-order] +from astroid import are_exclusive +import sys # [wrong-import-order] +import datetime # [wrong-import-order] +import unused_import +from .package import Class +import totally_missing # [wrong-import-order] +from . import package +import astroid # [wrong-import-order] +from . import package2 +from .package2 import Class2 +from ..package3 import Class3 +from six.moves.urllib.parse import quote # [wrong-import-order] + + +LOGGER = logging.getLogger(__name__) + + +if LOGGER: + # imports nested skipped + from . import package4 + import pprint + from pprint import PrettyPrinter + + +try: + # imports nested skipped + from . import package4 + import random + from random import division +except ImportError: + LOGGER.info('A useful message here') diff --git a/tests/functional/w/wrong_import_order.txt b/tests/functional/w/wrong_import_order.txt new file mode 100644 index 000000000..e520ef219 --- /dev/null +++ b/tests/functional/w/wrong_import_order.txt @@ -0,0 +1,6 @@ +wrong-import-order:12:0::"standard import ""import os.path"" should be placed before ""import six""" +wrong-import-order:14:0::"standard import ""import sys"" should be placed before ""import six""" +wrong-import-order:15:0::"standard import ""import datetime"" should be placed before ""import six""" +wrong-import-order:18:0::"third party import ""import totally_missing"" should be placed before ""from .package import Class""" +wrong-import-order:20:0::"third party import ""import astroid"" should be placed before ""from .package import Class""" +wrong-import-order:24:0::"third party import ""from six.moves.urllib.parse import quote"" should be placed before ""from .package import Class""" diff --git a/tests/functional/w/wrong_import_order2.py b/tests/functional/w/wrong_import_order2.py new file mode 100644 index 000000000..7157512dd --- /dev/null +++ b/tests/functional/w/wrong_import_order2.py @@ -0,0 +1,16 @@ +"""Checks import order rule in a right case""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module + + +# Standard imports +import os +from sys import argv + +# external imports +import isort + +from six import moves + +# local_imports +from . import my_package +from .my_package import myClass diff --git a/tests/functional/w/wrong_import_position.py b/tests/functional/w/wrong_import_position.py new file mode 100644 index 000000000..c06f9da1f --- /dev/null +++ b/tests/functional/w/wrong_import_position.py @@ -0,0 +1,33 @@ +"""Checks import order rule""" +# pylint: disable=unused-import,ungrouped-imports,wrong-import-order +# pylint: disable=import-error, too-few-public-methods, missing-docstring,using-constant-test, useless-object-inheritance +import os.path + +if True: + from astroid import are_exclusive +try: + import sys +except ImportError: + class Myclass(object): + """docstring""" + +if sys.version_info[0] >= 3: + from collections import OrderedDict +else: + class OrderedDict(object): + """Nothing to see here.""" + def some_func(self): + pass + +import six # [wrong-import-position] + +CONSTANT = True + +import datetime # [wrong-import-position] + +VAR = 0 +for i in range(10): + VAR += i + +import scipy # [wrong-import-position] +import astroid # [wrong-import-position] diff --git a/tests/functional/w/wrong_import_position.txt b/tests/functional/w/wrong_import_position.txt new file mode 100644 index 000000000..22c426726 --- /dev/null +++ b/tests/functional/w/wrong_import_position.txt @@ -0,0 +1,4 @@ +wrong-import-position:22:0::"Import ""import six"" should be placed at the top of the module" +wrong-import-position:26:0::"Import ""import datetime"" should be placed at the top of the module" +wrong-import-position:32:0::"Import ""import scipy"" should be placed at the top of the module" +wrong-import-position:33:0::"Import ""import astroid"" should be placed at the top of the module" diff --git a/tests/functional/w/wrong_import_position10.py b/tests/functional/w/wrong_import_position10.py new file mode 100644 index 000000000..f4a868039 --- /dev/null +++ b/tests/functional/w/wrong_import_position10.py @@ -0,0 +1,15 @@ +"""Checks import position rule""" +# pylint: disable=unused-import +import os + +try: + import ast +except ImportError: + def method(items): + """docstring""" + value = 0 + for item in items: + value += item + return value + +import sys diff --git a/tests/functional/w/wrong_import_position11.py b/tests/functional/w/wrong_import_position11.py new file mode 100644 index 000000000..9af72c0e5 --- /dev/null +++ b/tests/functional/w/wrong_import_position11.py @@ -0,0 +1,4 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,pointless-string-statement +A = 1 +import os # [wrong-import-position] diff --git a/tests/functional/w/wrong_import_position11.txt b/tests/functional/w/wrong_import_position11.txt new file mode 100644 index 000000000..a08aaa95c --- /dev/null +++ b/tests/functional/w/wrong_import_position11.txt @@ -0,0 +1 @@ +wrong-import-position:4:0::"Import ""import os"" should be placed at the top of the module" diff --git a/tests/functional/w/wrong_import_position12.py b/tests/functional/w/wrong_import_position12.py new file mode 100644 index 000000000..300968c40 --- /dev/null +++ b/tests/functional/w/wrong_import_position12.py @@ -0,0 +1,5 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,pointless-string-statement +"Two string" + +import os # [wrong-import-position] diff --git a/tests/functional/w/wrong_import_position12.txt b/tests/functional/w/wrong_import_position12.txt new file mode 100644 index 000000000..ca655ff5b --- /dev/null +++ b/tests/functional/w/wrong_import_position12.txt @@ -0,0 +1 @@ +wrong-import-position:5:0::"Import ""import os"" should be placed at the top of the module" diff --git a/tests/functional/w/wrong_import_position13.py b/tests/functional/w/wrong_import_position13.py new file mode 100644 index 000000000..6b3d03463 --- /dev/null +++ b/tests/functional/w/wrong_import_position13.py @@ -0,0 +1,4 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,no-name-in-module +A = 1 +from sys import x # [wrong-import-position] diff --git a/tests/functional/w/wrong_import_position13.txt b/tests/functional/w/wrong_import_position13.txt new file mode 100644 index 000000000..5010d9db4 --- /dev/null +++ b/tests/functional/w/wrong_import_position13.txt @@ -0,0 +1 @@ +wrong-import-position:4:0::"Import ""from sys import x"" should be placed at the top of the module" diff --git a/tests/functional/w/wrong_import_position14.py b/tests/functional/w/wrong_import_position14.py new file mode 100644 index 000000000..f5c9a03e5 --- /dev/null +++ b/tests/functional/w/wrong_import_position14.py @@ -0,0 +1,5 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,undefined-variable,import-error +if x: + import os +import y # [wrong-import-position] diff --git a/tests/functional/w/wrong_import_position14.txt b/tests/functional/w/wrong_import_position14.txt new file mode 100644 index 000000000..22e09e25a --- /dev/null +++ b/tests/functional/w/wrong_import_position14.txt @@ -0,0 +1 @@ +wrong-import-position:5:0::"Import ""import y"" should be placed at the top of the module" diff --git a/tests/functional/w/wrong_import_position15.py b/tests/functional/w/wrong_import_position15.py new file mode 100644 index 000000000..58a19b66c --- /dev/null +++ b/tests/functional/w/wrong_import_position15.py @@ -0,0 +1,9 @@ +"""Checks import position rule with pep-0008""" +# pylint: disable=unused-import + +__author__ = 'some author' +__email__ = 'some.author@some_email' +__copyright__ = 'Some copyright' + + +import sys diff --git a/tests/functional/w/wrong_import_position2.py b/tests/functional/w/wrong_import_position2.py new file mode 100644 index 000000000..d7441b465 --- /dev/null +++ b/tests/functional/w/wrong_import_position2.py @@ -0,0 +1,10 @@ +"""Checks import order rule with nested non_import sentence""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level +try: + from sys import argv +except ImportError: + pass +else: + pass + +import os diff --git a/tests/functional/w/wrong_import_position3.py b/tests/functional/w/wrong_import_position3.py new file mode 100644 index 000000000..a1808a8fd --- /dev/null +++ b/tests/functional/w/wrong_import_position3.py @@ -0,0 +1,3 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level +import os diff --git a/tests/functional/w/wrong_import_position4.py b/tests/functional/w/wrong_import_position4.py new file mode 100644 index 000000000..96f39ce8d --- /dev/null +++ b/tests/functional/w/wrong_import_position4.py @@ -0,0 +1,5 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level,unused-variable,import-outside-toplevel +def method1(): + """Method 1""" + import x diff --git a/tests/functional/w/wrong_import_position5.py b/tests/functional/w/wrong_import_position5.py new file mode 100644 index 000000000..ff9c28cd7 --- /dev/null +++ b/tests/functional/w/wrong_import_position5.py @@ -0,0 +1,4 @@ +r"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level + +import os diff --git a/tests/functional/w/wrong_import_position6.py b/tests/functional/w/wrong_import_position6.py new file mode 100644 index 000000000..e719d2cb9 --- /dev/null +++ b/tests/functional/w/wrong_import_position6.py @@ -0,0 +1,7 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level,undefined-variable + +import y + +if x: + import os diff --git a/tests/functional/w/wrong_import_position7.py b/tests/functional/w/wrong_import_position7.py new file mode 100644 index 000000000..58a79b84b --- /dev/null +++ b/tests/functional/w/wrong_import_position7.py @@ -0,0 +1,9 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level +try: + import x +except ImportError: + pass +finally: + pass +import y diff --git a/tests/functional/w/wrong_import_position8.py b/tests/functional/w/wrong_import_position8.py new file mode 100644 index 000000000..531d9ca5f --- /dev/null +++ b/tests/functional/w/wrong_import_position8.py @@ -0,0 +1,4 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level,undefined-variable +if x: + import os diff --git a/tests/functional/w/wrong_import_position9.py b/tests/functional/w/wrong_import_position9.py new file mode 100644 index 000000000..232c453cc --- /dev/null +++ b/tests/functional/w/wrong_import_position9.py @@ -0,0 +1,9 @@ +"""Checks import position rule""" +# pylint: disable=unused-import,ungrouped-imports,import-error,no-name-in-module,relative-beyond-top-level +import y +try: + import x +except ImportError: + pass +else: + pass diff --git a/tests/functional/w/wrong_import_position_exclude_dunder_main.py b/tests/functional/w/wrong_import_position_exclude_dunder_main.py new file mode 100644 index 000000000..05f680377 --- /dev/null +++ b/tests/functional/w/wrong_import_position_exclude_dunder_main.py @@ -0,0 +1,12 @@ +# pylint: disable=import-error, unused-import, missing-docstring +CONS = 42 + +if __name__ == '__main__': + CONSTANT = True + VAR = 0 + for i in range(10): + VAR += i + + import six + import datetime + import astroid |