Fix a bunch of linting issues (which should also help resolve other circular dependencies)

This commit is contained in:
Raoul Snyman 2018-10-26 16:15:31 -07:00
parent 4bed8eabed
commit ec479e589b
23 changed files with 47 additions and 55 deletions

View File

@ -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__)

View File

@ -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

View File

@ -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

View File

@ -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__)

View File

@ -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

View File

@ -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__)

View File

@ -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

View File

@ -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__)

View File

@ -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

View File

@ -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__)

View File

@ -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__)

View File

@ -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

View File

@ -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__)

View File

@ -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

View File

@ -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 = [

View File

@ -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

View File

@ -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

View File

@ -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']

View File

@ -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

View File

@ -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):

View File

@ -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__ = {

View File

@ -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

View File

@ -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