From 4a3e4e1ad459fa48812a1971821d250f0eb3bf3e Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 30 May 2017 22:05:18 +0200 Subject: [PATCH 1/3] Fix songshowplus encoding issue. --- openlp/plugins/songs/lib/importers/songshowplus.py | 6 +++--- .../songshowplussongs/a mighty fortress is our god.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/songshowplus.py b/openlp/plugins/songs/lib/importers/songshowplus.py index edb16c74e..4848349f0 100644 --- a/openlp/plugins/songs/lib/importers/songshowplus.py +++ b/openlp/plugins/songs/lib/importers/songshowplus.py @@ -23,7 +23,6 @@ The :mod:`songshowplus` module provides the functionality for importing SongShow Plus songs into the OpenLP database. """ -import chardet import os import logging import re @@ -226,6 +225,7 @@ class SongShowPlusImport(SongImport): def decode(self, data): try: - return str(data, chardet.detect(data)['encoding']) + # Don't question this, it works... + return data.decode('utf-8').encode('cp1251').decode('cp1251') except: - return str(data, retrieve_windows_encoding()) + return data.decode(retrieve_windows_encoding()) diff --git a/tests/resources/songshowplussongs/a mighty fortress is our god.json b/tests/resources/songshowplussongs/a mighty fortress is our god.json index 2788ad05c..96453c0df 100644 --- a/tests/resources/songshowplussongs/a mighty fortress is our god.json +++ b/tests/resources/songshowplussongs/a mighty fortress is our god.json @@ -15,7 +15,7 @@ "v1" ], [ - "Did we in our own strength confide, our striving would be losing;\r\nWere not the right Man on our side, the Man of God’s own choosing:\r\nDost ask who that may be? Christ Jesus, it is He;\r\nLord Sabaoth, His Name, from age to age the same,\r\nAnd He must win the battle.\r\n", + "Did we in our own strength confide, our striving would be losing;\r\nWere not the right Man on our side, the Man of God’s own choosing:\r\nDost ask who that may be? Christ Jesus, it is He;\r\nLord Sabaoth, His Name, from age to age the same,\r\nAnd He must win the battle.\r\n", "v2" ], [ @@ -23,7 +23,7 @@ "v3" ], [ - "That word above all earthly powers, no thanks to them, abideth;\r\nThe Spirit and the gifts are ours through Him Who with us sideth:\r\nLet goods and kindred go, this mortal life also;\r\nThe body they may kill: God’s truth abideth still,\r\nHis kingdom is forever.\r\n", + "That word above all earthly powers, no thanks to them, abideth;\r\nThe Spirit and the gifts are ours through Him Who with us sideth:\r\nLet goods and kindred go, this mortal life also;\r\nThe body they may kill: God’s truth abideth still,\r\nHis kingdom is forever.\r\n", "v4" ] ] From ad55a8d2541b483b910d86513fffd294d5371907 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 30 May 2017 22:06:27 +0200 Subject: [PATCH 2/3] Fix issue where enable-chord settings was not setup correctly for tests. --- .../openlp_plugins/songs/test_editverseform.py | 8 +++++++- .../openlp_plugins/songs/forms/test_editsongform.py | 9 ++++++++- .../openlp_plugins/songs/forms/test_editverseform.py | 9 ++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_plugins/songs/test_editverseform.py b/tests/functional/openlp_plugins/songs/test_editverseform.py index 0cb08e827..3e97abbb7 100644 --- a/tests/functional/openlp_plugins/songs/test_editverseform.py +++ b/tests/functional/openlp_plugins/songs/test_editverseform.py @@ -27,10 +27,15 @@ from unittest.mock import MagicMock from PyQt5 import QtCore +from openlp.core.common import Settings from openlp.plugins.songs.forms.editverseform import EditVerseForm from tests.helpers.testmixin import TestMixin +__default_settings__ = { + 'songs/enable chords': True, +} + class TestEditVerseForm(TestCase, TestMixin): """ @@ -40,9 +45,10 @@ class TestEditVerseForm(TestCase, TestMixin): """ Set up the components need for all tests. """ - self.edit_verse_form = EditVerseForm(None) self.setup_application() self.build_settings() + Settings().extend_default_settings(__default_settings__) + self.edit_verse_form = EditVerseForm(None) QtCore.QLocale.setDefault(QtCore.QLocale('en_GB')) def tearDown(self): diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py index b82bb29ae..e7d8308fa 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editsongform.py @@ -27,12 +27,16 @@ from unittest.mock import MagicMock from PyQt5 import QtWidgets -from openlp.core.common import Registry +from openlp.core.common import Registry, Settings from openlp.core.common.uistrings import UiStrings from openlp.plugins.songs.forms.editsongform import EditSongForm from tests.helpers.testmixin import TestMixin +__default_settings__ = { + 'songs/enable chords': True, +} + class TestEditSongForm(TestCase, TestMixin): """ @@ -48,12 +52,15 @@ class TestEditSongForm(TestCase, TestMixin): self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) Registry().register('theme_manager', MagicMock()) + self.build_settings() + Settings().extend_default_settings(__default_settings__) self.form = EditSongForm(MagicMock(), self.main_window, MagicMock()) def tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ + self.destroy_settings() del self.form del self.main_window diff --git a/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py b/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py index a28be8df2..78c5c3016 100644 --- a/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins/songs/forms/test_editverseform.py @@ -26,10 +26,14 @@ from unittest import TestCase from PyQt5 import QtCore, QtTest, QtWidgets -from openlp.core.common import Registry +from openlp.core.common import Registry, Settings from openlp.plugins.songs.forms.editverseform import EditVerseForm from tests.helpers.testmixin import TestMixin +__default_settings__ = { + 'songs/enable chords': True, +} + class TestEditVerseForm(TestCase, TestMixin): """ @@ -44,12 +48,15 @@ class TestEditVerseForm(TestCase, TestMixin): self.setup_application() self.main_window = QtWidgets.QMainWindow() Registry().register('main_window', self.main_window) + self.build_settings() + Settings().extend_default_settings(__default_settings__) self.form = EditVerseForm() def tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ + self.destroy_settings() del self.form del self.main_window From 1dc0b0a4b56913bb2ff97f1f432a0ae6249e5954 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 30 May 2017 22:15:20 +0200 Subject: [PATCH 3/3] pep8 fixes --- openlp/core/ui/lib/pathedit.py | 8 ++++---- openlp/plugins/presentations/presentationplugin.py | 2 +- openlp/plugins/songusage/forms/songusagedetaildialog.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/lib/pathedit.py b/openlp/core/ui/lib/pathedit.py index 238bcb00d..c489daa33 100755 --- a/openlp/core/ui/lib/pathedit.py +++ b/openlp/core/ui/lib/pathedit.py @@ -46,16 +46,16 @@ class PathEdit(QtWidgets.QWidget): :param parent: The parent of the widget. This is just passed to the super method. :type parent: QWidget or None - + :param dialog_caption: Used to customise the caption in the QFileDialog. :param dialog_caption: str - + :param default_path: The default path. This is set as the path when the revert button is clicked :type default_path: str :param show_revert: Used to determin if the 'revert button' should be visible. :type show_revert: bool - + :return: None :rtype: None """ @@ -72,7 +72,7 @@ class PathEdit(QtWidgets.QWidget): Set up the widget :param show_revert: Show or hide the revert button :type show_revert: bool - + :return: None :rtype: None """ diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 884f155a2..210f8a531 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -1,4 +1,4 @@ - # -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 ############################################################################### diff --git a/openlp/plugins/songusage/forms/songusagedetaildialog.py b/openlp/plugins/songusage/forms/songusagedetaildialog.py index 74c8c89c8..082173bf5 100644 --- a/openlp/plugins/songusage/forms/songusagedetaildialog.py +++ b/openlp/plugins/songusage/forms/songusagedetaildialog.py @@ -69,7 +69,7 @@ class Ui_SongUsageDetailDialog(object): self.file_horizontal_layout.setSpacing(8) self.file_horizontal_layout.setContentsMargins(8, 8, 8, 8) self.file_horizontal_layout.setObjectName('file_horizontal_layout') - self.report_path_edit = PathEdit(self.file_group_box, path_type = PathType.Directories, show_revert=False) + self.report_path_edit = PathEdit(self.file_group_box, path_type=PathType.Directories, show_revert=False) self.file_horizontal_layout.addWidget(self.report_path_edit) self.vertical_layout.addWidget(self.file_group_box) self.button_box = create_button_box(song_usage_detail_dialog, 'button_box', ['cancel', 'ok'])