2016-06-27 21:19:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2019-02-14 15:09:09 +00:00
|
|
|
# Copyright (c) 2008-2019 OpenLP Developers #
|
2016-06-27 21:19:53 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
Package to test for proper bzr tags.
|
|
|
|
"""
|
2016-07-05 20:30:33 +00:00
|
|
|
import platform
|
2016-08-01 18:00:58 +00:00
|
|
|
import sys
|
2018-10-02 04:39:42 +00:00
|
|
|
from unittest import SkipTest, TestCase
|
|
|
|
|
|
|
|
from openlp.core.common import is_win
|
|
|
|
|
2016-06-27 21:19:53 +00:00
|
|
|
|
2016-07-05 20:30:33 +00:00
|
|
|
try:
|
|
|
|
from pylint import epylint as lint
|
|
|
|
from pylint.__pkginfo__ import version
|
|
|
|
except ImportError:
|
|
|
|
raise SkipTest('pylint not installed - skipping tests using pylint.')
|
2016-06-27 21:19:53 +00:00
|
|
|
|
2016-07-06 19:48:57 +00:00
|
|
|
|
|
|
|
TOLERATED_ERRORS = {'registryproperties.py': ['access-member-before-definition'],
|
|
|
|
'opensong.py': ['no-name-in-module'],
|
2018-08-05 20:28:01 +00:00
|
|
|
'maindisplay.py': ['no-name-in-module'],
|
|
|
|
'icons.py': ['too-many-function-args']}
|
2016-07-06 19:48:57 +00:00
|
|
|
|
|
|
|
|
2016-06-27 21:19:53 +00:00
|
|
|
class TestPylint(TestCase):
|
|
|
|
|
|
|
|
def test_pylint(self):
|
|
|
|
"""
|
|
|
|
Test for pylint errors
|
|
|
|
"""
|
2016-08-02 19:32:36 +00:00
|
|
|
# Test if this file is specified in the arguments, if not skip the test.
|
|
|
|
in_argv = False
|
|
|
|
for arg in sys.argv:
|
|
|
|
if arg.endswith('test_pylint.py') or arg.endswith('test_pylint'):
|
|
|
|
in_argv = True
|
|
|
|
break
|
|
|
|
if not in_argv:
|
|
|
|
raise SkipTest('test_pylint.py not specified in arguments - skipping tests using pylint.')
|
|
|
|
|
2016-07-05 20:30:33 +00:00
|
|
|
# GIVEN: Some checks to disable and enable, and the pylint script
|
2016-07-06 19:48:57 +00:00
|
|
|
disabled_checks = 'import-error,no-member'
|
2016-08-01 17:42:29 +00:00
|
|
|
enabled_checks = 'missing-format-argument-key,unused-format-string-argument,bad-format-string'
|
2017-11-10 04:11:03 +00:00
|
|
|
pylint_kwargs = {
|
|
|
|
'return_std': True
|
|
|
|
}
|
|
|
|
if version < '1.7.0':
|
|
|
|
if is_win() or 'arch' in platform.dist()[0].lower():
|
|
|
|
pylint_kwargs.update({'script': 'pylint'})
|
|
|
|
else:
|
|
|
|
pylint_kwargs.update({'script': 'pylint3'})
|
2016-06-28 20:44:50 +00:00
|
|
|
|
|
|
|
# WHEN: Running pylint
|
|
|
|
(pylint_stdout, pylint_stderr) = \
|
2018-07-05 20:33:07 +00:00
|
|
|
lint.py_run('openlp --errors-only -j 4 --disable={disabled} --enable={enabled} '
|
2016-07-06 19:48:57 +00:00
|
|
|
'--reports=no --output-format=parseable'.format(disabled=disabled_checks,
|
|
|
|
enabled=enabled_checks),
|
2017-11-10 04:11:03 +00:00
|
|
|
**pylint_kwargs)
|
2016-06-27 21:19:53 +00:00
|
|
|
stdout = pylint_stdout.read()
|
|
|
|
stderr = pylint_stderr.read()
|
2016-07-06 19:48:57 +00:00
|
|
|
filtered_stdout = self._filter_tolerated_errors(stdout)
|
|
|
|
print(filtered_stdout)
|
2016-07-01 21:17:20 +00:00
|
|
|
print(stderr)
|
2016-06-27 21:19:53 +00:00
|
|
|
|
|
|
|
# THEN: The output should be empty
|
2017-12-23 09:09:45 +00:00
|
|
|
assert filtered_stdout == '', 'PyLint should find no errors'
|
2016-07-06 19:48:57 +00:00
|
|
|
|
|
|
|
def _filter_tolerated_errors(self, pylint_output):
|
|
|
|
"""
|
|
|
|
Filter out errors we tolerate.
|
|
|
|
"""
|
|
|
|
filtered_output = ''
|
|
|
|
for line in pylint_output.splitlines():
|
|
|
|
# Filter out module info lines
|
2018-07-05 20:33:07 +00:00
|
|
|
if '***' in line:
|
2016-07-06 19:48:57 +00:00
|
|
|
continue
|
|
|
|
# Filter out undefined-variable error releated to WindowsError
|
|
|
|
elif 'undefined-variable' in line and 'WindowsError' in line:
|
|
|
|
continue
|
|
|
|
# Filter out PyQt related errors
|
|
|
|
elif ('no-name-in-module' in line or 'no-member' in line) and 'PyQt5' in line:
|
|
|
|
continue
|
2016-08-01 18:49:01 +00:00
|
|
|
# Filter out distutils related errors
|
|
|
|
elif 'distutils' in line:
|
|
|
|
continue
|
2016-07-06 19:48:57 +00:00
|
|
|
elif self._is_line_tolerated(line):
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
filtered_output += line + '\n'
|
|
|
|
return filtered_output.strip()
|
|
|
|
|
|
|
|
def _is_line_tolerated(self, line):
|
|
|
|
"""
|
|
|
|
Check if line constains a tolerated error
|
|
|
|
"""
|
|
|
|
for filename in TOLERATED_ERRORS:
|
|
|
|
for tolerated_error in TOLERATED_ERRORS[filename]:
|
|
|
|
if filename in line and tolerated_error in line:
|
|
|
|
return True
|
|
|
|
return False
|