From 1ac75c85fdea60698c975b19ad5969a0be1e3a80 Mon Sep 17 00:00:00 2001 From: "Jeffrey S. Smith" Date: Fri, 13 Sep 2013 14:23:31 -0500 Subject: [PATCH 1/2] Handle tests with platform-dependent behavior carefully --- .../openlp_core_utils/test_utils.py | 23 +---------- .../songs/test_worshipcenterproimport.py | 38 ++++++++++--------- 2 files changed, 23 insertions(+), 38 deletions(-) diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 6eacb2e48..d3f574a8a 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -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 diff --git a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py index 7c9b80056..d5c107342 100644 --- a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py +++ b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py @@ -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') \ No newline at end of file + 'Incorrect number of calls made to addVerse') From cf9ddadf35b024942a94a026c9995b1d2ebe8852 Mon Sep 17 00:00:00 2001 From: "Jeffrey S. Smith" Date: Fri, 4 Oct 2013 16:44:58 -0500 Subject: [PATCH 2/2] Missed removing one line when merging --- .../openlp_plugins/songs/test_worshipcenterproimport.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py index 102caf98e..836c5340b 100644 --- a/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py +++ b/tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py @@ -129,7 +129,6 @@ 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.