diff options
author | Petr Viktorin <pviktori@redhat.com> | 2014-12-16 14:45:37 +0100 |
---|---|---|
committer | Tomas Babej <tbabej@redhat.com> | 2015-01-14 11:40:28 +0100 |
commit | 61c4ecccc1df222b153236518c9be0ac3091f94a (patch) | |
tree | f8d222fee1c359c1e7403ab914ed7f619139e721 /make-lint | |
parent | 10fe918acd8f7428588f2dff52f64070a9328c29 (diff) | |
download | freeipa-61c4ecccc1df222b153236518c9be0ac3091f94a.tar.gz freeipa-61c4ecccc1df222b153236518c9be0ac3091f94a.tar.xz freeipa-61c4ecccc1df222b153236518c9be0ac3091f94a.zip |
Run pylint on tests
Drop support for pylint < 1.0
Enable ignoring unknown attributes on modules (both nose and pytest
use advanced techniques, support for which only made it to pylint
recently)
Fix some bugs revealed by pylint
Do minor refactoring or add pylint:disable directives where the
linter complains.
Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'make-lint')
-rwxr-xr-x | make-lint | 47 |
1 files changed, 21 insertions, 26 deletions
@@ -29,24 +29,16 @@ try: from pylint import checkers from pylint.lint import PyLinter from pylint.checkers.typecheck import TypeChecker - try: - # Pylint 1.0 - from astroid import Class, Instance, InferenceError - from pylint.reporters.text import TextReporter - have_pylint_1_0 = True - except ImportError: - # Older Pylint - from logilab.astng import Class, Instance, InferenceError - from pylint.reporters.text import ParseableTextReporter - have_pylint_1_0 = False + from astroid import Class, Instance, Module, InferenceError + from pylint.reporters.text import TextReporter except ImportError: print >> sys.stderr, "To use {0}, please install pylint.".format(sys.argv[0]) sys.exit(32) # File names to ignore when searching for python source files IGNORE_FILES = ('.*', '*~', '*.in', '*.pyc', '*.pyo') -IGNORE_PATHS = ('build', 'rpmbuild', 'dist', 'install/po/test_i18n.py', - 'lite-server.py', 'make-lint', 'make-test', 'ipatests') +IGNORE_PATHS = ( + 'build', 'rpmbuild', 'dist', 'install/po/test_i18n.py', 'lite-server.py') class IPATypeChecker(TypeChecker): NAMESPACE_ATTRS = ['Command', 'Object', 'Method', 'Backend', 'Updater', @@ -54,7 +46,7 @@ class IPATypeChecker(TypeChecker): LOGGING_ATTRS = ['log', 'debug', 'info', 'warning', 'error', 'exception', 'critical'] - # 'class': ['generated', 'properties'] + # 'class or module': ['generated', 'properties'] ignore = { # Python standard library & 3rd party classes 'krbV.Principal': ['name'], @@ -65,6 +57,9 @@ class IPATypeChecker(TypeChecker): 'urlparse.ResultMixin': ['scheme', 'netloc', 'path', 'query', 'fragment', 'username', 'password', 'hostname', 'port'], 'urlparse.ParseResult': ['params'], + 'pytest': ['fixture', 'raises', 'skip', 'yield_fixture', 'mark'], + 'nose.tools': ['assert_equal', 'assert_raises'], + 'datetime.tzinfo': ['houroffset', 'minoffset', 'utcoffset', 'dst'], # IPA classes 'ipalib.base.NameSpace': ['add', 'mod', 'del', 'show', 'find'], @@ -96,6 +91,8 @@ class IPATypeChecker(TypeChecker): 'ipalib.session.SessionManager': LOGGING_ATTRS, 'ipaserver.install.ldapupdate.LDAPUpdate': LOGGING_ATTRS, 'ipaserver.rpcserver.KerberosSession': ['api'] + LOGGING_ATTRS, + 'ipatests.test_integration.base.IntegrationTest': [ + 'domain', 'master', 'replicas', 'clients', 'ad_domains'] } def _related_classes(self, klass): @@ -121,14 +118,16 @@ class IPATypeChecker(TypeChecker): inferred = [] for owner in inferred: - if not isinstance(owner, Class) and type(owner) is not Instance: - continue - - ignored = self._find_ignored_attrs(owner) - for pattern in ignored: - if fnmatchcase(node.attrname, pattern): + if isinstance(owner, Module): + if node.attrname in self.ignore.get(owner.name, ()): return + elif isinstance(owner, Class) or type(owner) is Instance: + ignored = self._find_ignored_attrs(owner) + for pattern in ignored: + if fnmatchcase(node.attrname, pattern): + return + super(IPATypeChecker, self).visit_getattr(node) class IPALinter(PyLinter): @@ -231,13 +230,9 @@ def main(): if options.errors_only: linter.disable_noerror_messages() linter.enable('F') - if have_pylint_1_0: - linter.set_reporter(TextReporter()) - linter.set_option('msg-template', - '{path}:{line}: [{msg_id}({symbol}), {obj}] {msg})') - else: - linter.set_reporter(ParseableTextReporter()) - linter.set_option('include-ids', True) + linter.set_reporter(TextReporter()) + linter.set_option('msg-template', + '{path}:{line}: [{msg_id}({symbol}), {obj}] {msg})') linter.set_option('reports', False) linter.set_option('persistent', False) |