diff --git a/openlp/core/ui/projector/sourceselectform.py b/openlp/core/ui/projector/sourceselectform.py index f47622090..3ae086de5 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. @@ -174,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): @@ -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..85592dd15 --- /dev/null +++ b/tests/functional/openlp_core_ui/test_projector_sourceselectform.py @@ -0,0 +1,83 @@ +# -*- 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 PyQt5 import QtCore + +from openlp.core.ui.projector.sourceselectform import FingerTabBarWidget, 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 + + +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) 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: diff --git a/tests/resources/__init__.py b/tests/resources/__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