From 7be7e92031f85f2371b1e23e04b40f0629dd9fb1 Mon Sep 17 00:00:00 2001 From: Laura M?dioni Date: Thu, 12 Nov 2015 13:43:22 +0100 Subject: slightly change wrong-import-position message and add forgotten functional test related to issue #692 --- pylint/checkers/imports.py | 4 ++-- pylint/test/functional/wrong_import_position.py | 21 +++++++++++++++++++++ pylint/test/functional/wrong_import_position.txt | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pylint/test/functional/wrong_import_position.py create mode 100644 pylint/test/functional/wrong_import_position.txt 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 -- cgit v1.2.1