Commit 53995c01 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

support pylint 1.7.2 and astroid 1.5.3.

parent 1ed317d1
......@@ -437,6 +437,7 @@ def checkPythonSourceCode(source_code_str):
try:
from pylint.lint import Run
from pylint.reporters.text import TextReporter
from pylint import __version__ as pylint_version
except ImportError, error:
try:
compile(source_code_str, '<string>', 'exec')
......@@ -475,7 +476,13 @@ def checkPythonSourceCode(source_code_str):
input_file.write(source_code_str)
input_file.seek(0)
Run([input_file.name, '--reports=n', '--indent-string=" "', '--zope=y',
if pylint_version > '1.7':
extra_arguments = ['--generated-members=REQUEST,acl_users,aq_parent',
'--load-plugins=pylint.extensions.bad_builtin',]
else:
# BBB
extra_arguments = ['--zope=y',]
Run([input_file.name, '--reports=n', '--indent-string=" "',
# Disable Refactoring and Convention messages which are too verbose
# TODO-arnau: Should perphaps check ERP5 Naming Conventions?
'--disable=R,C',
......@@ -510,7 +517,7 @@ def checkPythonSourceCode(source_code_str):
# 'Access to a protected member %s of a client class'
'--disable=W0212',
# string module does not only contain deprecated functions...
'--deprecated-modules=regsub,TERMIOS,Bastion,rexec'],
'--deprecated-modules=regsub,TERMIOS,Bastion,rexec'] + extra_arguments,
reporter=TextReporter(output_file), exit=False)
output_file.reset()
......
......@@ -24,13 +24,20 @@ from inspect import getargspec
try:
from pylint.checkers import imports
import astroid
try:
from astroid.exceptions import AstroidImportError, InconsistentMroError
except ImportError:
# BBB for astroid < 1.5
from astroid.exceptions import InferenceError as AstroidImportError
# BBB for astroid < 1.4
from astroid.exceptions import InferenceError as InconsistentMroError
except ImportError:
pass
else:
def _get_imported_module(self, importnode, modname):
try:
return importnode.do_import_module(modname)
except astroid.InferenceError, ex:
except (AstroidImportError, InconsistentMroError), ex:
# BEGIN
# XXX-arnau: Ignore ERP5 dynamic modules, hackish but required
......@@ -64,11 +71,15 @@ else:
args = repr(modname)
self.add_message("F0401", args=args, node=importnode)
if 'modnode' in getargspec(imports.ImportsChecker.get_imported_module).args:
# BBB for pylint < 1.4.0
def get_imported_module(self, modnode, importnode, modname):
return _get_imported_module(self, importnode, modname)
else:
get_imported_module = _get_imported_module
if hasattr(imports.ImportsChecker, 'get_imported_module'):
# BBB for pylint < 1.6.0
if 'modnode' in getargspec(imports.ImportsChecker.get_imported_module).args:
# BBB for pylint < 1.4.0
def get_imported_module(self, modnode, importnode, modname):
return _get_imported_module(self, importnode, modname)
else:
get_imported_module = _get_imported_module
imports.ImportsChecker.get_imported_module = get_imported_module
imports.ImportsChecker.get_imported_module = get_imported_module
else:
imports.ImportsChecker._get_imported_module = _get_imported_module
......@@ -30,6 +30,7 @@
import gc
import os
from pylint import __version__ as pylint_version
import shutil
import tempfile
import unittest
......@@ -1688,11 +1689,18 @@ class _TestZodbComponent(SecurityTestCase):
component.setTextContent('import unexistent_module')
self.tic()
self.assertEqual(
[m.getMessage().translate() for m in component.checkConsistency()],
["Error in Source Code: F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
self.assertEqual(component.getTextContentErrorMessageList(),
["F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
if pylint_version < '1.7': # BBB for pylint < 1.7
self.assertEqual(
[m.getMessage().translate() for m in component.checkConsistency()],
["Error in Source Code: F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
self.assertEqual(component.getTextContentErrorMessageList(),
["F: 1, 0: Unable to import 'unexistent_module' (import-error)"])
else:
self.assertEqual(
[m.getMessage().translate() for m in component.checkConsistency()],
["Error in Source Code: E: 1, 0: Unable to import 'unexistent_module' (Failed to import module unexistent_module with error:"])
self.assertEqual(component.getTextContentErrorMessageList(),
["E: 1, 0: Unable to import 'unexistent_module' (Failed to import module unexistent_module with error:"])
self.assertEqual(component.getTextContentWarningMessageList(),
["W: 1, 0: Unused import unexistent_module (unused-import)"])
......@@ -1725,16 +1733,24 @@ class _TestZodbComponent(SecurityTestCase):
[ComponentMixin._message_text_content_not_set],
[],
[]),
('def foobar(*args, **kwargs)\n return 42',
["Error in Source Code: E: 1, 0: invalid syntax (syntax-error)"],
["E: 1, 0: invalid syntax (syntax-error)"],
[]),
# Make sure that foobar NameError is at the end to make sure that after
# defining foobar function, it is not available at all
('foobar',
["Error in Source Code: E: 1, 0: Undefined variable 'foobar' (undefined-variable)"],
["E: 1, 0: Undefined variable 'foobar' (undefined-variable)"],
["W: 1, 0: Statement seems to have no effect (pointless-statement)"]))
if pylint_version < '1.7': # BBB for pylint < 1.7
invalid_code_dict += \
('def foobar(*args, **kwargs)\n return 42',
["Error in Source Code: E: 1, 0: invalid syntax (syntax-error)"],
["E: 1, 0: invalid syntax (syntax-error)"],
[]),
else:
invalid_code_dict += \
('def foobar(*args, **kwargs)\n return 42',
["Error in Source Code: E: 1, 0: invalid syntax (<string>, line 1) (syntax-error)"],
["E: 1, 0: invalid syntax (<string>, line 1) (syntax-error)"],
[]),
for (invalid_code,
check_consistency_list,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment