Handle tests with platform-dependent behavior carefully

This commit is contained in:
Jeffrey S. Smith 2013-09-13 14:23:31 -05:00
parent 2511332a9e
commit 1ac75c85fd
2 changed files with 23 additions and 38 deletions

View File

@ -105,33 +105,14 @@ class TestUtils(TestCase):
# THEN: The file name should be cleaned.
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
"""
with patch('openlp.core.utils.languagemanager.LanguageManager.get_language') as mocked_get_language, \
patch('openlp.core.utils.os') as mocked_os:
with patch('openlp.core.utils.languagemanager.LanguageManager.get_language') as mocked_get_language:
# 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 = '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']
# WHEN: We sort the list and use get_locale_key() to generate the sorting keys
# THEN: We get a properly sorted list

View File

@ -5,11 +5,13 @@
This module contains tests for the WorshipCenter Pro song importer.
"""
from unittest import TestCase
from unittest import TestCase, skipIf
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):
"""
@ -23,22 +25,23 @@ class TestRecord(object):
self.Field = field
self.Value = value
class WorshipCenterProImportLogger(WorshipCenterProImport):
"""
This class logs changes in the title instance variable
"""
_title_assignment_list = []
if os.name == 'nt':
class WorshipCenterProImportLogger(WorshipCenterProImport):
"""
This class logs changes in the title instance variable
"""
_title_assignment_list = []
def __init__(self, manager):
WorshipCenterProImport.__init__(self, manager)
def __init__(self, manager):
WorshipCenterProImport.__init__(self, manager)
@property
def title(self):
return self._title_assignment_list[-1]
@property
def title(self):
return self._title_assignment_list[-1]
@title.setter
def title(self, title):
self._title_assignment_list.append(title)
@title.setter
def title(self, title):
self._title_assignment_list.append(title)
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'
'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):
"""
Test the functions in the :mod:`worshipcenterproimport` module.
@ -189,4 +193,4 @@ class TestWorshipCenterProSongImport(TestCase):
for call in verse_calls:
mocked_add_verse.assert_any_call(call)
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')