From e3afbefd27de25b73ef411e5b8ec2471d0f55116 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 16:42:33 +0200 Subject: [PATCH 1/7] use QDate instead of python datetime object --- openlp/core/lib/settings.py | 2 +- openlp/core/utils/__init__.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index 30a8b25d8..d55e386d6 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -126,7 +126,7 @@ class Settings(QtCore.QSettings): 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': QtCore.QDate.currentDate().addDays(-1), u'general/loop delay': 5, u'general/recent files': [], u'general/save prompt': False, diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index d32729699..efe623405 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -29,7 +29,6 @@ """ The :mod:`openlp.core.utils` module provides the utility libraries for OpenLP. """ -from datetime import datetime from distutils.version import LooseVersion import logging import locale @@ -184,7 +183,7 @@ def check_latest_version(current_version): settings = Settings() settings.beginGroup(u'general') last_test = settings.value(u'last version test') - this_test = datetime.now().date() + this_test = QtCore.QDate.currentDate() settings.setValue(u'last version test', this_test) settings.endGroup() # Tell the main window whether there will ever be data to display From 5e3563ceda08f60380b68019d566bbe883ddc2e7 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 17:08:46 +0200 Subject: [PATCH 2/7] added two tests --- openlp/core/utils/__init__.py | 3 +- .../openlp_core_utils/test_utils.py | 49 ++++++++++++++++++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index efe623405..81716a9c9 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -243,8 +243,7 @@ def get_images_filter(): 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) diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 2e826bc61..71922beec 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -5,7 +5,7 @@ from unittest import TestCase 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 @@ class TestUtils(TestCase): # 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 be valid.' From 0d621f86991f42df0474d4e39fdf5708a8bcb803 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 17:14:27 +0200 Subject: [PATCH 3/7] changed assertion message --- tests/functional/openlp_core_utils/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 71922beec..fd1aaa84e 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -102,4 +102,4 @@ class TestUtils(TestCase): result = clean_filename(invalid_name) # THEN: The file name should be cleaned. - assert result == wanted_name, u'The file name should be valid.' + assert result == wanted_name, u'The file name should not contain any special characters.' From 7f111b31a7058f13afe9ddaba826397fbab4072d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 17:24:27 +0200 Subject: [PATCH 4/7] use unicode instead of QDateTime --- openlp/core/lib/settings.py | 3 +-- openlp/core/utils/__init__.py | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index d55e386d6..50b1318b6 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -125,8 +125,7 @@ class Settings(QtCore.QSettings): 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': QtCore.QDate.currentDate().addDays(-1), + u'general/last version test': u'', u'general/loop delay': 5, u'general/recent files': [], u'general/save prompt': False, diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 81716a9c9..ba3e06e58 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -29,6 +29,7 @@ """ The :mod:`openlp.core.utils` module provides the utility libraries for OpenLP. """ +from datetime import datetime from distutils.version import LooseVersion import logging import locale @@ -183,7 +184,7 @@ def check_latest_version(current_version): settings = Settings() settings.beginGroup(u'general') last_test = settings.value(u'last version test') - this_test = QtCore.QDate.currentDate() + 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 From ffb2350f62f4c9ce33973b202101ab75588b3b4f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 19:42:01 +0200 Subject: [PATCH 5/7] fix *cough* --- openlp/core/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index ba3e06e58..9cd8f8c81 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -244,7 +244,7 @@ def get_images_filter(): global IMAGES_FILTER if not IMAGES_FILTER: log.debug(u'Generating images filter.') - formats == 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) From 03eaa91a08776671ea4358524ade159fd761c79f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 2 Apr 2013 23:03:07 +0200 Subject: [PATCH 6/7] fixed assertion message and method doc string --- tests/functional/openlp_core_utils/test_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index fd1aaa84e..6d95c6583 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -70,11 +70,11 @@ class TestUtils(TestCase): 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.' + 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. + Test the split_filename() function with a path to a directory """ # GIVEN: A path to a dir. file_path = u'/home/user/mydir' @@ -87,7 +87,7 @@ class TestUtils(TestCase): # 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.' + u'A two-entry tuple with the directory and file name (empty) should have been returned.' def clean_filename_test(self): From db00c5049a012912e47fd1457009fcd1403311f3 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 15 Apr 2013 17:50:59 +0200 Subject: [PATCH 7/7] fixed missing unicode --- openlp/core/utils/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9a03c2b0e..d4ee8039c 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -247,7 +247,7 @@ def get_images_filter(): global IMAGES_FILTER if not IMAGES_FILTER: log.debug(u'Generating images filter.') - formats = 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) @@ -405,7 +405,7 @@ def get_natural_key(string): 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