openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #20285
[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:
Andreas Preikschat (googol)
For more details, see:
https://code.launchpad.net/~googol/openlp/last-version-fix/+merge/156650
Hello,
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.)
- Use unicode instead of QDateTime for "last version test" setting
- Added three tests
--
https://code.launchpad.net/~googol/openlp/last-version-fix/+merge/156650
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/settings.py'
--- openlp/core/lib/settings.py 2013-03-28 20:15:59 +0000
+++ openlp/core/lib/settings.py 2013-04-02 17:44:26 +0000
@@ -125,8 +125,7 @@
u'general/ccli number': u'',
u'general/has run wizard': False,
u'general/language': u'[en]',
- # This defaults to yesterday in order to force the update check to run when you've never run it before.
- u'general/last version test': datetime.datetime.now().date() - datetime.timedelta(days=1),
+ u'general/last version test': u'',
u'general/loop delay': 5,
u'general/recent files': [],
u'general/save prompt': False,
=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py 2013-03-04 10:55:02 +0000
+++ openlp/core/utils/__init__.py 2013-04-02 17:44:26 +0000
@@ -184,7 +184,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
@@ -244,8 +244,7 @@
global IMAGES_FILTER
if not IMAGES_FILTER:
log.debug(u'Generating images filter.')
- formats = [unicode(fmt)
- for fmt in QtGui.QImageReader.supportedImageFormats()]
+ formats = 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)
=== modified file 'tests/functional/openlp_core_utils/test_utils.py'
--- tests/functional/openlp_core_utils/test_utils.py 2012-12-07 21:38:02 +0000
+++ tests/functional/openlp_core_utils/test_utils.py 2013-04-02 17:44:26 +0000
@@ -5,7 +5,7 @@
from mock import patch
-from openlp.core.utils import get_filesystem_encoding, _get_frozen_path
+from openlp.core.utils import get_filesystem_encoding, _get_frozen_path, clean_filename, split_filename
class TestUtils(TestCase):
"""
@@ -56,3 +56,50 @@
# 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 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 (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.'