forked from openlp/openlp
Handle tests with platform-dependent behavior carefully
This commit is contained in:
parent
2511332a9e
commit
1ac75c85fd
@ -105,33 +105,14 @@ class TestUtils(TestCase):
|
|||||||
# THEN: The file name should be cleaned.
|
# THEN: The file name should be cleaned.
|
||||||
assert result == wanted_name, 'The file name should not contain any special characters.'
|
assert result == wanted_name, 'The file name should not contain any special characters.'
|
||||||
|
|
||||||
def get_locale_key_windows_test(self):
|
def get_locale_key_test(self):
|
||||||
"""
|
"""
|
||||||
Test the get_locale_key(string) function
|
Test the get_locale_key(string) function
|
||||||
"""
|
"""
|
||||||
with patch('openlp.core.utils.languagemanager.LanguageManager.get_language') as mocked_get_language, \
|
with patch('openlp.core.utils.languagemanager.LanguageManager.get_language') as mocked_get_language:
|
||||||
patch('openlp.core.utils.os') as mocked_os:
|
|
||||||
# GIVEN: The language is German
|
# GIVEN: The language is German
|
||||||
# 0x00C3 (A with diaresis) should be sorted as "A". 0x00DF (sharp s) should be sorted as "ss".
|
# 0x00C3 (A with diaresis) should be sorted as "A". 0x00DF (sharp s) should be sorted as "ss".
|
||||||
mocked_get_language.return_value = 'de'
|
mocked_get_language.return_value = 'de'
|
||||||
mocked_os.name = 'nt'
|
|
||||||
unsorted_list = ['Auszug', 'Aushang', '\u00C4u\u00DFerung']
|
|
||||||
# WHEN: We sort the list and use get_locale_key() to generate the sorting keys
|
|
||||||
# THEN: We get a properly sorted list
|
|
||||||
test_passes = sorted(unsorted_list, key=get_locale_key) == ['Aushang', '\u00C4u\u00DFerung', 'Auszug']
|
|
||||||
assert test_passes, 'Strings should be sorted properly'
|
|
||||||
|
|
||||||
def get_locale_key_linux_test(self):
|
|
||||||
|
|
||||||
"""
|
|
||||||
Test the get_locale_key(string) function
|
|
||||||
"""
|
|
||||||
with patch('openlp.core.utils.languagemanager.LanguageManager.get_language') as mocked_get_language, \
|
|
||||||
patch('openlp.core.utils.os.name') as mocked_os:
|
|
||||||
# GIVEN: The language is German
|
|
||||||
# 0x00C3 (A with diaresis) should be sorted as "A". 0x00DF (sharp s) should be sorted as "ss".
|
|
||||||
mocked_get_language.return_value = 'de'
|
|
||||||
mocked_os.name = 'linux'
|
|
||||||
unsorted_list = ['Auszug', 'Aushang', '\u00C4u\u00DFerung']
|
unsorted_list = ['Auszug', 'Aushang', '\u00C4u\u00DFerung']
|
||||||
# WHEN: We sort the list and use get_locale_key() to generate the sorting keys
|
# WHEN: We sort the list and use get_locale_key() to generate the sorting keys
|
||||||
# THEN: We get a properly sorted list
|
# THEN: We get a properly sorted list
|
||||||
|
@ -5,11 +5,13 @@
|
|||||||
This module contains tests for the WorshipCenter Pro song importer.
|
This module contains tests for the WorshipCenter Pro song importer.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase, skipIf
|
||||||
from mock import patch, MagicMock
|
from mock import patch, MagicMock
|
||||||
import pyodbc
|
|
||||||
|
|
||||||
from openlp.plugins.songs.lib.worshipcenterproimport import WorshipCenterProImport
|
import os
|
||||||
|
if os.name == 'nt':
|
||||||
|
import pyodbc
|
||||||
|
from openlp.plugins.songs.lib.worshipcenterproimport import WorshipCenterProImport
|
||||||
|
|
||||||
class TestRecord(object):
|
class TestRecord(object):
|
||||||
"""
|
"""
|
||||||
@ -23,22 +25,23 @@ class TestRecord(object):
|
|||||||
self.Field = field
|
self.Field = field
|
||||||
self.Value = value
|
self.Value = value
|
||||||
|
|
||||||
class WorshipCenterProImportLogger(WorshipCenterProImport):
|
if os.name == 'nt':
|
||||||
"""
|
class WorshipCenterProImportLogger(WorshipCenterProImport):
|
||||||
This class logs changes in the title instance variable
|
"""
|
||||||
"""
|
This class logs changes in the title instance variable
|
||||||
_title_assignment_list = []
|
"""
|
||||||
|
_title_assignment_list = []
|
||||||
|
|
||||||
def __init__(self, manager):
|
def __init__(self, manager):
|
||||||
WorshipCenterProImport.__init__(self, manager)
|
WorshipCenterProImport.__init__(self, manager)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def title(self):
|
def title(self):
|
||||||
return self._title_assignment_list[-1]
|
return self._title_assignment_list[-1]
|
||||||
|
|
||||||
@title.setter
|
@title.setter
|
||||||
def title(self, title):
|
def title(self, title):
|
||||||
self._title_assignment_list.append(title)
|
self._title_assignment_list.append(title)
|
||||||
|
|
||||||
|
|
||||||
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
RECORDSET_TEST_DATA = [TestRecord(1, 'TITLE', 'Amazing Grace'),
|
||||||
@ -98,6 +101,7 @@ SONG_TEST_DATA = [{'title': 'Amazing Grace',
|
|||||||
('There\'s a garden where\nJesus is waiting,\nAnd He bids you to come,\nmeet Him there;\n'
|
('There\'s a garden where\nJesus is waiting,\nAnd He bids you to come,\nmeet Him there;\n'
|
||||||
'Just to bow and\nreceive a new blessing\nIn the beautiful\ngarden of prayer.')]}]
|
'Just to bow and\nreceive a new blessing\nIn the beautiful\ngarden of prayer.')]}]
|
||||||
|
|
||||||
|
@skipIf(os.name != 'nt', 'WorshipCenter Pro import only supported on Windows')
|
||||||
class TestWorshipCenterProSongImport(TestCase):
|
class TestWorshipCenterProSongImport(TestCase):
|
||||||
"""
|
"""
|
||||||
Test the functions in the :mod:`worshipcenterproimport` module.
|
Test the functions in the :mod:`worshipcenterproimport` module.
|
||||||
@ -189,4 +193,4 @@ class TestWorshipCenterProSongImport(TestCase):
|
|||||||
for call in verse_calls:
|
for call in verse_calls:
|
||||||
mocked_add_verse.assert_any_call(call)
|
mocked_add_verse.assert_any_call(call)
|
||||||
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
self.assertEqual(mocked_add_verse.call_count, add_verse_call_count,
|
||||||
'Incorrect number of calls made to addVerse')
|
'Incorrect number of calls made to addVerse')
|
||||||
|
Loading…
Reference in New Issue
Block a user