summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-12-07 15:40:25 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-12-07 15:40:25 +0200
commit403df92d1710267ae5b7fe215acd9357a8cbf251 (patch)
treecc7337fb8a9f088550531dc3bb1204e643982ffc /pylint/test
parent1fc333e90d0328f878c8a58084eb2cba536d0b4b (diff)
parent9e0620833d014a0c8d34b6bf8c908e01b3ac7e70 (diff)
downloadpylint-403df92d1710267ae5b7fe215acd9357a8cbf251.tar.gz
Merged in jakirkham/pylint/issue_538_pt2 (pull request #315)
Add another check of the current working directory for `.pylintrc`.
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/functional/super_checks.py2
-rw-r--r--pylint/test/functional/super_checks.txt27
-rw-r--r--pylint/test/functional/syntax_error.txt2
-rw-r--r--pylint/test/functional/unknown_encoding_py29.txt2
-rw-r--r--pylint/test/functional/wrong_import_position.py16
-rw-r--r--pylint/test/functional/wrong_import_position.txt6
-rw-r--r--pylint/test/regrtest_data/beyond_top/__init__.py6
-rw-r--r--pylint/test/regrtest_data/beyond_top/data.py1
-rw-r--r--pylint/test/unittest_checker_imports.py22
-rw-r--r--pylint/test/unittest_checker_stdlib.py65
10 files changed, 127 insertions, 22 deletions
diff --git a/pylint/test/functional/super_checks.py b/pylint/test/functional/super_checks.py
index 14fd5a2..f4aec0a 100644
--- a/pylint/test/functional/super_checks.py
+++ b/pylint/test/functional/super_checks.py
@@ -65,9 +65,9 @@ class SuperDifferentScope(object):
class UnknownBases(Missing):
"""Don't emit if we don't know all the bases."""
def __init__(self):
- # pylint: disable=super-on-old-class
super(UnknownBases, self).__init__()
super(UnknownBases, self).test()
+ super(Missing, self).test() # [bad-super-call]
# Test that we are detecting proper super errors.
diff --git a/pylint/test/functional/super_checks.txt b/pylint/test/functional/super_checks.txt
index a98a25b..ea1d67b 100644
--- a/pylint/test/functional/super_checks.txt
+++ b/pylint/test/functional/super_checks.txt
@@ -1,18 +1,19 @@
old-style-class:6:Aaaa:Old-style class defined.
-super-on-old-class:8:Aaaa.hop:Use of super on an old style class:INFERENCE
+super-on-old-class:8:Aaaa.hop:Use of super on an old style class
no-member:10:Aaaa.hop:Super of 'Aaaa' has no 'hop' member:INFERENCE
-super-on-old-class:12:Aaaa.__init__:Use of super on an old style class:INFERENCE
+super-on-old-class:12:Aaaa.__init__:Use of super on an old style class
no-member:19:NewAaaa.hop:Super of 'NewAaaa' has no 'hop' member:INFERENCE
-bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super():INFERENCE
-missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super():INFERENCE
-bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
-bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super():INFERENCE
-bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super():INFERENCE
-bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super():INFERENCE
-not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable:HIGH
+bad-super-call:22:NewAaaa.__init__:Bad first argument 'Aaaa' given to super()
+missing-super-argument:27:Py3kAaaa.__init__:Missing argument to super()
+bad-super-call:32:Py3kWrongSuper.__init__:Bad first argument 'NewAaaa' given to super()
+bad-super-call:37:WrongNameRegression.__init__:Bad first argument 'Missing' given to super()
+bad-super-call:46:CrashSuper.__init__:Bad first argument 'NewAaaa' given to super()
+bad-super-call:62:SuperDifferentScope.test:Bad first argument 'object' given to super()
+bad-super-call:70:UnknownBases.__init__:Bad first argument 'Missing' given to super()
+not-callable:89:InvalidSuperChecks.__init__:super(InvalidSuperChecks, self).not_a_method is not callable
no-member:90:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE
-no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH
-too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call:HIGH
-no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call:HIGH
-unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call:HIGH
+no-value-for-parameter:92:InvalidSuperChecks.__init__:No value for argument 'param' in method call
+too-many-function-args:93:InvalidSuperChecks.__init__:Too many positional arguments for method call
+no-value-for-parameter:95:InvalidSuperChecks.__init__:No value for argument 'param' in method call
+unexpected-keyword-arg:95:InvalidSuperChecks.__init__:Unexpected keyword argument 'lala' in method call
no-member:98:InvalidSuperChecks.__init__:Super of 'InvalidSuperChecks' has no 'attribute_error' member:INFERENCE \ No newline at end of file
diff --git a/pylint/test/functional/syntax_error.txt b/pylint/test/functional/syntax_error.txt
index b57bc72..76abba8 100644
--- a/pylint/test/functional/syntax_error.txt
+++ b/pylint/test/functional/syntax_error.txt
@@ -1 +1 @@
-syntax-error:1::invalid syntax \ No newline at end of file
+syntax-error:1::invalid syntax (<string>, line 1) \ No newline at end of file
diff --git a/pylint/test/functional/unknown_encoding_py29.txt b/pylint/test/functional/unknown_encoding_py29.txt
index 588b3bf..20e7757 100644
--- a/pylint/test/functional/unknown_encoding_py29.txt
+++ b/pylint/test/functional/unknown_encoding_py29.txt
@@ -1 +1 @@
-syntax-error:1::"unknown encoding: IBO-8859-1"
+syntax-error:1::"unknown encoding: IBO-8859-1 (<string>, line 0)"
diff --git a/pylint/test/functional/wrong_import_position.py b/pylint/test/functional/wrong_import_position.py
index 1547ff2..269d757 100644
--- a/pylint/test/functional/wrong_import_position.py
+++ b/pylint/test/functional/wrong_import_position.py
@@ -1,13 +1,25 @@
"""Checks import order rule"""
# pylint: disable=unused-import,relative-import,ungrouped-imports,wrong-import-order,using-constant-test
-# pylint: disable=import-error
+# pylint: disable=import-error, too-few-public-methods, missing-docstring
import os.path
+
if True:
from astroid import are_exclusive
try:
import sys
except ImportError:
- import datetime
+ 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
CONSTANT = True
diff --git a/pylint/test/functional/wrong_import_position.txt b/pylint/test/functional/wrong_import_position.txt
index 2f417e4..5cde17d 100644
--- a/pylint/test/functional/wrong_import_position.txt
+++ b/pylint/test/functional/wrong_import_position.txt
@@ -1,3 +1,3 @@
-wrong-import-position:14::Import "import datetime" should be placed at the top of the module
-wrong-import-position:20::Import "import scipy" should be placed at the top of the module
-wrong-import-position:21::Import "import astroid" should be placed at the top of the module
+wrong-import-position:26::Import "import datetime" should be placed at the top of the module
+wrong-import-position:32::Import "import scipy" should be placed at the top of the module
+wrong-import-position:33::Import "import astroid" should be placed at the top of the module
diff --git a/pylint/test/regrtest_data/beyond_top/__init__.py b/pylint/test/regrtest_data/beyond_top/__init__.py
new file mode 100644
index 0000000..401fe06
--- /dev/null
+++ b/pylint/test/regrtest_data/beyond_top/__init__.py
@@ -0,0 +1,6 @@
+from ... import Something
+from . import data
+try:
+ from ... import Lala
+except ImportError:
+ pass \ No newline at end of file
diff --git a/pylint/test/regrtest_data/beyond_top/data.py b/pylint/test/regrtest_data/beyond_top/data.py
new file mode 100644
index 0000000..9ec64d2
--- /dev/null
+++ b/pylint/test/regrtest_data/beyond_top/data.py
@@ -0,0 +1 @@
+Anything = 42 \ No newline at end of file
diff --git a/pylint/test/unittest_checker_imports.py b/pylint/test/unittest_checker_imports.py
index f5e6bbb..0069be2 100644
--- a/pylint/test/unittest_checker_imports.py
+++ b/pylint/test/unittest_checker_imports.py
@@ -1,6 +1,8 @@
"""Unit tests for the imports checker."""
+import os
import unittest
+import astroid
from astroid import test_utils
from pylint.checkers import imports
from pylint.testutils import CheckerTestCase, Message, set_config
@@ -62,7 +64,7 @@ class ImportsCheckerTC(CheckerTestCase):
with self.assertNoMessages():
self.checker.visit_import(node)
- def test_visit_importfrom(self):
+ def test_reimported_same_line(self):
"""
Test that duplicate imports on single line raise 'reimported'.
"""
@@ -71,5 +73,23 @@ class ImportsCheckerTC(CheckerTestCase):
with self.assertAddsMessages(msg):
self.checker.visit_importfrom(node)
+ def test_relative_beyond_top_level(self):
+ here = os.path.abspath(os.path.dirname(__file__))
+ path = os.path.join(here, 'regrtest_data', 'beyond_top', '__init__.py')
+ with open(path) as stream:
+ data = stream.read()
+ module = astroid.parse(data, module_name='beyond_top', path=path)
+ import_from = module.body[0]
+
+ msg = Message(msg_id='relative-beyond-top-level',
+ node=import_from)
+ with self.assertAddsMessages(msg):
+ self.checker.visit_importfrom(import_from)
+ with self.assertNoMessages():
+ self.checker.visit_importfrom(module.body[1])
+ with self.assertNoMessages():
+ self.checker.visit_importfrom(module.body[2].body[0])
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/pylint/test/unittest_checker_stdlib.py b/pylint/test/unittest_checker_stdlib.py
new file mode 100644
index 0000000..82c1f17
--- /dev/null
+++ b/pylint/test/unittest_checker_stdlib.py
@@ -0,0 +1,65 @@
+# Copyright (c) 2003-2015 LOGILAB S.A. (Paris, FRANCE).
+# http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+import contextlib
+import unittest
+
+import astroid
+from astroid import test_utils
+
+from pylint.checkers import stdlib
+from pylint.testutils import CheckerTestCase
+
+
+@contextlib.contextmanager
+def _add_transform(manager, node, transform, predicate=None):
+ manager.register_transform(node, transform, predicate)
+ try:
+ yield
+ finally:
+ manager.unregister_transform(node, transform, predicate)
+
+
+class StdlibCheckerTest(CheckerTestCase):
+ CHECKER_CLASS = stdlib.StdlibChecker
+
+ def test_deprecated_no_qname_on_unexpected_nodes(self):
+ # Test that we don't crash on nodes which don't have
+ # a qname method. While this test might seem weird since
+ # it uses a transform, it's actually testing a crash that
+ # happened in production, but there was no way to retrieve
+ # the code for which this occurred (how an AssignAttr
+ # got to be the result of a function inference
+ # beats me..)
+
+ def infer_func(node, context=None):
+ new_node = astroid.AssignAttr()
+ new_node.parent = node
+ yield new_node
+
+ manager = astroid.MANAGER
+ transform = astroid.inference_tip(infer_func)
+ with _add_transform(manager, astroid.Name, transform):
+ node = test_utils.extract_node('''
+ call_something()
+ ''')
+ with self.assertNoMessages():
+ self.checker.visit_call(node)
+
+
+
+if __name__ == '__main__':
+ unittest.main()