diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 85d903546..481f58a82 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -26,13 +26,13 @@ from openlp.core.api.http import register_endpoint from openlp.core.common.actions import ActionList from openlp.core.common.i18n import UiStrings, translate from openlp.core.ui.icons import UiIcons -from openlp.core.lib import build_icon from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.ui import create_action from openlp.plugins.bibles.endpoint import api_bibles_endpoint, bibles_endpoint -from openlp.plugins.bibles.lib import BibleManager, BiblesTab, BibleMediaItem, LayoutStyle, DisplayStyle, \ - LanguageSelection -from openlp.plugins.bibles.lib.mediaitem import BibleSearch +from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, LanguageSelection +from openlp.plugins.bibles.lib.biblestab import BiblesTab +from openlp.plugins.bibles.lib.manager import BibleManager +from openlp.plugins.bibles.lib.mediaitem import BibleMediaItem, BibleSearch log = logging.getLogger(__name__) diff --git a/openlp/plugins/bibles/lib/__init__.py b/openlp/plugins/bibles/lib/__init__.py index b1a51bfd7..e8e7a1bf6 100644 --- a/openlp/plugins/bibles/lib/__init__.py +++ b/openlp/plugins/bibles/lib/__init__.py @@ -424,9 +424,3 @@ class SearchResults(object): Returns whether or not the verse list contains verses. """ return len(self.verse_list) > 0 - - -from .versereferencelist import VerseReferenceList -from .manager import BibleManager -from .biblestab import BiblesTab -from .mediaitem import BibleMediaItem diff --git a/openlp/plugins/bibles/lib/importers/csvbible.py b/openlp/plugins/bibles/lib/importers/csvbible.py index 29d22ff7d..ed753207a 100644 --- a/openlp/plugins/bibles/lib/importers/csvbible.py +++ b/openlp/plugins/bibles/lib/importers/csvbible.py @@ -54,7 +54,6 @@ from collections import namedtuple from openlp.core.common import get_file_encoding from openlp.core.common.i18n import translate -from openlp.core.common.path import Path from openlp.core.lib.exceptions import ValidationError from openlp.plugins.bibles.lib.bibleimport import BibleImport diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 32ca16bd6..faf3edfc2 100755 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -38,8 +38,9 @@ from openlp.core.ui.icons import UiIcons from openlp.core.widgets.edits import SearchEdit from openlp.plugins.bibles.forms.bibleimportform import BibleImportForm from openlp.plugins.bibles.forms.editbibleform import EditBibleForm -from openlp.plugins.bibles.lib import DisplayStyle, LayoutStyle, VerseReferenceList, \ - get_reference_match, get_reference_separator +from openlp.plugins.bibles.lib import DisplayStyle, LayoutStyle, get_reference_match, \ + get_reference_separator +from openlp.plugins.bibles.lib.versereferencelist import VerseReferenceList log = logging.getLogger(__name__) diff --git a/openlp/plugins/images/forms/__init__.py b/openlp/plugins/images/forms/__init__.py index f7a6b947b..450f19e8a 100644 --- a/openlp/plugins/images/forms/__init__.py +++ b/openlp/plugins/images/forms/__init__.py @@ -40,6 +40,3 @@ mentioned above, like so:: This allows OpenLP to use ``self.object`` for all the GUI elements while keeping them separate from the functionality, so that it is easier to recreate the GUI from the .ui files later if necessary. """ - -from .addgroupform import AddGroupForm -from .choosegroupform import ChooseGroupForm diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index cb6f91741..74572c0f8 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -32,7 +32,9 @@ from openlp.core.lib import ImageSource, build_icon from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.db import Manager from openlp.plugins.images.endpoint import api_images_endpoint, images_endpoint -from openlp.plugins.images.lib import ImageMediaItem, ImageTab, upgrade +from openlp.plugins.images.lib import upgrade +from openlp.plugins.images.lib.mediaitem import ImageMediaItem +from openlp.plugins.images.lib.imagetab import ImageTab from openlp.plugins.images.lib.db import init_schema log = logging.getLogger(__name__) diff --git a/openlp/plugins/images/lib/__init__.py b/openlp/plugins/images/lib/__init__.py index 668d437ce..711ded4ae 100644 --- a/openlp/plugins/images/lib/__init__.py +++ b/openlp/plugins/images/lib/__init__.py @@ -19,6 +19,3 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - -from .imagetab import ImageTab -from .mediaitem import ImageMediaItem diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index b82da4e26..4bd34ebb9 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -38,7 +38,8 @@ from openlp.core.lib.plugin import StringContent from openlp.core.lib.ui import create_widget_action, critical_error_message_box from openlp.core.ui.icons import UiIcons from openlp.core.widgets.views import TreeWidgetWithDnD -from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm +from openlp.plugins.images.forms.addgroupform import AddGroupForm +from openlp.plugins.images.forms.choosegroupform import ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/lib/__init__.py b/openlp/plugins/presentations/lib/__init__.py index 8cc7c1942..711ded4ae 100644 --- a/openlp/plugins/presentations/lib/__init__.py +++ b/openlp/plugins/presentations/lib/__init__.py @@ -19,8 +19,3 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - -from .presentationcontroller import PresentationController -from .messagelistener import MessageListener -from .mediaitem import PresentationMediaItem -from .presentationtab import PresentationTab diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 468bd75f9..e392f4ee3 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -21,7 +21,7 @@ ############################################################################### import logging -from PyQt5 import QtCore, QtGui, QtWidgets +from PyQt5 import QtCore, QtWidgets from openlp.core.common.i18n import UiStrings, translate, get_natural_key from openlp.core.common.path import path_to_str, str_to_path @@ -33,7 +33,7 @@ from openlp.core.lib.mediamanageritem import MediaManagerItem from openlp.core.lib.serviceitem import ItemCapabilities from openlp.core.lib.ui import critical_error_message_box, create_horizontal_adjusting_combo_box from openlp.core.ui.icons import UiIcons -from openlp.plugins.presentations.lib import MessageListener +from openlp.plugins.presentations.lib.messagelistener import MessageListener from openlp.plugins.presentations.lib.pdfcontroller import PDF_CONTROLLER_FILETYPES log = logging.getLogger(__name__) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index c64df5cde..be23ba445 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -36,7 +36,9 @@ from openlp.core.common.settings import Settings from openlp.core.lib import build_icon from openlp.core.lib.plugin import Plugin, StringContent from openlp.plugins.presentations.endpoint import api_presentations_endpoint, presentations_endpoint -from openlp.plugins.presentations.lib import PresentationController, PresentationMediaItem, PresentationTab +from openlp.plugins.presentations.lib.presentationcontroller import PresentationController +from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem +from openlp.plugins.presentations.lib.presentationtab import PresentationTab log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/forms/__init__.py b/openlp/plugins/songs/forms/__init__.py index b95871295..2bd280ffc 100644 --- a/openlp/plugins/songs/forms/__init__.py +++ b/openlp/plugins/songs/forms/__init__.py @@ -45,4 +45,3 @@ This allows OpenLP to use ``self.object`` for all the GUI elements while keeping them separate from the functionality, so that it is easier to recreate the GUI from the .ui files later if necessary. """ -from .editsongform import EditSongForm diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index c86d822fd..1335cfc05 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -33,7 +33,7 @@ from openlp.core.common.applocation import AppLocation from openlp.core.common.i18n import translate from openlp.core.common.settings import Settings from openlp.core.lib import clean_tags -from openlp.plugins.songs.lib.db import Author, MediaFile, Song, Topic +from openlp.plugins.songs.lib.db import Author, MediaFile, Song from openlp.plugins.songs.lib.ui import SongStrings log = logging.getLogger(__name__) diff --git a/openlp/plugins/songs/lib/importers/cclifile.py b/openlp/plugins/songs/lib/importers/cclifile.py index 1389918c1..0e2668836 100644 --- a/openlp/plugins/songs/lib/importers/cclifile.py +++ b/openlp/plugins/songs/lib/importers/cclifile.py @@ -289,10 +289,8 @@ class CCLIFileImport(SongImport): # verse type, so set flag verse_type = VerseType.tags[VerseType.Other] check_first_verse_line = True - verse_number = verse_desc_parts[1] else: verse_type = VerseType.tags[VerseType.Other] - verse_number = 1 verse_start = True else: # check first line for verse type diff --git a/openlp/plugins/songs/lib/songselect.py b/openlp/plugins/songs/lib/songselect.py index 61de5b574..35f01888b 100644 --- a/openlp/plugins/songs/lib/songselect.py +++ b/openlp/plugins/songs/lib/songselect.py @@ -33,7 +33,8 @@ from urllib.request import HTTPCookieProcessor, URLError, build_opener from bs4 import BeautifulSoup, NavigableString -from openlp.plugins.songs.lib import Song, Author, Topic, VerseType, clean_song +from openlp.plugins.songs.lib import VerseType, clean_song +from openlp.plugins.songs.lib.db import Song, Author, Topic from openlp.plugins.songs.lib.openlyricsxml import SongXML USER_AGENTS = [ diff --git a/openlp/plugins/songusage/forms/__init__.py b/openlp/plugins/songusage/forms/__init__.py index 1ab5ed70c..711ded4ae 100644 --- a/openlp/plugins/songusage/forms/__init__.py +++ b/openlp/plugins/songusage/forms/__init__.py @@ -19,6 +19,3 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### - -from .songusagedeleteform import SongUsageDeleteForm -from .songusagedetailform import SongUsageDetailForm diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index a0dcff54f..87ab46c37 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -33,7 +33,8 @@ from openlp.core.lib.plugin import Plugin, StringContent from openlp.core.lib.db import Manager from openlp.core.lib.ui import create_action from openlp.core.ui.icons import UiIcons -from openlp.plugins.songusage.forms import SongUsageDetailForm, SongUsageDeleteForm +from openlp.plugins.songusage.forms.songusagedetailform import SongUsageDetailForm +from openlp.plugins.songusage.forms.songusagedeleteform import SongUsageDeleteForm from openlp.plugins.songusage.lib import upgrade from openlp.plugins.songusage.lib.db import init_schema, SongUsageItem diff --git a/scripts/translation_utils.py b/scripts/translation_utils.py index 44f2476f5..f6eac49aa 100755 --- a/scripts/translation_utils.py +++ b/scripts/translation_utils.py @@ -58,7 +58,7 @@ import urllib.request import webbrowser from PyQt5 import QtCore -from lxml import etree, objectify +from lxml import objectify SERVER_URL = 'http://www.transifex.com/api/2/project/openlp/resource/openlp-26x/' IGNORED_PATHS = ['scripts'] diff --git a/setup.cfg b/setup.cfg index 223e5c7c2..11ca74af3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,7 @@ ignore = E402 [flake8] exclude=resources.py,vlc.py max-line-length = 120 -ignore = E402 +ignore = D200,E402,W503,W504 [pycodestyle] exclude = resources.py,vlc.py @@ -21,4 +21,3 @@ max-line-length = 120 # W503 line break before binary operator # W504 line break after binary operator ignore = E402,E722,W503,W504 - diff --git a/tests/functional/openlp_plugins/bibles/test_csvimport.py b/tests/functional/openlp_plugins/bibles/test_csvimport.py index db07706eb..6908da7b7 100644 --- a/tests/functional/openlp_plugins/bibles/test_csvimport.py +++ b/tests/functional/openlp_plugins/bibles/test_csvimport.py @@ -25,7 +25,7 @@ This module contains tests for the CSV Bible importer. import csv from collections import namedtuple from unittest import TestCase -from unittest.mock import ANY, MagicMock, PropertyMock, call, patch +from unittest.mock import MagicMock, PropertyMock, call, patch from openlp.core.common.path import Path from openlp.core.lib.exceptions import ValidationError @@ -131,35 +131,40 @@ class TestCSVImport(TestCase): # GIVEN: A mocked csv.reader which returns an iterator with test data test_data = [['1', 'Line 1', 'Data 1'], ['2', 'Line 2', 'Data 2'], ['3', 'Line 3', 'Data 3']] TestTuple = namedtuple('TestTuple', 'line_no line_description line_data') + mocked_csv_file = MagicMock() + mocked_enter_file = MagicMock() + mocked_csv_file.open.return_value.__enter__.return_value = mocked_enter_file with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', - return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True) as mocked_open,\ + return_value={'encoding': 'utf-8', 'confidence': 0.99}), \ patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', return_value=iter(test_data)) as mocked_reader: # WHEN: Calling the CSVBible parse_csv_file method with a file name and TestTuple - result = CSVBible.parse_csv_file(Path('file.csv'), TestTuple) + result = CSVBible.parse_csv_file(mocked_csv_file, TestTuple) # THEN: A list of TestTuple instances with the parsed data should be returned assert result == [TestTuple('1', 'Line 1', 'Data 1'), TestTuple('2', 'Line 2', 'Data 2'), TestTuple('3', 'Line 3', 'Data 3')] - mocked_open.assert_called_once_with('r', encoding='utf-8', newline='') - mocked_reader.assert_called_once_with(ANY, delimiter=',', quotechar='"') + mocked_csv_file.open.assert_called_once_with('r', encoding='utf-8', newline='') + mocked_reader.assert_called_once_with(mocked_enter_file, delimiter=',', quotechar='"') def test_parse_csv_file_oserror(self): """ Test the parse_csv_file() handles an OSError correctly """ # GIVEN: Mocked a mocked open object which raises an OSError + mocked_csv_file = MagicMock() + mocked_csv_file.__str__.return_value = 'file.csv' + mocked_csv_file.open.side_effect = OSError() + with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', - return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', side_effect=OSError, create=True): + return_value={'encoding': 'utf-8', 'confidence': 0.99}): # WHEN: Calling CSVBible.parse_csv_file # THEN: A ValidationError should be raised with self.assertRaises(ValidationError) as context: - CSVBible.parse_csv_file(Path('file.csv'), None) + CSVBible.parse_csv_file(mocked_csv_file, None) assert context.exception.msg == 'Parsing "file.csv" failed' def test_parse_csv_file_csverror(self): @@ -167,15 +172,17 @@ class TestCSVImport(TestCase): Test the parse_csv_file() handles an csv.Error correctly """ # GIVEN: Mocked a csv.reader which raises an csv.Error + mocked_csv_file = MagicMock() + mocked_csv_file.__str__.return_value = 'file.csv' + with patch('openlp.plugins.bibles.lib.importers.csvbible.get_file_encoding', return_value={'encoding': 'utf-8', 'confidence': 0.99}),\ - patch('openlp.plugins.bibles.lib.importers.csvbible.Path.open', create=True),\ patch('openlp.plugins.bibles.lib.importers.csvbible.csv.reader', side_effect=csv.Error): # WHEN: Calling CSVBible.parse_csv_file # THEN: A ValidationError should be raised with self.assertRaises(ValidationError) as context: - CSVBible.parse_csv_file(Path('file.csv'), None) + CSVBible.parse_csv_file(mocked_csv_file, None) assert context.exception.msg == 'Parsing "file.csv" failed' def test_process_books_stopped_import(self): diff --git a/tests/functional/openlp_plugins/images/test_imagetab.py b/tests/functional/openlp_plugins/images/test_imagetab.py index 813be4e88..7bd705a4f 100644 --- a/tests/functional/openlp_plugins/images/test_imagetab.py +++ b/tests/functional/openlp_plugins/images/test_imagetab.py @@ -29,7 +29,7 @@ from PyQt5 import QtWidgets from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings -from openlp.plugins.images.lib import ImageTab +from openlp.plugins.images.lib.imagetab import ImageTab from tests.helpers.testmixin import TestMixin __default_settings__ = { diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py b/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py index 4252a2064..bd24f2c85 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_manager.py @@ -27,7 +27,8 @@ from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings -from openlp.plugins.bibles.lib import BibleManager, LanguageSelection +from openlp.plugins.bibles.lib import LanguageSelection +from openlp.plugins.bibles.lib.manager import BibleManager from tests.helpers.testmixin import TestMixin from tests.utils.constants import TEST_RESOURCES_PATH diff --git a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py index bf1057667..aef54c38f 100644 --- a/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py +++ b/tests/interfaces/openlp_plugins/bibles/test_lib_parse_reference.py @@ -27,7 +27,8 @@ from unittest.mock import MagicMock, patch from openlp.core.common.registry import Registry from openlp.core.common.settings import Settings -from openlp.plugins.bibles.lib import BibleManager, parse_reference, LanguageSelection +from openlp.plugins.bibles.lib import LanguageSelection, parse_reference +from openlp.plugins.bibles.lib.manager import BibleManager from tests.helpers.testmixin import TestMixin from tests.utils.constants import TEST_RESOURCES_PATH