summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura M?dioni <laura.medioni@logilab.fr>2015-11-12 13:43:22 +0100
committerLaura M?dioni <laura.medioni@logilab.fr>2015-11-12 13:43:22 +0100
commit7be7e92031f85f2371b1e23e04b40f0629dd9fb1 (patch)
tree2d6316330f61aa2d63852841ae5c4556384e1b47
parent38fd37a36933409625f422cbd7b91740540e3172 (diff)
downloadpylint-7be7e92031f85f2371b1e23e04b40f0629dd9fb1.tar.gz
slightly change wrong-import-position message and add forgotten functional test
related to issue #692
-rw-r--r--pylint/checkers/imports.py4
-rw-r--r--pylint/test/functional/wrong_import_position.py21
-rw-r--r--pylint/test/functional/wrong_import_position.txt3
3 files changed, 26 insertions, 2 deletions
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index 480adde..8ff1962 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -187,7 +187,7 @@ MSGS = {
'C0412': ('Imports from package %s are not grouped',
'ungrouped-imports',
'Used when imports are not grouped by packages'),
- 'C0413': ('Wrong import position: %s should be placed at the top of the '
+ 'C0413': ('Import "%s" should be placed at the top of the '
'module',
'wrong-import-position',
'Used when code and imports are mixed'),
@@ -383,7 +383,7 @@ given file (report RP0402 must not be disabled)'}
"""Sends a message if import `node` comes after another piece of code"""
if self._first_non_import_node:
self.add_message('wrong-import-position', node=node,
- args='"%s"' % node.as_string())
+ args=node.as_string())
def _check_imports_order(self, node):
"""Checks imports of module `node` are grouped by category
diff --git a/pylint/test/functional/wrong_import_position.py b/pylint/test/functional/wrong_import_position.py
new file mode 100644
index 0000000..32a8314
--- /dev/null
+++ b/pylint/test/functional/wrong_import_position.py
@@ -0,0 +1,21 @@
+"""Checks import order rule"""
+# pylint: disable=unused-import,relative-import,ungrouped-imports,wrong-import-order,using-constant-test
+
+import os.path
+if True:
+ from astroid import are_exclusive
+try:
+ import sys
+except ImportError:
+ import datetime
+
+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/pylint/test/functional/wrong_import_position.txt b/pylint/test/functional/wrong_import_position.txt
new file mode 100644
index 0000000..2f417e4
--- /dev/null
+++ b/pylint/test/functional/wrong_import_position.txt
@@ -0,0 +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