From 7931eb1d1763354e616019034fc8810230216c44 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 10 Dec 2016 22:59:06 +0200 Subject: [PATCH 1/5] Fix a problem with the incorrect parent module for QSize --- openlp/core/ui/projector/sourceselectform.py | 11 ++-- .../test_projector_sourceselectform.py | 54 +++++++++++++++++++ .../test_projectorsourceform.py | 14 +++-- 3 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 tests/functional/openlp_core_ui/test_projector_sourceselectform.py diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index f47622090..cf19552c3 100644 --- a/openlp/core/ui/projector/sourceselectform.py +++ b/openlp/core/ui/projector/sourceselectform.py @@ -61,9 +61,8 @@ def source_group(inputs, source_text): """ groupdict = {} keydict = {} - checklist = inputs - key = checklist[0][0] - for item in checklist: + key = inputs[0][0] + for item in inputs: if item[0] == key: groupdict[item] = source_text[item] continue @@ -75,7 +74,7 @@ def source_group(inputs, source_text): return keydict -def Build_Tab(group, source_key, default, projector, projectordb, edit=False): +def build_tab(group, source_key, default, projector, projectordb, edit=False): """ Create the radio button page for a tab. Dictionary will be a 1-key entry where key=tab to setup, val=list of inputs. @@ -275,7 +274,7 @@ class SourceSelectTabs(QtWidgets.QDialog): keys.sort() if self.edit: for key in keys: - (tab, button_count, buttonchecked) = Build_Tab(group=self.button_group, + (tab, button_count, buttonchecked) = build_tab(group=self.button_group, source_key={key: self.source_group[key]}, default=self.projector.source, projector=self.projector, @@ -290,7 +289,7 @@ class SourceSelectTabs(QtWidgets.QDialog): QtWidgets.QDialogButtonBox.Cancel) else: for key in keys: - (tab, button_count, buttonchecked) = Build_Tab(group=self.button_group, + (tab, button_count, buttonchecked) = build_tab(group=self.button_group, source_key={key: self.source_group[key]}, default=self.projector.source, projector=self.projector, diff --git a/tests/functional/openlp_core_ui/test_projector_sourceselectform.py b/tests/functional/openlp_core_ui/test_projector_sourceselectform.py new file mode 100644 index 000000000..51ba4bcc3 --- /dev/null +++ b/tests/functional/openlp_core_ui/test_projector_sourceselectform.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2016 OpenLP Developers # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +:mod: `tests.functional.openlp_core_ui.test_projectorsourceform` module + +Tests for the Projector Source Select form. +""" +from openlp.core.ui.projector.sourceselectform import source_group + + +def test_source_group(): + """ + Test the source_group() method + """ + # GIVEN: A list of inputs and source text + inputs = [ + 'vga1', 'vga2', + 'hdmi1', 'hdmi2' + ] + source_text = { + 'vga1': 'VGA 1', + 'vga2': 'VGA 2', + 'hdmi1': 'HDMI 1', + 'hdmi2': 'HDMI 2' + } + + # WHEN: source_group() is called + result = source_group(inputs, source_text) + + # THEN: the resultant dictionary should be correct + expected_dict = { + 'v': {'vga1': 'VGA 1', 'vga2': 'VGA 2'}, + 'h': {'hdmi1': 'HDMI 1', 'hdmi2': 'HDMI 2'} + } + assert result == expected_dict, result diff --git a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py index 93aeb4c0a..35df7c3aa 100644 --- a/tests/interfaces/openlp_core_ui/test_projectorsourceform.py +++ b/tests/interfaces/openlp_core_ui/test_projectorsourceform.py @@ -24,19 +24,17 @@ Tests for the Projector Source Select form. """ -import logging -log = logging.getLogger(__name__) -log.debug('test_projectorsourceform loaded') import os +import time from unittest import TestCase +from unittest.mock import patch from PyQt5.QtWidgets import QDialog -from tests.functional import patch from tests.helpers.testmixin import TestMixin from tests.resources.projector.data import TEST_DB, TEST1_DATA -from openlp.core.common import Registry, Settings +from openlp.core.common import Registry from openlp.core.lib.projector.db import ProjectorDB, Projector from openlp.core.lib.projector.constants import PJLINK_DEFAULT_CODES, PJLINK_DEFAULT_SOURCES from openlp.core.ui.projector.sourceselectform import source_group, SourceSelectSingle @@ -49,7 +47,7 @@ def build_source_dict(): :returns: dictionary of valid PJLink source codes grouped by PJLink source group """ test_group = {} - for group in PJLINK_DEFAULT_SOURCES.keys(): + for group in PJLINK_DEFAULT_SOURCES: test_group[group] = {} for key in PJLINK_DEFAULT_CODES: test_group[key[0]][key] = PJLINK_DEFAULT_CODES[key] @@ -86,8 +84,8 @@ class ProjectorSourceFormTest(TestCase, TestMixin): Delete all C++ objects at end so we don't segfault. """ self.projectordb.session.close() - del(self.projectordb) - del(self.projector) + del self.projectordb + del self.projector retries = 0 while retries < 5: try: From e96281c1c0a7e32b94acc567ce2ddb0d74ceec70 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 10 Dec 2016 22:59:32 +0200 Subject: [PATCH 2/5] Make the test resources directories into Python modules for some of the tests that need it --- tests/resources/__init__.py | 0 tests/resources/bibles/__init__.py | 0 tests/resources/easyslidessongs/__init__.py | 0 tests/resources/easyworshipsongs/__init__.py | 0 tests/resources/lyrixsongs/__init__.py | 0 tests/resources/openlyricssongs/__init__.py | 0 tests/resources/opensongsongs/__init__.py | 0 tests/resources/powerpraisesongs/__init__.py | 0 tests/resources/presentationmanagersongs/__init__.py | 0 tests/resources/presentations/__init__.py | 0 tests/resources/projector/__init__.py | 0 tests/resources/propresentersongs/__init__.py | 0 tests/resources/remotes/__init__.py | 0 tests/resources/service/__init__.py | 0 tests/resources/songbeamersongs/__init__.py | 0 tests/resources/songprosongs/__init__.py | 0 tests/resources/songs/__init__.py | 0 tests/resources/songselect/__init__.py | 0 tests/resources/songshowplussongs/__init__.py | 0 tests/resources/sundayplussongs/__init__.py | 0 tests/resources/themes/Default/__init__.py | 0 tests/resources/themes/__init__.py | 0 tests/resources/videopsalmsongs/__init__.py | 0 tests/resources/wordsofworshipsongs/__init__.py | 0 tests/resources/worshipassistantsongs/__init__.py | 0 tests/resources/zionworxsongs/__init__.py | 0 26 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/resources/__init__.py create mode 100644 tests/resources/bibles/__init__.py create mode 100644 tests/resources/easyslidessongs/__init__.py create mode 100644 tests/resources/easyworshipsongs/__init__.py create mode 100644 tests/resources/lyrixsongs/__init__.py create mode 100644 tests/resources/openlyricssongs/__init__.py create mode 100644 tests/resources/opensongsongs/__init__.py create mode 100644 tests/resources/powerpraisesongs/__init__.py create mode 100644 tests/resources/presentationmanagersongs/__init__.py create mode 100644 tests/resources/presentations/__init__.py create mode 100644 tests/resources/projector/__init__.py create mode 100644 tests/resources/propresentersongs/__init__.py create mode 100644 tests/resources/remotes/__init__.py create mode 100644 tests/resources/service/__init__.py create mode 100644 tests/resources/songbeamersongs/__init__.py create mode 100644 tests/resources/songprosongs/__init__.py create mode 100644 tests/resources/songs/__init__.py create mode 100644 tests/resources/songselect/__init__.py create mode 100644 tests/resources/songshowplussongs/__init__.py create mode 100644 tests/resources/sundayplussongs/__init__.py create mode 100644 tests/resources/themes/Default/__init__.py create mode 100644 tests/resources/themes/__init__.py create mode 100644 tests/resources/videopsalmsongs/__init__.py create mode 100644 tests/resources/wordsofworshipsongs/__init__.py create mode 100644 tests/resources/worshipassistantsongs/__init__.py create mode 100644 tests/resources/zionworxsongs/__init__.py diff --git a/tests/resources/__init__.py b/tests/resources/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/bibles/__init__.py b/tests/resources/bibles/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/easyslidessongs/__init__.py b/tests/resources/easyslidessongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/easyworshipsongs/__init__.py b/tests/resources/easyworshipsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/lyrixsongs/__init__.py b/tests/resources/lyrixsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/openlyricssongs/__init__.py b/tests/resources/openlyricssongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/opensongsongs/__init__.py b/tests/resources/opensongsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/powerpraisesongs/__init__.py b/tests/resources/powerpraisesongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/presentationmanagersongs/__init__.py b/tests/resources/presentationmanagersongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/presentations/__init__.py b/tests/resources/presentations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/projector/__init__.py b/tests/resources/projector/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/propresentersongs/__init__.py b/tests/resources/propresentersongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/remotes/__init__.py b/tests/resources/remotes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/service/__init__.py b/tests/resources/service/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/songbeamersongs/__init__.py b/tests/resources/songbeamersongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/songprosongs/__init__.py b/tests/resources/songprosongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/songs/__init__.py b/tests/resources/songs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/songselect/__init__.py b/tests/resources/songselect/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/songshowplussongs/__init__.py b/tests/resources/songshowplussongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/sundayplussongs/__init__.py b/tests/resources/sundayplussongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/themes/Default/__init__.py b/tests/resources/themes/Default/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/themes/__init__.py b/tests/resources/themes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/videopsalmsongs/__init__.py b/tests/resources/videopsalmsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/wordsofworshipsongs/__init__.py b/tests/resources/wordsofworshipsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/worshipassistantsongs/__init__.py b/tests/resources/worshipassistantsongs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/zionworxsongs/__init__.py b/tests/resources/zionworxsongs/__init__.py new file mode 100644 index 000000000..e69de29bb From 47f20598d59e8d5767cbef22efc67fbc55c7585b Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 15 Dec 2016 12:30:16 +0200 Subject: [PATCH 3/5] Only need __init__.py files for directories with Python files in them --- tests/resources/bibles/__init__.py | 0 tests/resources/easyslidessongs/__init__.py | 0 tests/resources/easyworshipsongs/__init__.py | 0 tests/resources/lyrixsongs/__init__.py | 0 tests/resources/openlyricssongs/__init__.py | 0 tests/resources/opensongsongs/__init__.py | 0 tests/resources/powerpraisesongs/__init__.py | 0 tests/resources/presentationmanagersongs/__init__.py | 0 tests/resources/presentations/__init__.py | 0 tests/resources/propresentersongs/__init__.py | 0 tests/resources/remotes/__init__.py | 0 tests/resources/service/__init__.py | 0 tests/resources/songbeamersongs/__init__.py | 0 tests/resources/songprosongs/__init__.py | 0 tests/resources/songs/__init__.py | 0 tests/resources/songselect/__init__.py | 0 tests/resources/songshowplussongs/__init__.py | 0 tests/resources/sundayplussongs/__init__.py | 0 tests/resources/themes/Default/__init__.py | 0 tests/resources/themes/__init__.py | 0 tests/resources/videopsalmsongs/__init__.py | 0 tests/resources/wordsofworshipsongs/__init__.py | 0 tests/resources/worshipassistantsongs/__init__.py | 0 tests/resources/zionworxsongs/__init__.py | 0 24 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/resources/bibles/__init__.py delete mode 100644 tests/resources/easyslidessongs/__init__.py delete mode 100644 tests/resources/easyworshipsongs/__init__.py delete mode 100644 tests/resources/lyrixsongs/__init__.py delete mode 100644 tests/resources/openlyricssongs/__init__.py delete mode 100644 tests/resources/opensongsongs/__init__.py delete mode 100644 tests/resources/powerpraisesongs/__init__.py delete mode 100644 tests/resources/presentationmanagersongs/__init__.py delete mode 100644 tests/resources/presentations/__init__.py delete mode 100644 tests/resources/propresentersongs/__init__.py delete mode 100644 tests/resources/remotes/__init__.py delete mode 100644 tests/resources/service/__init__.py delete mode 100644 tests/resources/songbeamersongs/__init__.py delete mode 100644 tests/resources/songprosongs/__init__.py delete mode 100644 tests/resources/songs/__init__.py delete mode 100644 tests/resources/songselect/__init__.py delete mode 100644 tests/resources/songshowplussongs/__init__.py delete mode 100644 tests/resources/sundayplussongs/__init__.py delete mode 100644 tests/resources/themes/Default/__init__.py delete mode 100644 tests/resources/themes/__init__.py delete mode 100644 tests/resources/videopsalmsongs/__init__.py delete mode 100644 tests/resources/wordsofworshipsongs/__init__.py delete mode 100644 tests/resources/worshipassistantsongs/__init__.py delete mode 100644 tests/resources/zionworxsongs/__init__.py diff --git a/tests/resources/bibles/__init__.py b/tests/resources/bibles/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/easyslidessongs/__init__.py b/tests/resources/easyslidessongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/easyworshipsongs/__init__.py b/tests/resources/easyworshipsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/lyrixsongs/__init__.py b/tests/resources/lyrixsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/openlyricssongs/__init__.py b/tests/resources/openlyricssongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/opensongsongs/__init__.py b/tests/resources/opensongsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/powerpraisesongs/__init__.py b/tests/resources/powerpraisesongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/presentationmanagersongs/__init__.py b/tests/resources/presentationmanagersongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/presentations/__init__.py b/tests/resources/presentations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/propresentersongs/__init__.py b/tests/resources/propresentersongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/remotes/__init__.py b/tests/resources/remotes/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/service/__init__.py b/tests/resources/service/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/songbeamersongs/__init__.py b/tests/resources/songbeamersongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/songprosongs/__init__.py b/tests/resources/songprosongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/songs/__init__.py b/tests/resources/songs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/songselect/__init__.py b/tests/resources/songselect/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/songshowplussongs/__init__.py b/tests/resources/songshowplussongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/sundayplussongs/__init__.py b/tests/resources/sundayplussongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/themes/Default/__init__.py b/tests/resources/themes/Default/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/themes/__init__.py b/tests/resources/themes/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/videopsalmsongs/__init__.py b/tests/resources/videopsalmsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/wordsofworshipsongs/__init__.py b/tests/resources/wordsofworshipsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/worshipassistantsongs/__init__.py b/tests/resources/worshipassistantsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/resources/zionworxsongs/__init__.py b/tests/resources/zionworxsongs/__init__.py deleted file mode 100644 index e69de29bb..000000000 From bd5056fb09bce4e57c3efdc71fc6cbee7fbdccfd Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 15 Dec 2016 13:01:51 +0200 Subject: [PATCH 4/5] Added a test but forgot the actual fix --- openlp/core/ui/projector/sourceselectform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index cf19552c3..3ae086de5 100644 --- a/openlp/core/ui/projector/sourceselectform.py +++ b/openlp/core/ui/projector/sourceselectform.py @@ -173,7 +173,7 @@ class FingerTabBarWidget(QtWidgets.QTabBar): :param width: Remove default width parameter in kwargs :param height: Remove default height parameter in kwargs """ - self.tabSize = QtWidgets.QSize(kwargs.pop('width', 100), kwargs.pop('height', 25)) + self.tabSize = QtCore.QSize(kwargs.pop('width', 100), kwargs.pop('height', 25)) QtWidgets.QTabBar.__init__(self, parent, *args, **kwargs) def paintEvent(self, event): From 7bfdc7deef3cec8ad2ddcf13f69d3fdc8f2f3e91 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 15 Dec 2016 13:18:02 +0200 Subject: [PATCH 5/5] Add some tests around the fix --- .../test_projector_sourceselectform.py | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_ui/test_projector_sourceselectform.py b/tests/functional/openlp_core_ui/test_projector_sourceselectform.py index 51ba4bcc3..85592dd15 100644 --- a/tests/functional/openlp_core_ui/test_projector_sourceselectform.py +++ b/tests/functional/openlp_core_ui/test_projector_sourceselectform.py @@ -24,7 +24,9 @@ Tests for the Projector Source Select form. """ -from openlp.core.ui.projector.sourceselectform import source_group +from PyQt5 import QtCore + +from openlp.core.ui.projector.sourceselectform import FingerTabBarWidget, source_group def test_source_group(): @@ -52,3 +54,30 @@ def test_source_group(): 'h': {'hdmi1': 'HDMI 1', 'hdmi2': 'HDMI 2'} } assert result == expected_dict, result + + +def test_finger_tab_bar_widget(): + """ + Test that the FingerTabBarWidget is initialised correctly + """ + # GIVEN: A FinderTabBarWidget class + # WHEN: An instance of the FingerTabBarWidget is created + widget = FingerTabBarWidget() + + # THEN: It should havea tabSize of 100x25 + assert widget.tabSize == QtCore.QSize(100, 25) + + +def test_finger_tab_bar_widget_with_kwargs(): + """ + Test that the FingerTabBarWidget is initialised correctly from kwargs + """ + # GIVEN: A FinderTabBarWidget class and some arguments + width = 300 + height = 100 + + # WHEN: An instance of the FingerTabBarWidget is created + widget = FingerTabBarWidget(width=width, height=height) + + # THEN: It should havea tabSize of 100x25 + assert widget.tabSize == QtCore.QSize(width, height)