← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol/openlp/bug-1100277 into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol/openlp/bug-1100277 into lp:openlp.

Requested reviews:
  Tim Bentley (trb143)
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/146971

Hello,

- fixed Bug #1100277 (Songs don't load with latest build)
- added nose to check_dependencies.py
- fixed version number compare in create_separated_list

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/146971
Your team OpenLP Core is subscribed to branch 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 21:53:24 +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 'scripts/check_dependencies.py'
--- scripts/check_dependencies.py	2013-01-07 09:18:29 +0000
+++ scripts/check_dependencies.py	2013-02-06 21:53:24 +0000
@@ -40,7 +40,13 @@
 import sys
 from distutils.version import LooseVersion
 
-is_win = sys.platform.startswith('win')
+# 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:
+    pass
+
+IS_WIN = sys.platform.startswith('win')
 
 VERS = {
     'Python': '2.6',
@@ -48,7 +54,7 @@
     '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
@@ -84,7 +90,7 @@
     ('sqlite', ' (SQLite 2 support)'),
     ('MySQLdb', ' (MySQL support)'),
     ('psycopg2', ' (PostgreSQL support)'),
-    ('pytest', ' (testing framework)'),
+    ('nose', ' (testing framework)'),
 ]
 
 w = sys.stdout.write
@@ -176,7 +182,7 @@
     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)

=== 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 21:53:24 +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,94 @@
             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):
+        """
+        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:
+            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)
+
+            # 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\'.'
+
+    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'
+            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: 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):
+        """
+        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'
+
+            # 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: 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):
+        """
+        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'
+            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: 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):
+        """
+        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
+            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: 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\'.'


Follow ups