openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #19229
[Merge] lp:~googol/openlp/bug-1100277 into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/bug-1100277 into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Related bugs:
Bug #1100277 in OpenLP: "Songs don't load with latest build"
https://bugs.launchpad.net/openlp/+bug/1100277
For more details, see:
https://code.launchpad.net/~googol/openlp/bug-1100277/+merge/146942
Hello,
- fixed Bug #1100277 (Songs don't load with latest build)
The translate() returns a unicode object instead of a QString since the sip change. And %1 is a QString feature, but as a unicode object is returned, we cannot use this. At leasts that my explanation. ;)
http://pastebin.com/mqewVcMM
NOTE: Fix has to verified by ElderP!
--
https://code.launchpad.net/~googol/openlp/bug-1100277/+merge/146942
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/bug-1100277 into lp:openlp.
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py 2013-02-02 20:54:34 +0000
+++ openlp/core/lib/__init__.py 2013-02-06 19:53:26 +0000
@@ -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,23 +367,23 @@
``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''
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
=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
--- tests/functional/openlp_core_lib/test_lib.py 2013-01-21 20:15:10 +0000
+++ tests/functional/openlp_core_lib/test_lib.py 2013-02-06 19:53:26 +0000
@@ -7,7 +7,7 @@
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 @@
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 @@
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 @@
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') 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\'.'
+
+ def create_separated_list_empty_list_test(self):
+ """
+ """
+ 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 = []
+
+ # 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') 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']
+
+ # 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') 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']
+
+ # 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') 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']
+
+ # 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\'.'
Follow ups