openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #23727
[Merge] lp:~googol/openlp/i18n-script into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/i18n-script into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~googol/openlp/i18n-script/+merge/222612
Hello,
- Make the i18n script work with trunk
- moved tests
lp:~googol/openlp/i18n-script (revision 2396)
[SUCCESS] http://ci.openlp.org/job/Branch-01-Pull/478/
[SUCCESS] http://ci.openlp.org/job/Branch-02-Functional-Tests/434/
[SUCCESS] http://ci.openlp.org/job/Branch-03-Interface-Tests/379/
[SUCCESS] http://ci.openlp.org/job/Branch-04-Windows_Tests/340/
[SUCCESS] http://ci.openlp.org/job/Branch-05a-Code_Analysis/234/
[SUCCESS] http://ci.openlp.org/job/Branch-05b-Test_Coverage/108/
--
https://code.launchpad.net/~googol/openlp/i18n-script/+merge/222612
Your team OpenLP Core is requested to review the proposed merge of lp:~googol/openlp/i18n-script into lp:openlp.
=== modified file 'scripts/translation_utils.py'
--- scripts/translation_utils.py 2014-05-22 11:52:53 +0000
+++ scripts/translation_utils.py 2014-06-10 09:52:16 +0000
@@ -63,7 +63,7 @@
from optparse import OptionParser
from PyQt4 import QtCore
-SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/'
+SERVER_URL = 'http://www.transifex.net/api/2/project/openlp/resource/openlp-22x/'
IGNORED_PATHS = ['scripts']
IGNORED_FILES = ['setup.py']
@@ -193,27 +193,26 @@
if not password:
password = getpass(' Transifex password: ')
# First get the list of languages
- url = SERVER_URL + 'resource/ents/'
- base64string = base64.encodebytes('%s:%s' % (username, password))[:-1]
- auth_header = 'Basic %s' % base64string
- request = urllib.request.Request(url + '?details')
+ base64string = base64.encodebytes(('%s:%s' % (username, password)).encode())[:-1]
+ auth_header = 'Basic %s' % base64string.decode()
+ request = urllib.request.Request(SERVER_URL + '?details')
request.add_header('Authorization', auth_header)
- print_verbose('Downloading list of languages from: %s' % url)
+ print_verbose('Downloading list of languages from: %s' % SERVER_URL)
try:
json_response = urllib.request.urlopen(request)
except urllib.error.HTTPError:
print_quiet('Username or password incorrect.')
return False
- json_dict = json.loads(json_response.read())
+ json_dict = json.loads(json_response.read().decode())
languages = [lang['code'] for lang in json_dict['available_languages']]
for language in languages:
- lang_url = url + 'translation/%s/?file' % language
+ lang_url = SERVER_URL + 'translation/%s/?file' % language
request = urllib.request.Request(lang_url)
request.add_header('Authorization', auth_header)
filename = os.path.join(os.path.abspath('..'), 'resources', 'i18n', language + '.ts')
print_verbose('Get Translation File: %s' % filename)
response = urllib.request.urlopen(request)
- fd = open(filename, 'w')
+ fd = open(filename, 'wb')
fd.write(response.read())
fd.close()
print_quiet(' Done.')
=== modified file 'tests/functional/openlp_core_common/test_common.py'
--- tests/functional/openlp_core_common/test_common.py 2014-05-07 23:52:51 +0000
+++ tests/functional/openlp_core_common/test_common.py 2014-06-10 09:52:16 +0000
@@ -32,7 +32,7 @@
from unittest import TestCase
-from openlp.core.common import de_hump, trace_error_handler
+from openlp.core.common import check_directory_exists, de_hump, trace_error_handler, translate
from tests.functional import MagicMock, patch
@@ -40,6 +40,45 @@
"""
A test suite to test out various functions in the openlp.core.common module.
"""
+ def check_directory_exists_test(self):
+ """
+ Test the check_directory_exists() function
+ """
+ with patch('openlp.core.lib.os.path.exists') as mocked_exists, \
+ patch('openlp.core.lib.os.makedirs') as mocked_makedirs:
+ # GIVEN: A directory to check and a mocked out os.makedirs and os.path.exists
+ directory_to_check = 'existing/directory'
+
+ # WHEN: os.path.exists returns True and we check to see if the directory exists
+ mocked_exists.return_value = True
+ check_directory_exists(directory_to_check)
+
+ # THEN: Only os.path.exists should have been called
+ mocked_exists.assert_called_with(directory_to_check)
+ self.assertIsNot(mocked_makedirs.called, 'os.makedirs should not have been called')
+
+ # WHEN: os.path.exists returns False and we check the directory exists
+ mocked_exists.return_value = False
+ check_directory_exists(directory_to_check)
+
+ # THEN: Both the mocked functions should have been called
+ mocked_exists.assert_called_with(directory_to_check)
+ mocked_makedirs.assert_called_with(directory_to_check)
+
+ # WHEN: os.path.exists raises an IOError
+ mocked_exists.side_effect = IOError()
+ check_directory_exists(directory_to_check)
+
+ # THEN: We shouldn't get an exception though the mocked exists has been called
+ mocked_exists.assert_called_with(directory_to_check)
+
+ # WHEN: Some other exception is raised
+ mocked_exists.side_effect = ValueError()
+
+ # THEN: check_directory_exists raises an exception
+ mocked_exists.assert_called_with(directory_to_check)
+ self.assertRaises(ValueError, check_directory_exists, directory_to_check)
+
def de_hump_conversion_test(self):
"""
Test the de_hump function with a class name
@@ -81,3 +120,22 @@
# THEN: The mocked_logger.error() method should have been called with the correct parameters
mocked_logger.error.assert_called_with(
'OpenLP Error trace\n File openlp.fake at line 56 \n\t called trace_error_handler_test')
+
+ def translate_test(self):
+ """
+ Test the translate() function
+ """
+ # GIVEN: A string to translate and a mocked Qt translate function
+ context = 'OpenLP.Tests'
+ text = 'Untranslated string'
+ comment = 'A comment'
+ encoding = 1
+ n = 1
+ mocked_translate = MagicMock(return_value='Translated string')
+
+ # WHEN: we call the translate function
+ result = translate(context, text, comment, encoding, n, mocked_translate)
+
+ # THEN: the translated string should be returned, and the mocked function should have been called
+ mocked_translate.assert_called_with(context, text, comment, encoding, n)
+ self.assertEqual('Translated string', result, 'The translated string should have been returned')
=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
--- tests/functional/openlp_core_lib/test_lib.py 2014-05-02 06:42:17 +0000
+++ tests/functional/openlp_core_lib/test_lib.py 2014-06-10 09:52:16 +0000
@@ -36,9 +36,8 @@
from PyQt4 import QtCore, QtGui
-from openlp.core.common import check_directory_exists, translate
-from openlp.core.lib import str_to_bool, create_thumb, get_text_file_string, \
- build_icon, image_to_byte, check_item_selected, validate_thumb, create_separated_list, clean_tags, expand_tags
+from openlp.core.lib import build_icon, check_item_selected, clean_tags, create_thumb, create_separated_list, \
+ expand_tags, get_text_file_string, image_to_byte, resize_image, str_to_bool, validate_thumb
from tests.functional import MagicMock, patch
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
@@ -152,64 +151,6 @@
# THEN: we should get back a true
self.assertTrue(str_result, 'The result should be True')
- def translate_test(self):
- """
- Test the translate() function
- """
- # GIVEN: A string to translate and a mocked Qt translate function
- context = 'OpenLP.Tests'
- text = 'Untranslated string'
- comment = 'A comment'
- encoding = 1
- n = 1
- mocked_translate = MagicMock(return_value='Translated string')
-
- # WHEN: we call the translate function
- result = translate(context, text, comment, encoding, n, mocked_translate)
-
- # THEN: the translated string should be returned, and the mocked function should have been called
- mocked_translate.assert_called_with(context, text, comment, encoding, n)
- self.assertEqual('Translated string', result, 'The translated string should have been returned')
-
- def check_directory_exists_test(self):
- """
- Test the check_directory_exists() function
- """
- with patch('openlp.core.lib.os.path.exists') as mocked_exists, \
- patch('openlp.core.lib.os.makedirs') as mocked_makedirs:
- # GIVEN: A directory to check and a mocked out os.makedirs and os.path.exists
- directory_to_check = 'existing/directory'
-
- # WHEN: os.path.exists returns True and we check to see if the directory exists
- mocked_exists.return_value = True
- check_directory_exists(directory_to_check)
-
- # THEN: Only os.path.exists should have been called
- mocked_exists.assert_called_with(directory_to_check)
- self.assertIsNot(mocked_makedirs.called, 'os.makedirs should not have been called')
-
- # WHEN: os.path.exists returns False and we check the directory exists
- mocked_exists.return_value = False
- check_directory_exists(directory_to_check)
-
- # THEN: Both the mocked functions should have been called
- mocked_exists.assert_called_with(directory_to_check)
- mocked_makedirs.assert_called_with(directory_to_check)
-
- # WHEN: os.path.exists raises an IOError
- mocked_exists.side_effect = IOError()
- check_directory_exists(directory_to_check)
-
- # THEN: We shouldn't get an exception though the mocked exists has been called
- mocked_exists.assert_called_with(directory_to_check)
-
- # WHEN: Some other exception is raised
- mocked_exists.side_effect = ValueError()
-
- # THEN: check_directory_exists raises an exception
- mocked_exists.assert_called_with(directory_to_check)
- self.assertRaises(ValueError, check_directory_exists, directory_to_check)
-
def get_text_file_string_no_file_test(self):
"""
Test the get_text_file_string() function when a file does not exist
@@ -353,7 +294,7 @@
Test that the check_item_selected() function returns True when there are selected indexes
"""
# GIVEN: A mocked out QtGui module and a list widget with selected indexes
- MockedQtGui = patch('openlp.core.lib.QtGui')
+ mocked_QtGui = patch('openlp.core.lib.QtGui')
mocked_list_widget = MagicMock()
mocked_list_widget.selectedIndexes.return_value = True
message = 'message'
@@ -508,6 +449,27 @@
mocked_os.stat.assert_any_call(thumb_path)
assert result is False, 'The result should be False'
+ def resize_thumb_test(self):
+ """
+ Test the resize_thumb() function
+ """
+ # GIVEN: A path to an image.
+ image_path = os.path.join(TEST_PATH, 'church.jpg')
+ wanted_width = 777
+ wanted_height = 72
+ # We want the background to be white.
+ wanted_background_hex = '#FFFFFF'
+ wanted_background_rgb = QtGui.QColor(wanted_background_hex).rgb()
+
+ # WHEN: Resize the image and add a background.
+ image = resize_image(image_path, wanted_width, wanted_height, wanted_background_hex)
+
+ # THEN: Check if the size is correct and the background was set.
+ result_size = image.size()
+ self.assertEqual(wanted_height, result_size.height(), 'The image should have the requested height.')
+ self.assertEqual(wanted_width, result_size.width(), 'The image should have the requested width.')
+ self.assertEqual(image.pixel(0, 0), wanted_background_rgb, 'The background should be white.')
+
def create_separated_list_qlocate_test(self):
"""
Test the create_separated_list function using the Qt provided method
References