From ad1970f27e8eeaa54f9fcbeab66e6da297172f1d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sat, 22 Mar 2014 10:53:55 +0100 Subject: [PATCH 1/5] fixed spelling --- openlp/core/ui/mainwindow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 3526e551f..e1f1dc51f 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -652,7 +652,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow, RegistryProperties): translate('OpenLP.MainWindow', 'Are you sure you want to re-run the First ' 'Time Wizard?\n\nRe-running this wizard may make changes to your ' 'current OpenLP configuration and possibly add songs to your ' - '#existing songs list and change your default theme.'), + 'existing songs list and change your default theme.'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) From 7a1825a79a44a7bdda5c029734a61dfb4fee9dda Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 23 Mar 2014 11:49:03 +0100 Subject: [PATCH 2/5] tests --- openlp/core/lib/searchedit.py | 13 +- .../openlp_core_lib/test_searchedit.py | 137 ++++++++++++++++++ 2 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 tests/interfaces/openlp_core_lib/test_searchedit.py diff --git a/openlp/core/lib/searchedit.py b/openlp/core/lib/searchedit.py index d6eaafa7d..4e79beaae 100644 --- a/openlp/core/lib/searchedit.py +++ b/openlp/core/lib/searchedit.py @@ -179,15 +179,8 @@ class SearchEdit(QtGui.QLineEdit): correct action on the button, and set the current search type (using the list of identifiers provided by the developer), the ``searchTypeChanged(int)`` signal is emitted with the identifier. """ - sender = self.sender() for action in self.menu_button.menu().actions(): + # Why is this needed? action.setChecked(False) - self.menu_button.setDefaultAction(sender) - self._current_search_type = sender.data() - # setplaceholder_text has been implemented in Qt 4.7 and in at least - # PyQt 4.9 (I am not sure, if it was implemented in PyQt 4.8). - try: - self.setPlaceholderText(self.menu_button.defaultAction().placeholder_text) - except AttributeError: - pass - self.emit(QtCore.SIGNAL('searchTypeChanged(int)'), self._current_search_type) + sender = self.sender() + self.set_current_search_type(sender.data()) diff --git a/tests/interfaces/openlp_core_lib/test_searchedit.py b/tests/interfaces/openlp_core_lib/test_searchedit.py new file mode 100644 index 000000000..5814d10f8 --- /dev/null +++ b/tests/interfaces/openlp_core_lib/test_searchedit.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2014 Raoul Snyman # +# Portions copyright (c) 2008-2014 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# 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 # +############################################################################### +""" +Module to test the EditCustomForm. +""" +from unittest import TestCase +from unittest.mock import MagicMock + +from PyQt4 import QtCore, QtGui, QtTest + +from openlp.core.common import Registry +from openlp.core.lib.searchedit import SearchEdit +from tests.helpers.testmixin import TestMixin + + +class SearchTypes(object): + First = 0 + Second = 1 + + +SECOND_PLACEHOLDER_TEXT = "Second Placeholder Text" +SEARCH_TYPES = [(SearchTypes.First, QtGui.QIcon(), "First", "First Placeholder Text"), + (SearchTypes.Second, QtGui.QIcon(), "Second", SECOND_PLACEHOLDER_TEXT)] + + +class TestSearchEdit(TestCase, TestMixin): + """ + Test the EditCustomForm. + """ + def setUp(self): + """ + Create the UI + """ + Registry.create() + self.get_application() + self.main_window = QtGui.QMainWindow() + Registry().register('main_window', self.main_window) + + self.search_edit = SearchEdit(self.main_window) + # To complete set up we have to set the search types. + self.search_edit.set_search_types(SEARCH_TYPES) + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.main_window + + + def set_search_types_test(self): + """ + Test setting the search types of the search edit. + """ + # GIVEN: The search edit with the search types set. NOTE: The set_search_types(types) is called in the setUp() + # method! + + # WHEN: + + # THEN: The first search type should be the first one in the list. + assert self.search_edit.current_search_type() == SearchTypes.First, "The first search type should be selected." + + def set_current_search_type_test(self): + """ + Test if changing the search type works. + """ + # GIVEN: + # WHEN: Change the search type + result = self.search_edit.set_current_search_type(SearchTypes.Second) + + # THEN: + assert result, "The call should return success (True)." + assert self.search_edit.current_search_type() == SearchTypes.Second,\ + "The search type should be SearchTypes.Second" + assert self.search_edit.placeholderText() == SECOND_PLACEHOLDER_TEXT,\ + "The correct placeholder text should be 'Second Placeholder Text'." + + def clear_button_visibility_test(self): + """ + Test if the clear button is hidden/shown correctly. + """ + # GIVEN: Everything is left to its defaults (hidden). + assert self.search_edit.clear_button.isHidden(), "Pre condition not met. Button should be hidden." + + # WHEN: Type something in the search edit. + QtTest.QTest.keyPress(self.search_edit, QtCore.Qt.Key_A) + QtTest.QTest.keyRelease(self.search_edit, QtCore.Qt.Key_A) + + # THEN: The clear button should not be hidden any more. + assert not self.search_edit.clear_button.isHidden(), "The clear button should be visible." + + def press_clear_button_test(self): + """ + Check if the search edit behaves correctly when pressing the clear button. + """ + # GIVEN: A search edit with text. + QtTest.QTest.keyPress(self.search_edit, QtCore.Qt.Key_A) + QtTest.QTest.keyRelease(self.search_edit, QtCore.Qt.Key_A) + + # WHEN: Press the clear button. + QtTest.QTest.mouseClick(self.search_edit.clear_button, QtCore.Qt.LeftButton) + + # THEN: The search edit text should be cleared and the button be hidden. + assert not self.search_edit.text(), "The search edit should not have any text." + assert self.search_edit.clear_button.isHidden(), "The clear button should be hidden." + + def resize_event_test(self): + """ + Just check if the resizeEvent() method is re-implemented. + """ + assert hasattr(self.search_edit, "resizeEvent"), "The search edit should re-implement the resizeEvent method." + \ No newline at end of file From fcf4d0ce1767f0f211d6497cdc5f37a9b99eb2e2 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 23 Mar 2014 11:53:11 +0100 Subject: [PATCH 3/5] missing line at the end --- tests/interfaces/openlp_core_lib/test_searchedit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/interfaces/openlp_core_lib/test_searchedit.py b/tests/interfaces/openlp_core_lib/test_searchedit.py index 5814d10f8..07db05dd7 100644 --- a/tests/interfaces/openlp_core_lib/test_searchedit.py +++ b/tests/interfaces/openlp_core_lib/test_searchedit.py @@ -134,4 +134,5 @@ class TestSearchEdit(TestCase, TestMixin): Just check if the resizeEvent() method is re-implemented. """ assert hasattr(self.search_edit, "resizeEvent"), "The search edit should re-implement the resizeEvent method." + \ No newline at end of file From b4bf94a4f073b281f8626cadb23a5d8afe7bde1a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 28 Mar 2014 21:41:27 +0100 Subject: [PATCH 4/5] pep8 --- tests/interfaces/openlp_core_lib/test_searchedit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/interfaces/openlp_core_lib/test_searchedit.py b/tests/interfaces/openlp_core_lib/test_searchedit.py index 07db05dd7..98c942885 100644 --- a/tests/interfaces/openlp_core_lib/test_searchedit.py +++ b/tests/interfaces/openlp_core_lib/test_searchedit.py @@ -72,7 +72,6 @@ class TestSearchEdit(TestCase, TestMixin): """ del self.main_window - def set_search_types_test(self): """ Test setting the search types of the search edit. From 93ff30184012341f68e9bc40482d3773435a6a2b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 31 Mar 2014 14:13:50 +0200 Subject: [PATCH 5/5] cleanup: remove local variable --- openlp/core/lib/searchedit.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/lib/searchedit.py b/openlp/core/lib/searchedit.py index 13e388775..de329236c 100644 --- a/openlp/core/lib/searchedit.py +++ b/openlp/core/lib/searchedit.py @@ -181,5 +181,4 @@ class SearchEdit(QtGui.QLineEdit): for action in self.menu_button.menu().actions(): # Why is this needed? action.setChecked(False) - sender = self.sender() - self.set_current_search_type(sender.data()) + self.set_current_search_type(self.sender().data())