diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index d77432181..f42c3b5fc 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -122,6 +122,21 @@ def get_upgrade_op(session): 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): """ Upgrade a database. @@ -197,21 +212,6 @@ def delete_database(plugin_name, db_file_name=None): 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): """ Provide generic object persistence management diff --git a/openlp/plugins/bibles/lib/osis.py b/openlp/plugins/bibles/lib/osis.py index c0a3bec81..85aea70b3 100644 --- a/openlp/plugins/bibles/lib/osis.py +++ b/openlp/plugins/bibles/lib/osis.py @@ -126,8 +126,6 @@ class OSISBible(BibleDB): # Remove div-tags in the book 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) - if not book_ref_id: - book_ref_id = self.get_book_ref_id_by_localised_name(book.get('osisID')) if not book_ref_id: log.error('Importing books from "{name}" failed'.format(name=self.filename)) return False diff --git a/openlp/plugins/bibles/lib/zefania.py b/openlp/plugins/bibles/lib/zefania.py index 0ea96a2a3..482d98107 100644 --- a/openlp/plugins/bibles/lib/zefania.py +++ b/openlp/plugins/bibles/lib/zefania.py @@ -86,8 +86,6 @@ class ZefaniaBible(BibleDB): continue if bname: 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: log.debug('Could not find a name, will use number, basically a guess.') book_ref_id = int(bnumber) diff --git a/openlp/plugins/songs/lib/importers/cclifile.py b/openlp/plugins/songs/lib/importers/cclifile.py index b17f78129..58ceefebc 100644 --- a/openlp/plugins/songs/lib/importers/cclifile.py +++ b/openlp/plugins/songs/lib/importers/cclifile.py @@ -255,7 +255,7 @@ class CCLIFileImport(SongImport): song_author = '' verse_start = False for line in text_list: - verse_type= 'v' + verse_type = 'v' clean_line = line.strip() if not clean_line: if line_number == 0: diff --git a/tests/utils/test_pylint.py b/tests/utils/test_pylint.py index d4e744e55..dc6c83909 100644 --- a/tests/utils/test_pylint.py +++ b/tests/utils/test_pylint.py @@ -33,6 +33,13 @@ try: except ImportError: 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): def test_pylint(self): @@ -40,23 +47,55 @@ class TestPylint(TestCase): Test for pylint errors """ # 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' - if 'arch' in platform.dist()[0].lower(): + if is_win() or 'arch' in platform.dist()[0].lower(): pylint_script = 'pylint' else: pylint_script = 'pylint3' # WHEN: Running pylint (pylint_stdout, pylint_stderr) = \ - lint.py_run('openlp --errors-only --disable={disabled} --enable={enabled} --reports=no --output-format=parseable'.format( - disabled=disabled_checks, - enabled=enabled_checks), + lint.py_run('openlp --errors-only --disable={disabled} --enable={enabled} ' + '--reports=no --output-format=parseable'.format(disabled=disabled_checks, + enabled=enabled_checks), return_std=True, script=pylint_script) stdout = pylint_stdout.read() stderr = pylint_stderr.read() - print(stdout) + filtered_stdout = self._filter_tolerated_errors(stdout) + print(filtered_stdout) print(stderr) # 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