forked from openlp/openlp
- Use unicode instead of QDateTime for 'last version test' setting
- Added three tests bzr-revno: 2235
This commit is contained in:
commit
bbb3b32e88
@ -125,8 +125,7 @@ class Settings(QtCore.QSettings):
|
||||
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,
|
||||
|
@ -187,7 +187,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 = 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 @@ 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 = 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 @@ 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
|
||||
|
||||
|
||||
|
@ -5,7 +5,9 @@ from unittest import TestCase
|
||||
|
||||
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 @@ 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 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 @@ class TestUtils(TestCase):
|
||||
# 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'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user