More pylint-fixes

This commit is contained in:
Tomas Groth 2016-07-06 21:48:57 +02:00
parent 99e6ab6657
commit 1992a51339
5 changed files with 62 additions and 27 deletions

View File

@ -122,6 +122,21 @@ def get_upgrade_op(session):
return Operations(context) return Operations(context)
class BaseModel(object):
"""
BaseModel provides a base object with a set of generic functions
"""
@classmethod
def populate(cls, **kwargs):
"""
Creates an instance of a class and populates it, returning the instance
"""
instance = cls()
for key, value in kwargs.items():
instance.__setattr__(key, value)
return instance
def upgrade_db(url, upgrade): def upgrade_db(url, upgrade):
""" """
Upgrade a database. Upgrade a database.
@ -197,21 +212,6 @@ def delete_database(plugin_name, db_file_name=None):
return delete_file(db_file_path) return delete_file(db_file_path)
class BaseModel(object):
"""
BaseModel provides a base object with a set of generic functions
"""
@classmethod
def populate(cls, **kwargs):
"""
Creates an instance of a class and populates it, returning the instance
"""
instance = cls()
for key, value in kwargs.items():
instance.__setattr__(key, value)
return instance
class Manager(object): class Manager(object):
""" """
Provide generic object persistence management Provide generic object persistence management

View File

@ -126,8 +126,6 @@ class OSISBible(BibleDB):
# Remove div-tags in the book # Remove div-tags in the book
etree.strip_tags(book, ('{http://www.bibletechnologies.net/2003/OSIS/namespace}div')) etree.strip_tags(book, ('{http://www.bibletechnologies.net/2003/OSIS/namespace}div'))
book_ref_id = self.get_book_ref_id_by_name(book.get('osisID'), num_books, language_id) book_ref_id = self.get_book_ref_id_by_name(book.get('osisID'), num_books, language_id)
if not book_ref_id:
book_ref_id = self.get_book_ref_id_by_localised_name(book.get('osisID'))
if not book_ref_id: if not book_ref_id:
log.error('Importing books from "{name}" failed'.format(name=self.filename)) log.error('Importing books from "{name}" failed'.format(name=self.filename))
return False return False

View File

@ -86,8 +86,6 @@ class ZefaniaBible(BibleDB):
continue continue
if bname: if bname:
book_ref_id = self.get_book_ref_id_by_name(bname, num_books, language_id) book_ref_id = self.get_book_ref_id_by_name(bname, num_books, language_id)
if not book_ref_id:
book_ref_id = self.get_book_ref_id_by_localised_name(bname)
else: else:
log.debug('Could not find a name, will use number, basically a guess.') log.debug('Could not find a name, will use number, basically a guess.')
book_ref_id = int(bnumber) book_ref_id = int(bnumber)

View File

@ -255,7 +255,7 @@ class CCLIFileImport(SongImport):
song_author = '' song_author = ''
verse_start = False verse_start = False
for line in text_list: for line in text_list:
verse_type= 'v' verse_type = 'v'
clean_line = line.strip() clean_line = line.strip()
if not clean_line: if not clean_line:
if line_number == 0: if line_number == 0:

View File

@ -33,6 +33,13 @@ try:
except ImportError: except ImportError:
raise SkipTest('pylint not installed - skipping tests using pylint.') raise SkipTest('pylint not installed - skipping tests using pylint.')
from openlp.core.common import is_win
TOLERATED_ERRORS = {'registryproperties.py': ['access-member-before-definition'],
'opensong.py': ['no-name-in-module'],
'maindisplay.py': ['no-name-in-module']}
class TestPylint(TestCase): class TestPylint(TestCase):
def test_pylint(self): def test_pylint(self):
@ -40,23 +47,55 @@ class TestPylint(TestCase):
Test for pylint errors Test for pylint errors
""" """
# GIVEN: Some checks to disable and enable, and the pylint script # GIVEN: Some checks to disable and enable, and the pylint script
disabled_checks = 'no-member,import-error,no-name-in-module' disabled_checks = 'import-error,no-member'
enabled_checks = 'missing-format-argument-key,unused-format-string-argument' enabled_checks = 'missing-format-argument-key,unused-format-string-argument'
if 'arch' in platform.dist()[0].lower(): if is_win() or 'arch' in platform.dist()[0].lower():
pylint_script = 'pylint' pylint_script = 'pylint'
else: else:
pylint_script = 'pylint3' pylint_script = 'pylint3'
# WHEN: Running pylint # WHEN: Running pylint
(pylint_stdout, pylint_stderr) = \ (pylint_stdout, pylint_stderr) = \
lint.py_run('openlp --errors-only --disable={disabled} --enable={enabled} --reports=no --output-format=parseable'.format( lint.py_run('openlp --errors-only --disable={disabled} --enable={enabled} '
disabled=disabled_checks, '--reports=no --output-format=parseable'.format(disabled=disabled_checks,
enabled=enabled_checks), enabled=enabled_checks),
return_std=True, script=pylint_script) return_std=True, script=pylint_script)
stdout = pylint_stdout.read() stdout = pylint_stdout.read()
stderr = pylint_stderr.read() stderr = pylint_stderr.read()
print(stdout) filtered_stdout = self._filter_tolerated_errors(stdout)
print(filtered_stdout)
print(stderr) print(stderr)
# THEN: The output should be empty # THEN: The output should be empty
self.assertTrue(stdout == 's', 'PyLint should find no errors') self.assertTrue(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 line.startswith('**'):
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
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