From ede9bb70d93984927dd2c88e772fb26358403ec4 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 5 Feb 2013 18:36:43 +0100 Subject: [PATCH 01/20] attempt to fix bug #1100277 Fixes: https://launchpad.net/bugs/1100277 --- openlp/core/lib/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index c34c824db..ca8a46126 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -373,16 +373,15 @@ def create_separated_list(stringlist): elif len(stringlist) == 1: return stringlist[0] elif len(stringlist) == 2: - return translate('OpenLP.core.lib', '%1 and %2', + return translate('OpenLP.core.lib', '%s and %s', 'Locale list separator: 2 items') % (stringlist[0], stringlist[1]) else: - merged = translate('OpenLP.core.lib', '%1, and %2', + merged = translate('OpenLP.core.lib', '%s, and %s', u'Locale list separator: end') % (stringlist[-2], stringlist[-1]) for index in reversed(range(1, len(stringlist) - 2)): - merged = translate('OpenLP.core.lib', '%1, %2', - u'Locale list separator: middle') % (stringlist[index], merged) - return translate('OpenLP.core.lib', '%1, %2', - u'Locale list separator: start') % (stringlist[0], merged) + merged = translate('OpenLP.core.lib', '%s, %s', + u'Locale list separator: middle') % (stringlist[index], merged) + return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) from registry import Registry From 6e17ff9d9e4d4e1239dd48e06434b5ce1ffd6b29 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 5 Feb 2013 19:57:08 +0000 Subject: [PATCH 02/20] Set lineEdit focus when displaying form --- openlp/core/ui/filerenameform.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index 0743578a1..ccdca9928 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -56,4 +56,5 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Copy')) else: self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) + self.fileNameEdit.setFocus() return QtGui.QDialog.exec_(self) From 022f0e0184b7f689ba598e1deb90dea203dc1d1f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 18:36:36 +0100 Subject: [PATCH 03/20] started with tests --- tests/functional/openlp_core_lib/test_lib.py | 98 +++++++++++++++++++- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 176197e24..8c1f87852 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -7,7 +7,7 @@ from datetime import datetime, timedelta from mock import MagicMock, patch from openlp.core.lib import str_to_bool, translate, check_directory_exists, get_text_file_string, build_icon, \ - image_to_byte, check_item_selected, validate_thumb + image_to_byte, check_item_selected, validate_thumb, create_separated_list class TestLib(TestCase): @@ -308,14 +308,14 @@ class TestLib(TestCase): file_path = u'path/to/file' thumb_path = u'path/to/thumb' mocked_os.path.exists.return_value = False - + # WHEN: we run the validate_thumb() function result = validate_thumb(file_path, thumb_path) - + # THEN: we should have called a few functions, and the result should be False mocked_os.path.exists.assert_called_with(thumb_path) assert result is False, u'The result should be False' - + def validate_thumb_file_exists_and_newer_test(self): """ Test the validate_thumb() function when the thumbnail exists and has a newer timestamp than the file @@ -350,7 +350,7 @@ class TestLib(TestCase): thumb_mocked_stat.st_mtime = datetime.now() - timedelta(seconds=10) mocked_os.path.exists.return_value = True mocked_os.stat.side_effect = lambda fname: file_mocked_stat if fname == file_path else thumb_mocked_stat - + # WHEN: we run the validate_thumb() function result = validate_thumb(file_path, thumb_path) @@ -359,3 +359,91 @@ class TestLib(TestCase): mocked_os.stat.assert_any_call(file_path) mocked_os.stat.assert_any_call(thumb_path) assert result is False, u'The result should be False' + + def create_separated_list_qlocate_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'4.9' + qt_version.return_value = u'4.8' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2', u'Author 3'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2, and Author 3\'.' + + def create_separated_list_empty_list_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'', u'The string sould be empty.' + + def create_separated_list_with_one_item_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [u'Author 1'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1', u'The string should be u\'Author 1\'.' + + def create_separated_list_with_two_items_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ + patch(u'openlp.core.lib.translate') as mocked_translate: + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + mocked_translate.return_value = u'%s and %s' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1 and Author 2', u'The string should be u\'Author 1 and Author 2\'.' + + def create_separated_list_with_three_items_test(self): + """ + """ + with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ + patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ + patch(u'openlp.core.lib.translate') as mocked_translate: + # I need two translate functions returning two different things! + mocked_translate.return_value = u'' + pyqt_version.return_value = u'3.0' + qt_version.return_value = u'3.0' + # GIVEN: A list of strings. + string_list = [u'Author 1', u'Author 2', u'Author 3'] + + # WHEN: We get a string build from the entries it the list and a seperator. + string_result = create_separated_list(string_list) + + # THEN: + assert string_result == u'Author 1, Author 2 and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2 and Author 3\'.' + From 2c8f0e66b2887680e1128a52b92d728769f01e4e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:45:11 +0100 Subject: [PATCH 04/20] comleted tests --- tests/functional/openlp_core_lib/test_lib.py | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 8c1f87852..aa3291d78 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -363,16 +363,20 @@ class TestLib(TestCase): def create_separated_list_qlocate_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'4.9' - qt_version.return_value = u'4.8' + with patch(u'openlp.core.lib.Qt') as mocked_QT, \ + patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: + mocked_QT.PYQT_VERSION_STR = u'4.9' + mocked_QT.qVersion.return_value = u'4.8' + mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) + print string_result + # THEN: assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' @@ -380,10 +384,10 @@ class TestLib(TestCase): def create_separated_list_empty_list_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [] @@ -396,10 +400,10 @@ class TestLib(TestCase): def create_separated_list_with_one_item_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [u'Author 1'] @@ -412,12 +416,11 @@ class TestLib(TestCase): def create_separated_list_with_two_items_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ - patch(u'openlp.core.lib.translate') as mocked_translate: - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2'] @@ -430,13 +433,11 @@ class TestLib(TestCase): def create_separated_list_with_three_items_test(self): """ """ - with patch(u'openlp.core.lib.Qt.PYQT_VERSION_STR') as pyqt_version, \ - patch(u'openlp.core.lib.Qt.qVersion') as qt_version, \ - patch(u'openlp.core.lib.translate') as mocked_translate: - # I need two translate functions returning two different things! - mocked_translate.return_value = u'' - pyqt_version.return_value = u'3.0' - qt_version.return_value = u'3.0' + with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate + mocked_QT.PYQT_VERSION_STR = u'4.8' + mocked_QT.qVersion.return_value = u'4.7' + # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] @@ -444,6 +445,5 @@ class TestLib(TestCase): string_result = create_separated_list(string_list) # THEN: - assert string_result == u'Author 1, Author 2 and Author 3', u'The string should be u\'Author 1, ' \ - 'Author 2 and Author 3\'.' - + assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ + 'Author 2, and Author 3\'.' From 818bd4a4353553aedb036ecebee880031f66ff33 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:49:39 +0100 Subject: [PATCH 05/20] fixed version number compare --- openlp/core/lib/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ca8a46126..d7b5ef8b5 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -30,6 +30,7 @@ The :mod:`lib` module contains most of the components and libraries that make OpenLP work. """ +from distutils.version import LooseVersion import logging import os @@ -366,7 +367,8 @@ def create_separated_list(stringlist): ``stringlist`` List of unicode strings """ - if Qt.PYQT_VERSION_STR >= u'4.9' and Qt.qVersion() >= u'4.8': + if LooseVersion(Qt.PYQT_VERSION_STR) >= LooseVersion(u'4.9') and \ + LooseVersion(Qt.qVersion()) >= LooseVersion(u'4.8'): return QtCore.QLocale().createSeparatedList(stringlist) if not stringlist: return u'' From fe74e66400695264febd743f791b588d58fe0ac0 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 20:55:28 +0100 Subject: [PATCH 06/20] docs ;) --- tests/functional/openlp_core_lib/test_lib.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index aa3291d78..e78f78c0d 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -362,6 +362,7 @@ class TestLib(TestCase): def create_separated_list_qlocate_test(self): """ + Test the create_separated_list function using the Qt provided method. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: @@ -383,6 +384,7 @@ class TestLib(TestCase): def create_separated_list_empty_list_test(self): """ + Test the create_separated_list function with an empty list. """ with patch(u'openlp.core.lib.Qt') as mocked_QT: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -399,6 +401,7 @@ class TestLib(TestCase): def create_separated_list_with_one_item_test(self): """ + Test the create_separated_list function with a list consisting of only one entry. """ with patch(u'openlp.core.lib.Qt') as mocked_QT: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -415,6 +418,7 @@ class TestLib(TestCase): def create_separated_list_with_two_items_test(self): """ + Test the create_separated_list function with a list of two entries. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_QT.PYQT_VERSION_STR = u'4.8' @@ -432,6 +436,7 @@ class TestLib(TestCase): def create_separated_list_with_three_items_test(self): """ + Test the create_separated_list function with a list of three items. """ with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate From 4c2bc4667375e06f4feefadd9b66d5e5cd90afcc Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:36:59 +0100 Subject: [PATCH 07/20] added nose to checkdependencies script --- scripts/check_dependencies.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index be15414b4..4b56acb63 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -40,6 +40,12 @@ import os import sys from distutils.version import LooseVersion +# If we import uno before nose this will greate a warning. Just try to import nose first to supress the warning. +try: + import nose +except ImportError: + pass + is_win = sys.platform.startswith('win') VERS = { @@ -85,6 +91,7 @@ OPTIONAL_MODULES = [ ('MySQLdb', ' (MySQL support)'), ('psycopg2', ' (PostgreSQL support)'), ('pytest', ' (testing framework)'), + ('nose', ' (testing framework)'), ] w = sys.stdout.write From 1fc779e8ed3faf8cdc390fb0e42eb1c2c39e0e08 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:37:30 +0100 Subject: [PATCH 08/20] use CAPS --- scripts/check_dependencies.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 4b56acb63..2035d1bb0 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -46,7 +46,7 @@ try: except ImportError: pass -is_win = sys.platform.startswith('win') +IS_WIN = sys.platform.startswith('win') VERS = { 'Python': '2.6', @@ -54,7 +54,7 @@ VERS = { 'Qt4': '4.6', 'sqlalchemy': '0.5', # pyenchant 1.6 required on Windows - 'enchant': '1.6' if is_win else '1.3' + 'enchant': '1.6' if IS_WIN else '1.3' } # pywin32 @@ -183,7 +183,7 @@ def main(): for m in OPTIONAL_MODULES: check_module(m[0], text=m[1]) - if is_win: + if IS_WIN: print('Checking for Windows specific modules...') for m in WIN32_MODULES: check_module(m) From 47fa8209ba9c5e9d47cc124e95e811f7188070c7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:42:09 +0100 Subject: [PATCH 09/20] changed wording --- scripts/check_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 2035d1bb0..52b832c48 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -40,7 +40,7 @@ import os import sys from distutils.version import LooseVersion -# If we import uno before nose this will greate a warning. Just try to import nose first to supress the warning. +# If we try to import uno before nose this will greate a warning. Just try to import nose first to supress the warning. try: import nose except ImportError: From ed38ba35192763c36728a2eb01ea613516b52254 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 21:47:57 +0100 Subject: [PATCH 10/20] fixed comments --- tests/functional/openlp_core_lib/test_lib.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index e78f78c0d..b05eb8da6 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -378,7 +378,7 @@ class TestLib(TestCase): print string_result - # THEN: + # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' @@ -396,7 +396,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We shoud have an emptry string. assert string_result == u'', u'The string sould be empty.' def create_separated_list_with_one_item_test(self): @@ -413,7 +413,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1" assert string_result == u'Author 1', u'The string should be u\'Author 1\'.' def create_separated_list_with_two_items_test(self): @@ -431,7 +431,7 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1 and Author 2" assert string_result == u'Author 1 and Author 2', u'The string should be u\'Author 1 and Author 2\'.' def create_separated_list_with_three_items_test(self): @@ -449,6 +449,6 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - # THEN: + # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' From 396d0b1cd20a0e79017a44b00d458d0747f36d9b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 22:39:52 +0100 Subject: [PATCH 11/20] remove pytest and renamed mocked function --- scripts/check_dependencies.py | 1 - tests/functional/openlp_core_lib/test_lib.py | 30 ++++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 52b832c48..3485b8505 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -90,7 +90,6 @@ OPTIONAL_MODULES = [ ('sqlite', ' (SQLite 2 support)'), ('MySQLdb', ' (MySQL support)'), ('psycopg2', ' (PostgreSQL support)'), - ('pytest', ' (testing framework)'), ('nose', ' (testing framework)'), ] diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index b05eb8da6..6035085e4 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -364,10 +364,10 @@ class TestLib(TestCase): """ Test the create_separated_list function using the Qt provided method. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, \ + with patch(u'openlp.core.lib.Qt') as mocked_qt, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: - mocked_QT.PYQT_VERSION_STR = u'4.9' - mocked_QT.qVersion.return_value = u'4.8' + mocked_qt.PYQT_VERSION_STR = u'4.9' + mocked_qt.qVersion.return_value = u'4.8' mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' # GIVEN: A list of strings. @@ -386,9 +386,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with an empty list. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [] @@ -403,9 +403,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list consisting of only one entry. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [u'Author 1'] @@ -420,9 +420,9 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list of two entries. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' # GIVEN: A list of strings. @@ -438,10 +438,10 @@ class TestLib(TestCase): """ Test the create_separated_list function with a list of three items. """ - with patch(u'openlp.core.lib.Qt') as mocked_QT, patch(u'openlp.core.lib.translate') as mocked_translate: + with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate - mocked_QT.PYQT_VERSION_STR = u'4.8' - mocked_QT.qVersion.return_value = u'4.7' + mocked_qt.PYQT_VERSION_STR = u'4.8' + mocked_qt.qVersion.return_value = u'4.7' # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] From 947cfce93184e9d748c8f456fc2588f6a166bf83 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 6 Feb 2013 22:50:55 +0100 Subject: [PATCH 12/20] cough... --- tests/functional/openlp_core_lib/test_lib.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 6035085e4..568051980 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -376,8 +376,6 @@ class TestLib(TestCase): # WHEN: We get a string build from the entries it the list and a seperator. string_result = create_separated_list(string_list) - print string_result - # THEN: We should have "Author 1, Author 2, and Author 3" assert string_result == u'Author 1, Author 2, and Author 3', u'The string should be u\'Author 1, ' \ 'Author 2, and Author 3\'.' From 589d335d3941a6b3b43c6e68a482cc8c055a112c Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Thu, 7 Feb 2013 21:55:22 +0000 Subject: [PATCH 13/20] Changed filerenamefor to registry. Started on test for filerenameform --- openlp/core/ui/filerenameform.py | 16 +++++++++++++--- openlp/core/ui/thememanager.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/filerenameform.py b/openlp/core/ui/filerenameform.py index ccdca9928..934a8dee8 100644 --- a/openlp/core/ui/filerenameform.py +++ b/openlp/core/ui/filerenameform.py @@ -34,18 +34,18 @@ from PyQt4 import QtGui from filerenamedialog import Ui_FileRenameDialog -from openlp.core.lib import translate +from openlp.core.lib import translate, Registry class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): """ The file rename dialog """ - def __init__(self, parent): + def __init__(self): """ Constructor """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) def exec_(self, copy=False): @@ -58,3 +58,13 @@ class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog): self.setWindowTitle(translate('OpenLP.FileRenameForm', 'File Rename')) self.fileNameEdit.setFocus() return QtGui.QDialog.exec_(self) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a482a3c44..666f80dbe 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -62,7 +62,7 @@ class ThemeManager(QtGui.QWidget): Registry().register(u'theme_manager', self) self.settingsSection = u'themes' self.themeForm = ThemeForm(self) - self.fileRenameForm = FileRenameForm(self) + self.fileRenameForm = FileRenameForm() # start with the layout self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) From e1552ddce19c23acd957de4aa58042e869041526 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 19:13:18 +0000 Subject: [PATCH 14/20] actually added test file --- .../openlp_core_ui/test_filerenamedialog.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/interfaces/openlp_core_ui/test_filerenamedialog.py diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py new file mode 100644 index 000000000..cc4f2b1c5 --- /dev/null +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -0,0 +1,83 @@ +""" + Package to test the openlp.core.ui package. +""" +from unittest import TestCase + +from mock import patch +from openlp.core.lib import Registry +from openlp.core.ui import filerenameform +from PyQt4 import QtCore, QtGui, QtTest + +class TestStartFileRenameForm(TestCase): + + def setUp(self): + """ + Create the UI + """ + registry = Registry.create() + self.app = QtGui.QApplication([]) + self.main_window = QtGui.QMainWindow() + Registry().register(u'main_window', self.main_window) + self.form = filerenameform.FileRenameForm() + + def tearDown(self): + """ + Delete all the C++ objects at the end so that we don't have a segfault + """ + del self.form + del self.main_window + del self.app + + def basic_display_test(self): + """ + Test FileRenameForm functionality + """ + # GIVEN: FileRenameForm with no ARGS + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + false_arg = False + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(false_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + + # GIVEN: FileRenameForm with False ARG + true_arg = True + + # WHEN displaying the UI and pressing enter + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_(true_arg) + + # THEN the window title is set as + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') + + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + + # THEN the lineEdit should have focus + self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') + + + + # Regression test for bug1067251 + # GIVEN: FileRenameForm with defaults + + # WHEN displaying the UI + # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + # self.form.exec_() + + # THEN the lineEdit should have focus + #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file From 7d7da00848bedb375f2557b611b0e2fc00079b4f Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Fri, 8 Feb 2013 21:49:26 +0000 Subject: [PATCH 15/20] made changes according to Superfly's instructions. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index cc4f2b1c5..0f5cfb9cf 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -35,7 +35,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with no ARGS # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the window title is set as @@ -45,7 +45,7 @@ class TestStartFileRenameForm(TestCase): false_arg = False # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(false_arg) # THEN the window title is set as @@ -55,7 +55,7 @@ class TestStartFileRenameForm(TestCase): true_arg = True # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_(true_arg) # THEN the window title is set as @@ -64,7 +64,7 @@ class TestStartFileRenameForm(TestCase): # GIVEN: FileRenameForm with defaults # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: self.form.exec_() # THEN the lineEdit should have focus From 17200d85fc94f51f2accf73aa69ea94f14989c87 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Sat, 9 Feb 2013 21:23:43 +0000 Subject: [PATCH 16/20] some more changes to the test --- .../openlp_core_ui/test_filerenamedialog.py | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 0f5cfb9cf..9e242f0d5 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -28,56 +28,42 @@ class TestStartFileRenameForm(TestCase): del self.main_window del self.app - def basic_display_test(self): + def window_title_test(self): """ - Test FileRenameForm functionality + Test the windowTitle of the FileRenameDialog """ - # GIVEN: FileRenameForm with no ARGS - - # WHEN displaying the UI + # GIVEN: A mocked QDialog.exec_() method with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + + # WHEN: The form is executed with no args self.form.exec_() - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # GIVEN: FileRenameForm with False ARG - false_arg = False + # WHEN: The form is executed with False arg + self.form.exec_(False) - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(false_arg) + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Rename', u'The window title should be "File Rename"') + # WHEN: The form is executed with True arg + self.form.exec_(True) - # GIVEN: FileRenameForm with False ARG - true_arg = True + # THEN: the window title is set correctly + self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - # WHEN displaying the UI and pressing enter - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: - self.form.exec_(true_arg) + def line_edit_focus_test(self): + """ + Regression test for bug1067251 + Test that the fileNameEdit setFocus has called with True when executed + """ + # GIVEN: A mocked QLineEdit class + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ + patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: - # THEN the window title is set as - self.assertEqual(self.form.windowTitle(), u'File Copy', u'The window title should be "File Copy"') - - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + # WHEN: The form is executed with no args self.form.exec_() - # THEN the lineEdit should have focus - self.assertEqual(self.form.fileNameEdit.hasFocus(), True, u'fileNameEdit should have focus.') - - - - # Regression test for bug1067251 - # GIVEN: FileRenameForm with defaults - - # WHEN displaying the UI - # with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: - # self.form.exec_() - - # THEN the lineEdit should have focus - #self.assertEqual(self.form.fileNameEdit.hasFocus(), u'File Rename', u'The window title should be "File Rename"') \ No newline at end of file + # THEN: the setFocus method of the fileNameEdit has been called with True + mocked_line_edit.setFocus.assert_called_with() From d0104bf7954b89238544dcf6c96e31b7691d88e6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 10 Feb 2013 19:59:00 +0100 Subject: [PATCH 17/20] fixed comments --- tests/functional/openlp_core_lib/test_lib.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_lib.py b/tests/functional/openlp_core_lib/test_lib.py index 568051980..8527373dc 100644 --- a/tests/functional/openlp_core_lib/test_lib.py +++ b/tests/functional/openlp_core_lib/test_lib.py @@ -366,11 +366,10 @@ class TestLib(TestCase): """ with patch(u'openlp.core.lib.Qt') as mocked_qt, \ patch(u'openlp.core.lib.QtCore.QLocale.createSeparatedList') as mocked_createSeparatedList: + # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.9' mocked_qt.qVersion.return_value = u'4.8' mocked_createSeparatedList.return_value = u'Author 1, Author 2, and Author 3' - - # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -385,10 +384,9 @@ class TestLib(TestCase): Test the create_separated_list function with an empty list. """ with patch(u'openlp.core.lib.Qt') as mocked_qt: + # GIVEN: An empty list and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. string_list = [] # WHEN: We get a string build from the entries it the list and a seperator. @@ -402,10 +400,9 @@ class TestLib(TestCase): Test the create_separated_list function with a list consisting of only one entry. """ with patch(u'openlp.core.lib.Qt') as mocked_qt: + # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. string_list = [u'Author 1'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -419,11 +416,10 @@ class TestLib(TestCase): Test the create_separated_list function with a list of two entries. """ with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: + # GIVEN: A list of strings and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' mocked_translate.return_value = u'%s and %s' - - # GIVEN: A list of strings. string_list = [u'Author 1', u'Author 2'] # WHEN: We get a string build from the entries it the list and a seperator. @@ -437,11 +433,11 @@ class TestLib(TestCase): Test the create_separated_list function with a list of three items. """ with patch(u'openlp.core.lib.Qt') as mocked_qt, patch(u'openlp.core.lib.translate') as mocked_translate: - mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate + # GIVEN: A list with a string and the mocked Qt module. mocked_qt.PYQT_VERSION_STR = u'4.8' mocked_qt.qVersion.return_value = u'4.7' - - # GIVEN: A list of strings. + # Always return the untranslated string. + mocked_translate.side_effect = lambda module, string_to_translate, comment: string_to_translate string_list = [u'Author 1', u'Author 2', u'Author 3'] # WHEN: We get a string build from the entries it the list and a seperator. From 75b8ed55fa130fbc317ca597fd02d38153cce957 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 11 Feb 2013 09:31:46 +0100 Subject: [PATCH 18/20] fixed bug 1047995 by reimplementing the keyPressEvent Fixes: https://launchpad.net/bugs/1047995 --- openlp/plugins/songs/forms/editsongform.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 46ea0029c..87f948aa0 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -116,6 +116,23 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.findVerseSplit = re.compile(u'---\[\]---\n', re.UNICODE) self.whitespace = re.compile(r'\W+', re.UNICODE) + def keyPressEvent(self, event): + """ + Reimplement the keyPressEvent to react on Return/Enter keys. When some combo boxes have focus we do not want + dialog's default action be triggered but instead our own. + + ``event`` + A QtGui.QKeyEvent event. + """ + if event.key() in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return): + if self.authorsComboBox.hasFocus() and self.authorsComboBox.currentText(): + self.onAuthorAddButtonClicked() + return + if self.topicsComboBox.hasFocus() and self.topicsComboBox.currentText(): + self.onTopicAddButtonClicked() + return + QtGui.QDialog.keyPressEvent(self, event) + def initialise(self): """ Set up the form for when it is displayed. From 35eebb2a8eec6dd6f0807b1e793b528c7da334e2 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Mon, 11 Feb 2013 20:47:53 +0000 Subject: [PATCH 19/20] Added validator test --- .../openlp_core_ui/test_filerenamedialog.py | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 9e242f0d5..3e22b11e1 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -3,10 +3,10 @@ """ from unittest import TestCase -from mock import patch +from mock import MagicMock, patch from openlp.core.lib import Registry from openlp.core.ui import filerenameform -from PyQt4 import QtCore, QtGui, QtTest +from PyQt4 import QtGui, QtTest class TestStartFileRenameForm(TestCase): @@ -58,12 +58,26 @@ class TestStartFileRenameForm(TestCase): Regression test for bug1067251 Test that the fileNameEdit setFocus has called with True when executed """ - # GIVEN: A mocked QLineEdit class - with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec, \ - patch(u'PyQt4.QtGui.QLineEdit') as mocked_line_edit: + # GIVEN: A mocked QDialog.exec_() method and mocked fileNameEdit.setFocus() method. + with patch(u'PyQt4.QtGui.QDialog.exec_') as mocked_exec: + mocked_set_focus = MagicMock() + self.form.fileNameEdit.setFocus = mocked_set_focus - # WHEN: The form is executed with no args + # WHEN: The form is executed self.form.exec_() # THEN: the setFocus method of the fileNameEdit has been called with True - mocked_line_edit.setFocus.assert_called_with() + mocked_set_focus.assert_called_with() + + def file_name_validation_test(self): + """ + Test the fileNameEdit validation + """ + # GIVEN: QLineEdit with a validator set with illegal file name characters. + + # WHEN: 'Typing' a string containing invalid file characters. + QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i \F[i\l]e" :N+a%me') + + # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered + # out. + self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name') From f419108e61440d018d97b2d0c351b42064f41c55 Mon Sep 17 00:00:00 2001 From: phill-ridout Date: Tue, 12 Feb 2013 19:26:19 +0000 Subject: [PATCH 20/20] Removed spacing from comments. --- tests/interfaces/openlp_core_ui/test_filerenamedialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 3e22b11e1..74fe83b26 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -79,5 +79,5 @@ class TestStartFileRenameForm(TestCase): QtTest.QTest.keyClicks(self.form.fileNameEdit, u'I/n\\v?a*l|i \F[i\l]e" :N+a%me') # THEN: The text in the QLineEdit should be the same as the input string with the invalid chatacters filtered - # out. + # out. self.assertEqual(self.form.fileNameEdit.text(), u'Invalid File Name')