summaryrefslogtreecommitdiff
path: root/pylint/test
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-11-30 00:46:56 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-11-30 00:46:56 +0200
commita56f16b7a7e5b7b40a9d613e8cbec671a052f9e3 (patch)
tree442a49272532e2d8f0d00149772de90eda092920 /pylint/test
parentb751e27cab545061149f1714e96449dfc1d60a9d (diff)
downloadpylint-a56f16b7a7e5b7b40a9d613e8cbec671a052f9e3.tar.gz
Add wrong-import-position to check_messages's decorator arguments for ImportChecker.leave_module
This fixes an esoteric bug which occurs when ungrouped-imports and wrong-import-order are disabled and pylint is executed on multiple files. What happens is that without wrong-import-position in check_messages, leave_module will never be called, which means that the first non-import node from other files might leak into the current file, leading to wrong-import-position being emitted by pylint.
Diffstat (limited to 'pylint/test')
-rw-r--r--pylint/test/regrtest_data/import_something.py4
-rw-r--r--pylint/test/regrtest_data/wrong_import_position.py11
-rw-r--r--pylint/test/test_self.py22
3 files changed, 36 insertions, 1 deletions
diff --git a/pylint/test/regrtest_data/import_something.py b/pylint/test/regrtest_data/import_something.py
new file mode 100644
index 0000000..3a74a71
--- /dev/null
+++ b/pylint/test/regrtest_data/import_something.py
@@ -0,0 +1,4 @@
+# pylint: disable=missing-docstring,unused-import
+
+import os
+import sys
diff --git a/pylint/test/regrtest_data/wrong_import_position.py b/pylint/test/regrtest_data/wrong_import_position.py
new file mode 100644
index 0000000..9e2d099
--- /dev/null
+++ b/pylint/test/regrtest_data/wrong_import_position.py
@@ -0,0 +1,11 @@
+"""Test that wrong-import-position is properly reset when
+other errors are disabled.
+"""
+# pylint: disable=unused-import, too-few-public-methods
+
+
+class Something(object):
+ """A class before an import."""
+
+
+import os
diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py
index 324cc16..69b739c 100644
--- a/pylint/test/test_self.py
+++ b/pylint/test/test_self.py
@@ -94,7 +94,9 @@ class RunTC(unittest.TestCase):
def _run_pylint(self, args, out, reporter=None):
with _patch_streams(out):
with self.assertRaises(SystemExit) as cm:
- Run(args, reporter=reporter)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ Run(args, reporter=reporter)
return cm.exception.code
def _test_output(self, args, expected_output):
@@ -270,6 +272,24 @@ class RunTC(unittest.TestCase):
module = join(HERE, 'regrtest_data', 'html_crash_420.py')
self._runtest([module], code=16, reporter=HTMLReporter(out))
+ def test_wrong_import_position_when_others_disabled(self):
+ expected_output = textwrap.dedent('''
+ No config file found, using default configuration
+ ************* Module wrong_import_position
+ C: 11, 0: Import "import os" should be placed at the top of the module (wrong-import-position)
+ ''')
+ module1 = join(HERE, 'regrtest_data', 'import_something.py')
+ module2 = join(HERE, 'regrtest_data', 'wrong_import_position.py')
+ args = [module2, module1,
+ "--disable=all", "--enable=wrong-import-position",
+ "-rn"]
+ out = six.StringIO()
+ self._run_pylint(args, out=out)
+ actual_output = out.getvalue()
+ self.assertEqual(expected_output.strip(), actual_output.strip())
+
+
+
if __name__ == '__main__':
unittest.main()