openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #20550
[Merge] lp:~googol/openlp/last-version-fix into lp:openlp
Andreas Preikschat has proposed merging lp:~googol/openlp/last-version-fix into lp:openlp.
Requested reviews:
Tim Bentley (trb143)
Andreas Preikschat (googol)
For more details, see:
https://code.launchpad.net/~googol/openlp/last-version-fix/+merge/159954
Hello,
- Use unicode instead of QDateTime for "last version test" setting
- Added three tests
Python datetime objects are not converted by PyQt to Qt QDateTime objects. This script shows the error: http://pastebin.com/qbpKFknx (Just run the script twice.)
--
https://code.launchpad.net/~googol/openlp/last-version-fix/+merge/159954
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/settings.py'
--- openlp/core/lib/settings.py 2013-03-30 09:53:01 +0000
+++ openlp/core/lib/settings.py 2013-04-20 20:26:32 +0000
@@ -125,8 +125,7 @@
u'core/ccli number': u'',
u'core/has run wizard': False,
u'core/language': u'[en]',
- # This defaults to yesterday in order to force the update check to run when you've never run it before.
- u'core/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1),
+ u'core/last version test': u'',
u'core/loop delay': 5,
u'core/recent files': [],
u'core/save prompt': False,
=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py 2013-04-16 16:37:26 +0000
+++ openlp/core/utils/__init__.py 2013-04-20 20:26:32 +0000
@@ -187,7 +187,7 @@
settings = Settings()
settings.beginGroup(u'general')
last_test = settings.value(u'last version test')
- this_test = datetime.now().date()
+ this_test = unicode(datetime.now().date())
settings.setValue(u'last version test', this_test)
settings.endGroup()
# Tell the main window whether there will ever be data to display
@@ -247,8 +247,7 @@
global IMAGES_FILTER
if not IMAGES_FILTER:
log.debug(u'Generating images filter.')
- formats = [unicode(fmt)
- for fmt in QtGui.QImageReader.supportedImageFormats()]
+ formats = map(unicode, QtGui.QImageReader.supportedImageFormats())
visible_formats = u'(*.%s)' % u'; *.'.join(formats)
actual_formats = u'(*.%s)' % u' *.'.join(formats)
IMAGES_FILTER = u'%s %s %s' % (translate('OpenLP', 'Image Files'), visible_formats, actual_formats)
@@ -406,7 +405,7 @@
key = [int(part) if part.isdigit() else get_locale_key(part) for part in key]
# Python 3 does not support comparision of different types anymore. So make sure, that we do not compare str and int.
#if string[0].isdigit():
- # return [''] + key
+ # return [''] + key
return key
=== modified file 'tests/functional/openlp_core_utils/test_utils.py'
--- tests/functional/openlp_core_utils/test_utils.py 2013-04-06 18:21:23 +0000
+++ tests/functional/openlp_core_utils/test_utils.py 2013-04-20 20:26:32 +0000
@@ -5,7 +5,9 @@
from mock import patch
-from openlp.core.utils import get_filesystem_encoding, _get_frozen_path, get_locale_key, get_natural_key
+from openlp.core.utils import clean_filename, get_filesystem_encoding, _get_frozen_path, get_locale_key, \
+ get_natural_key, split_filename
+
class TestUtils(TestCase):
"""
@@ -56,6 +58,53 @@
# THEN: The frozen parameter is returned
assert _get_frozen_path(u'frozen', u'not frozen') == u'frozen', u'Should return "frozen"'
+ def split_filename_with_file_path_test(self):
+ """
+ Test the split_filename() function with a path to a file
+ """
+ # GIVEN: A path to a file.
+ file_path = u'/home/user/myfile.txt'
+ wanted_result = (u'/home/user', u'myfile.txt')
+ with patch(u'openlp.core.utils.os.path.isfile') as mocked_is_file:
+ mocked_is_file.return_value = True
+
+ # WHEN: Split the file name.
+ result = split_filename(file_path)
+
+ # THEN: A tuple should be returned.
+ assert result == wanted_result, u'A tuple with the directory and file name should have been returned.'
+
+ def split_filename_with_dir_path_test(self):
+ """
+ Test the split_filename() function with a path to a directory
+ """
+ # GIVEN: A path to a dir.
+ file_path = u'/home/user/mydir'
+ wanted_result = (u'/home/user/mydir', u'')
+ with patch(u'openlp.core.utils.os.path.isfile') as mocked_is_file:
+ mocked_is_file.return_value = False
+
+ # WHEN: Split the file name.
+ result = split_filename(file_path)
+
+ # THEN: A tuple should be returned.
+ assert result == wanted_result, \
+ u'A two-entry tuple with the directory and file name (empty) should have been returned.'
+
+ def clean_filename_test(self):
+ """
+ Test the clean_filename() function
+ """
+ # GIVEN: A invalid file name and the valid file name.
+ invalid_name = u'A_file_with_invalid_characters_[\\/:\*\?"<>\|\+\[\]%].py'
+ wanted_name = u'A_file_with_invalid_characters______________________.py'
+
+ # WHEN: Clean the name.
+ result = clean_filename(invalid_name)
+
+ # THEN: The file name should be cleaned.
+ assert result == wanted_name, u'The file name should not contain any special characters.'
+
def get_locale_key_test(self):
"""
Test the get_locale_key(string) function
@@ -82,4 +131,3 @@
# THEN: We get a properly sorted list
test_passes = sorted(unsorted_list, key=get_natural_key) == [u'1st item', u'item 3b', u'item 10a']
assert test_passes, u'Numbers should be sorted naturally'
-
Follow ups