Skip to content

Commit

Permalink
[FIX] test-folder-imported: check if node has a modname as attribute
Browse files Browse the repository at this point in the history
In python versions above 3.5, an error occurs when try to get 'modname' from node.
  • Loading branch information
fernandahf committed Jan 19, 2021
1 parent 9504bf0 commit ab6d7ca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions pylint_odoo/checkers/modules_odoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,14 @@ def check_odoo_relative_import(self, node):

def check_folder_test_imported(self, node):
if (hasattr(node.parent, 'file')
and os.path.basename(node.parent.file) == '__init__.py'
and ("tests" in [item for item, _ in node.names]
or "tests" in node.modname)):
self.add_message('test-folder-imported', node=node,
args=(node.parent.name,))
and os.path.basename(node.parent.file) == '__init__.py'):
if isinstance(node, astroid.ImportFrom):
package_names = node.modname.split('.')[:1]
elif isinstance(node, astroid.Import):
package_names = [name[0].split('.')[0] for name in node.names]
if "tests" in package_names:
self.add_message('test-folder-imported', node=node,
args=(node.parent.name,))

@staticmethod
def _is_absolute_import(node, name):
Expand Down
4 changes: 2 additions & 2 deletions pylint_odoo/test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
'method-inverse': 1,
'method-required-super': 8,
'method-search': 1,
'missing-import-error': 7,
'missing-manifest-dependency': 5,
'missing-import-error': 8,
'missing-manifest-dependency': 6,
'missing-newline-extrafiles': 4,
'missing-readme': 1,
'missing-return': 1,
Expand Down
2 changes: 1 addition & 1 deletion pylint_odoo/test_repo/eleven_module/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import models
from . import utf8_models
from .tests import test_model1
import tests

0 comments on commit ab6d7ca

Please sign in to comment.