forked from openlp/openlp
- fixed Bug #1100277 (Songs don't load with latest build)
- added nose to check_dependencies.py - fixed version number compare in create_separated_list bzr-revno: 2178
This commit is contained in:
commit
7c9506af4a
@ -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 @@ 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''
|
||||
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',
|
||||
merged = translate('OpenLP.core.lib', '%s, %s',
|
||||
u'Locale list separator: middle') % (stringlist[index], merged)
|
||||
return translate('OpenLP.core.lib', '%1, %2',
|
||||
u'Locale list separator: start') % (stringlist[0], merged)
|
||||
return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged)
|
||||
|
||||
|
||||
from registry import Registry
|
||||
|
@ -40,7 +40,13 @@ import os
|
||||
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 @@ 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
|
||||
@ -84,7 +90,7 @@ OPTIONAL_MODULES = [
|
||||
('sqlite', ' (SQLite 2 support)'),
|
||||
('MySQLdb', ' (MySQL support)'),
|
||||
('psycopg2', ' (PostgreSQL support)'),
|
||||
('pytest', ' (testing framework)'),
|
||||
('nose', ' (testing framework)'),
|
||||
]
|
||||
|
||||
w = sys.stdout.write
|
||||
@ -176,7 +182,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)
|
||||
|
@ -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):
|
||||
|
||||
@ -359,3 +359,90 @@ 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):
|
||||
"""
|
||||
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:
|
||||
# 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'
|
||||
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:
|
||||
# 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'
|
||||
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:
|
||||
# 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'
|
||||
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:
|
||||
# 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'
|
||||
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:
|
||||
# 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'
|
||||
# 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.
|
||||
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\'.'
|
||||
|
Loading…
Reference in New Issue
Block a user