forked from openlp/openlp
Merge branch 'test_fixes' into 'master'
test_fixes See merge request openlp/openlp!13
This commit is contained in:
commit
ab19467c0b
@ -1,58 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
##########################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# ---------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2019 OpenLP Developers #
|
||||
# ---------------------------------------------------------------------- #
|
||||
# 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, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# 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, see <https://www.gnu.org/licenses/>. #
|
||||
##########################################################################
|
||||
"""
|
||||
Package to test for proper bzr tags.
|
||||
"""
|
||||
import os
|
||||
from subprocess import PIPE, Popen
|
||||
from unittest import TestCase, SkipTest
|
||||
|
||||
|
||||
TAGS1 = {'1.9.0', '1.9.1', '1.9.2', '1.9.3', '1.9.4', '1.9.5', '1.9.6', '1.9.7', '1.9.8', '1.9.9', '1.9.10',
|
||||
'1.9.11', '1.9.12', '2.0', '2.1.0', '2.1.1', '2.1.2', '2.1.3', '2.1.4', '2.1.5', '2.1.6', '2.2',
|
||||
'2.3.1', '2.3.2', '2.3.3', '2.4'}
|
||||
|
||||
|
||||
class TestBzrTags(TestCase):
|
||||
|
||||
def test_bzr_tags(self):
|
||||
"""
|
||||
Test for proper bzr tags
|
||||
"""
|
||||
# GIVEN: A bzr branch
|
||||
path = os.path.dirname(__file__)
|
||||
|
||||
# WHEN getting the branches tags
|
||||
try:
|
||||
bzr = Popen(('bzr', 'tags', '--directory=' + path), stdout=PIPE)
|
||||
except Exception:
|
||||
raise SkipTest('bzr is not installed')
|
||||
std_out = bzr.communicate()[0]
|
||||
count = len(TAGS1)
|
||||
tags = [line.decode('utf-8').split()[0] for line in std_out.splitlines()]
|
||||
count1 = 0
|
||||
for t in tags:
|
||||
if t in TAGS1:
|
||||
count1 += 1
|
||||
|
||||
# THEN the tags should match the accepted tags
|
||||
assert count == count1, 'List of tags should match'
|
@ -1,119 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||
|
||||
##########################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# ---------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2019 OpenLP Developers #
|
||||
# ---------------------------------------------------------------------- #
|
||||
# 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, either version 3 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# 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, see <https://www.gnu.org/licenses/>. #
|
||||
##########################################################################
|
||||
"""
|
||||
Package to test for proper bzr tags.
|
||||
"""
|
||||
import platform
|
||||
import sys
|
||||
from unittest import SkipTest, TestCase
|
||||
|
||||
from openlp.core.common import is_win
|
||||
|
||||
|
||||
try:
|
||||
from pylint import epylint as lint
|
||||
from pylint.__pkginfo__ import version
|
||||
except ImportError:
|
||||
raise SkipTest('pylint not installed - skipping tests using pylint.')
|
||||
|
||||
|
||||
TOLERATED_ERRORS = {'registryproperties.py': ['access-member-before-definition'],
|
||||
'opensong.py': ['no-name-in-module'],
|
||||
'maindisplay.py': ['no-name-in-module'],
|
||||
'icons.py': ['too-many-function-args']}
|
||||
|
||||
|
||||
class TestPylint(TestCase):
|
||||
|
||||
def test_pylint(self):
|
||||
"""
|
||||
Test for pylint errors
|
||||
"""
|
||||
# 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.')
|
||||
|
||||
# GIVEN: Some checks to disable and enable, and the pylint script
|
||||
disabled_checks = 'import-error,no-member'
|
||||
enabled_checks = 'missing-format-argument-key,unused-format-string-argument,bad-format-string'
|
||||
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'})
|
||||
|
||||
# WHEN: Running pylint
|
||||
(pylint_stdout, pylint_stderr) = \
|
||||
lint.py_run('openlp --errors-only -j 4 --disable={disabled} --enable={enabled} '
|
||||
'--reports=no --output-format=parseable'.format(disabled=disabled_checks,
|
||||
enabled=enabled_checks),
|
||||
**pylint_kwargs)
|
||||
stdout = pylint_stdout.read()
|
||||
stderr = pylint_stderr.read()
|
||||
filtered_stdout = self._filter_tolerated_errors(stdout)
|
||||
print(filtered_stdout)
|
||||
print(stderr)
|
||||
|
||||
# THEN: The output should be empty
|
||||
assert filtered_stdout == '', 'PyLint should find no errors'
|
||||
|
||||
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
|
||||
if '***' in line:
|
||||
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
|
||||
# Filter out distutils related errors
|
||||
elif 'distutils' in line:
|
||||
continue
|
||||
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
|
Loading…
Reference in New Issue
Block a user