openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #21942
[Merge] lp:~raoul-snyman/openlp/update-mock into lp:openlp
Raoul Snyman has proposed merging lp:~raoul-snyman/openlp/update-mock into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
For more details, see:
https://code.launchpad.net/~raoul-snyman/openlp/update-mock/+merge/188239
This doesn't fix up, or fix, ALL of the tests. It just makes sure that we can always import Mock.
--
https://code.launchpad.net/~raoul-snyman/openlp/update-mock/+merge/188239
Your team OpenLP Core is requested to review the proposed merge of lp:~raoul-snyman/openlp/update-mock into lp:openlp.
=== modified file 'tests/functional/__init__.py'
--- tests/functional/__init__.py 2013-08-31 18:17:38 +0000
+++ tests/functional/__init__.py 2013-09-29 21:32:52 +0000
@@ -7,7 +7,13 @@
sip.setapi('QUrl', 2)
sip.setapi('QVariant', 2)
+import sys
from PyQt4 import QtGui
+if sys.version_info[1] >= 3:
+ from unittest.mock import patch, MagicMock
+else:
+ from mock import patch, MagicMock
+
# Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" a QApplication.
application = QtGui.QApplication([])
=== modified file 'tests/functional/openlp_core_lib/test_db.py'
--- tests/functional/openlp_core_lib/test_db.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_db.py 2013-09-29 21:32:52 +0000
@@ -1,14 +1,42 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib package.
"""
from unittest import TestCase
-from mock import MagicMock, patch
from sqlalchemy.pool import NullPool
from sqlalchemy.orm.scoping import ScopedSession
from sqlalchemy import MetaData
from openlp.core.lib.db import init_db, get_upgrade_op
+from tests.functional import patch, MagicMock
class TestDB(TestCase):
=== modified file 'tests/functional/openlp_core_lib/test_formattingtags.py'
--- tests/functional/openlp_core_lib/test_formattingtags.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_formattingtags.py 2013-09-29 21:32:52 +0000
@@ -1,12 +1,39 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib.formattingtags package.
"""
import copy
from unittest import TestCase
-from mock import patch
-
from openlp.core.lib import FormattingTags
+from tests.functional import patch
TAG = {
=== modified file 'tests/functional/openlp_core_lib/test_image_manager.py'
--- tests/functional/openlp_core_lib/test_image_manager.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_image_manager.py 2013-09-29 21:32:52 +0000
@@ -1,15 +1,41 @@
-"""
- Package to test the openlp.core.ui package.
-"""
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
+"""
+Package to test the openlp.core.ui package.
+"""
import os
from unittest import TestCase
-from PyQt4 import QtCore, QtGui
+from PyQt4 import QtGui
from openlp.core.lib import Registry, ImageManager, ScreenList
-
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
=== modified file 'tests/functional/openlp_core_lib/test_lib.py'
--- tests/functional/openlp_core_lib/test_lib.py 2013-09-09 21:10:40 +0000
+++ tests/functional/openlp_core_lib/test_lib.py 2013-09-29 21:32:52 +0000
@@ -1,3 +1,31 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib package.
"""
@@ -6,22 +34,20 @@
from unittest import TestCase
from datetime import datetime, timedelta
-from mock import MagicMock, patch
from PyQt4 import QtCore, QtGui
from openlp.core.lib import str_to_bool, create_thumb, translate, check_directory_exists, get_text_file_string, \
build_icon, image_to_byte, check_item_selected, validate_thumb, create_separated_list, clean_tags, expand_tags
-
+from tests.functional import MagicMock, patch
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
-
class TestLib(TestCase):
- def str_to_bool_with_bool_test(self):
+ def str_to_bool_with_bool_true_test(self):
"""
- Test the str_to_bool function with boolean input
+ Test the str_to_bool function with boolean input of True
"""
# GIVEN: A boolean value set to true
true_boolean = True
@@ -30,9 +56,13 @@
true_result = str_to_bool(true_boolean)
# THEN: We should get back a True bool
- assert isinstance(true_result, bool), 'The result should be a boolean'
- assert true_result is True, 'The result should be True'
+ self.assertIsInstance(true_result, bool, 'The result should be a boolean')
+ self.assertTrue(true_result, 'The result should be True')
+ def str_to_bool_with_bool_false_test(self):
+ """
+ Test the str_to_bool function with boolean input of False
+ """
# GIVEN: A boolean value set to false
false_boolean = False
@@ -40,12 +70,12 @@
false_result = str_to_bool(false_boolean)
# THEN: We should get back a True bool
- assert isinstance(false_result, bool), 'The result should be a boolean'
- assert false_result is False, 'The result should be True'
+ self.assertIsInstance(false_result, bool, 'The result should be a boolean')
+ self.assertFalse(false_result, 'The result should be True')
- def str_to_bool_with_invalid_test(self):
+ def str_to_bool_with_integer_test(self):
"""
- Test the str_to_bool function with a set of invalid inputs
+ Test the str_to_bool function with an integer input
"""
# GIVEN: An integer value
int_string = 1
@@ -54,8 +84,12 @@
int_result = str_to_bool(int_string)
# THEN: we should get back a false
- assert int_result is False, 'The result should be False'
+ self.assertFalse(int_result, 'The result should be False')
+ def str_to_bool_with_invalid_string_test(self):
+ """
+ Test the str_to_bool function with an invalid string
+ """
# GIVEN: An string value with completely invalid input
invalid_string = 'my feet are wet'
@@ -63,11 +97,11 @@
str_result = str_to_bool(invalid_string)
# THEN: we should get back a false
- assert str_result is False, 'The result should be False'
+ self.assertFalse(str_result, 'The result should be False')
- def str_to_bool_with_false_values_test(self):
+ def str_to_bool_with_string_false_test(self):
"""
- Test the str_to_bool function with a set of false inputs
+ Test the str_to_bool function with a string saying "false"
"""
# GIVEN: A string set to "false"
false_string = 'false'
@@ -76,8 +110,12 @@
false_result = str_to_bool(false_string)
# THEN: we should get back a false
- assert false_result is False, 'The result should be False'
+ self.assertFalse(false_result, 'The result should be False')
+ def str_to_bool_with_string_no_test(self):
+ """
+ Test the str_to_bool function with a string saying "NO"
+ """
# GIVEN: An string set to "NO"
no_string = 'NO'
@@ -85,11 +123,11 @@
str_result = str_to_bool(no_string)
# THEN: we should get back a false
- assert str_result is False, 'The result should be False'
+ self.assertFalse(str_result, 'The result should be False')
- def str_to_bool_with_true_values_test(self):
+ def str_to_bool_with_true_string_value_test(self):
"""
- Test the str_to_bool function with a set of true inputs
+ Test the str_to_bool function with a string set to "True"
"""
# GIVEN: A string set to "True"
true_string = 'True'
@@ -98,8 +136,12 @@
true_result = str_to_bool(true_string)
# THEN: we should get back a true
- assert true_result is True, 'The result should be True'
+ self.assertTrue(true_result, 'The result should be True')
+ def str_to_bool_with_yes_string_value_test(self):
+ """
+ Test the str_to_bool function with a string set to "yes"
+ """
# GIVEN: An string set to "yes"
yes_string = 'yes'
@@ -107,7 +149,7 @@
str_result = str_to_bool(yes_string)
# THEN: we should get back a true
- assert str_result is True, 'The result should be True'
+ self.assertTrue(str_result, 'The result should be True')
def translate_test(self):
"""
@@ -126,7 +168,7 @@
# THEN: the translated string should be returned, and the mocked function should have been called
mocked_translate.assert_called_with(context, text, comment, encoding, n)
- assert result == 'Translated string', 'The translated string should have been returned'
+ self.assertEqual('Translated string', result, 'The translated string should have been returned')
def check_directory_exists_test(self):
"""
@@ -143,7 +185,7 @@
# THEN: Only os.path.exists should have been called
mocked_exists.assert_called_with(directory_to_check)
- assert not mocked_makedirs.called, 'os.makedirs should not have been called'
+ self.assertIsNot(mocked_makedirs.called, 'os.makedirs should not have been called')
# WHEN: os.path.exists returns False and we check the directory exists
mocked_exists.return_value = False
@@ -181,13 +223,14 @@
# THEN: The result should be False
mocked_isfile.assert_called_with(filename)
- assert result is False, 'False should be returned if no file exists'
+ self.assertFalse(result, 'False should be returned if no file exists')
def get_text_file_string_read_error_test(self):
"""
Test the get_text_file_string() method when a read error happens
"""
- with patch('openlp.core.lib.os.path.isfile') as mocked_isfile, patch('openlp.core.lib.open', create=True) as mocked_open:
+ with patch('openlp.core.lib.os.path.isfile') as mocked_isfile, \
+ patch('openlp.core.lib.open', create=True) as mocked_open:
# GIVEN: A mocked-out open() which raises an exception and isfile returns True
filename = 'testfile.txt'
mocked_isfile.return_value = True
@@ -199,13 +242,13 @@
# THEN: None should be returned
mocked_isfile.assert_called_with(filename)
mocked_open.assert_called_with(filename, 'r')
- assert result is None, 'None should be returned if the file cannot be opened'
+ self.assertIsNone(result, 'None should be returned if the file cannot be opened')
def get_text_file_string_decode_error_test(self):
"""
Test the get_text_file_string() method when the contents cannot be decoded
"""
- assert True, 'Impossible to test due to conflicts when mocking out the "open" function'
+ self.skipTest('Impossible to test due to conflicts when mocking out the "open" function')
def build_icon_with_qicon_test(self):
"""
@@ -220,7 +263,7 @@
result = build_icon(mocked_icon)
# THEN: The result should be our mocked QIcon
- assert result is mocked_icon, 'The result should be the mocked QIcon'
+ self.assertIs(mocked_icon, result, 'The result should be the mocked QIcon')
def build_icon_with_resource_test(self):
"""
@@ -242,7 +285,7 @@
MockedQPixmap.assert_called_with(resource_uri)
# There really should be more assert statements here but due to type checking and things they all break. The
# best we can do is to assert that we get back a MagicMock object.
- assert isinstance(result, MagicMock), 'The result should be a MagicMock, because we mocked it out'
+ self.assertIsInstance(result, MagicMock, 'The result should be a MagicMock, because we mocked it out')
def image_to_byte_test(self):
"""
@@ -267,7 +310,8 @@
mocked_buffer.open.assert_called_with('writeonly')
mocked_image.save.assert_called_with(mocked_buffer, "PNG")
mocked_byte_array.toBase64.assert_called_with()
- assert result == 'base64mock', 'The result should be the return value of the mocked out base64 method'
+ self.assertEqual('base64mock', result,
+ 'The result should be the return value of the mocked out base64 method')
def create_thumb_with_size_test(self):
"""
@@ -286,16 +330,16 @@
pass
# Only continue when the thumb does not exist.
- assert not os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists.'
+ self.assertFalse(os.path.exists(thumb_path), 'Test was not run, because the thumb already exists.')
# WHEN: Create the thumb.
icon = create_thumb(image_path, thumb_path, size=thumb_size)
# THEN: Check if the thumb was created.
- assert os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists.'
- assert isinstance(icon, QtGui.QIcon), 'The icon should be a QIcon.'
- assert not icon.isNull(), 'The icon should not be null.'
- assert QtGui.QImageReader(thumb_path).size() == thumb_size, 'The thumb should have the given size.'
+ self.assertTrue(os.path.exists(thumb_path), 'Test was not ran, because the thumb already exists')
+ self.assertIsInstance(icon, QtGui.QIcon, 'The icon should be a QIcon')
+ self.assertFalse(icon.isNull(), 'The icon should not be null')
+ self.assertEqual(thumb_size, QtGui.QImageReader(thumb_path).size(), 'The thumb should have the given size')
# Remove the thumb so that the test actually tests if the thumb will be created.
try:
@@ -318,7 +362,7 @@
# THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with()
- assert result, 'The result should be True'
+ self.assertTrue(result, 'The result should be True')
def check_item_selected_false_test(self):
"""
@@ -326,7 +370,7 @@
"""
# GIVEN: A mocked out QtGui module and a list widget with selected indexes
with patch('openlp.core.lib.QtGui') as MockedQtGui, \
- patch('openlp.core.lib.translate') as mocked_translate:
+ patch('openlp.core.lib.translate') as mocked_translate:
mocked_translate.return_value = 'mocked translate'
mocked_list_widget = MagicMock()
mocked_list_widget.selectedIndexes.return_value = False
@@ -339,7 +383,7 @@
# THEN: The selectedIndexes function should have been called and the result should be true
mocked_list_widget.selectedIndexes.assert_called_with()
MockedQtGui.QMessageBox.information.assert_called_with('parent', 'mocked translate', 'message')
- assert not result, 'The result should be False'
+ self.assertFalse(result, 'The result should be False')
def clean_tags_test(self):
"""
@@ -361,7 +405,7 @@
result_string = clean_tags(string_to_pass)
# THEN: The strings should be identical.
- assert result_string == wanted_string, 'The strings should be identical.'
+ self.assertEqual(wanted_string, result_string, 'The strings should be identical')
def expand_tags_test(self):
"""
@@ -400,7 +444,7 @@
result_string = expand_tags(string_to_pass)
# THEN: The strings should be identical.
- assert result_string == wanted_string, 'The strings should be identical.'
+ self.assertEqual(wanted_string, result_string, 'The strings should be identical.')
def validate_thumb_file_does_not_exist_test(self):
"""
=== modified file 'tests/functional/openlp_core_lib/test_pluginmanager.py'
--- tests/functional/openlp_core_lib/test_pluginmanager.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_pluginmanager.py 2013-09-29 21:32:52 +0000
@@ -1,12 +1,39 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib.pluginmanager package.
"""
from unittest import TestCase
-from mock import MagicMock
-
from openlp.core.lib.pluginmanager import PluginManager
from openlp.core.lib import Settings, Registry, PluginStatus
+from tests.functional import MagicMock
class TestPluginManager(TestCase):
@@ -42,8 +69,8 @@
plugin_manager.hook_media_manager()
# THEN: The create_media_manager_item() method should have been called
- assert mocked_plugin.create_media_manager_item.call_count == 0, \
- 'The create_media_manager_item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
+ 'The create_media_manager_item() method should not have been called.')
def hook_media_manager_with_active_plugin_test(self):
"""
@@ -75,8 +102,8 @@
plugin_manager.hook_settings_tabs()
# THEN: The hook_settings_tabs() method should have been called
- assert mocked_plugin.create_media_manager_item.call_count == 0, \
- 'The create_media_manager_item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.create_media_manager_item.call_count,
+ 'The create_media_manager_item() method should not have been called.')
def hook_settings_tabs_with_disabled_plugin_and_mocked_form_test(self):
"""
@@ -95,10 +122,10 @@
plugin_manager.hook_settings_tabs()
# THEN: The create_settings_tab() method should not have been called, but the plugins lists should be the same
- assert mocked_plugin.create_settings_tab.call_count == 0, \
- 'The create_media_manager_item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.create_settings_tab.call_count,
+ 'The create_media_manager_item() method should not have been called.')
self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
- 'The plugins on the settings form should be the same as the plugins in the plugin manager')
+ 'The plugins on the settings form should be the same as the plugins in the plugin manager')
def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self):
"""
@@ -117,10 +144,10 @@
plugin_manager.hook_settings_tabs()
# THEN: The create_media_manager_item() method should have been called with the mocked settings form
- assert mocked_plugin.create_settings_tab.call_count == 1, \
- 'The create_media_manager_item() method should have been called once.'
- self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins,
- 'The plugins on the settings form should be the same as the plugins in the plugin manager')
+ self.assertEqual(1, mocked_plugin.create_settings_tab.call_count,
+ 'The create_media_manager_item() method should have been called once.')
+ self.assertEqual(plugin_manager.plugins, mocked_settings_form.plugin_manager.plugins,
+ 'The plugins on the settings form should be the same as the plugins in the plugin manager')
def hook_settings_tabs_with_active_plugin_and_no_form_test(self):
"""
@@ -152,8 +179,8 @@
plugin_manager.hook_import_menu()
# THEN: The create_media_manager_item() method should have been called
- assert mocked_plugin.add_import_menu_item.call_count == 0, \
- 'The add_import_menu_item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.add_import_menu_item.call_count,
+ 'The add_import_menu_item() method should not have been called.')
def hook_import_menu_with_active_plugin_test(self):
"""
@@ -185,8 +212,8 @@
plugin_manager.hook_export_menu()
# THEN: The add_export_menu_Item() method should not have been called
- assert mocked_plugin.add_export_menu_Item.call_count == 0, \
- 'The add_export_menu_Item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.add_export_menu_Item.call_count,
+ 'The add_export_menu_Item() method should not have been called.')
def hook_export_menu_with_active_plugin_test(self):
"""
@@ -219,8 +246,8 @@
plugin_manager.hook_upgrade_plugin_settings(settings)
# THEN: The upgrade_settings() method should not have been called
- assert mocked_plugin.upgrade_settings.call_count == 0, \
- 'The upgrade_settings() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.upgrade_settings.call_count,
+ 'The upgrade_settings() method should not have been called.')
def hook_upgrade_plugin_settings_with_active_plugin_test(self):
"""
@@ -253,8 +280,8 @@
plugin_manager.hook_tools_menu()
# THEN: The add_tools_menu_item() method should have been called
- assert mocked_plugin.add_tools_menu_item.call_count == 0, \
- 'The add_tools_menu_item() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.add_tools_menu_item.call_count,
+ 'The add_tools_menu_item() method should not have been called.')
def hook_tools_menu_with_active_plugin_test(self):
"""
@@ -288,7 +315,7 @@
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
mocked_plugin.is_active.assert_called_with()
- assert mocked_plugin.initialise.call_count == 0, 'The initialise() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.initialise.call_count, 'The initialise() method should not have been called.')
def initialise_plugins_with_active_plugin_test(self):
"""
@@ -324,7 +351,7 @@
# THEN: The is_active() method should have been called, and initialise() method should NOT have been called
mocked_plugin.is_active.assert_called_with()
- assert mocked_plugin.finalise.call_count == 0, 'The finalise() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.finalise.call_count, 'The finalise() method should not have been called.')
def finalise_plugins_with_active_plugin_test(self):
"""
@@ -392,8 +419,8 @@
# THEN: The isActive() method should have been called, and initialise() method should NOT have been called
mocked_plugin.is_active.assert_called_with()
- assert mocked_plugin.new_service_created.call_count == 0,\
- 'The new_service_created() method should not have been called.'
+ self.assertEqual(0, mocked_plugin.new_service_created.call_count,
+ 'The new_service_created() method should not have been called.')
def new_service_created_with_active_plugin_test(self):
"""
=== modified file 'tests/functional/openlp_core_lib/test_registry.py'
--- tests/functional/openlp_core_lib/test_registry.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_registry.py 2013-09-29 21:32:52 +0000
@@ -1,12 +1,39 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib package.
"""
import os
from unittest import TestCase
-from mock import MagicMock
-
from openlp.core.lib import Registry
+from tests.functional import MagicMock
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
@@ -32,14 +59,14 @@
with self.assertRaises(KeyError) as context:
Registry().register('test1', mock_1)
self.assertEqual(context.exception.args[0], 'Duplicate service exception test1',
- 'KeyError exception should have been thrown for duplicate service')
+ 'KeyError exception should have been thrown for duplicate service')
# WHEN I try to get back a non existent component
# THEN I will get an exception
with self.assertRaises(KeyError) as context:
temp = Registry().get('test2')
self.assertEqual(context.exception.args[0], 'Service test2 not found in list',
- 'KeyError exception should have been thrown for missing service')
+ 'KeyError exception should have been thrown for missing service')
# WHEN I try to replace a component I should be allowed (testing only)
Registry().remove('test1')
@@ -47,7 +74,7 @@
with self.assertRaises(KeyError) as context:
temp = Registry().get('test1')
self.assertEqual(context.exception.args[0], 'Service test1 not found in list',
- 'KeyError exception should have been thrown for deleted service')
+ 'KeyError exception should have been thrown for deleted service')
def registry_function_test(self):
"""
=== modified file 'tests/functional/openlp_core_lib/test_screen.py'
--- tests/functional/openlp_core_lib/test_screen.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_screen.py 2013-09-29 21:32:52 +0000
@@ -1,14 +1,40 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib.screenlist package.
"""
-
from unittest import TestCase
-from mock import MagicMock
from PyQt4 import QtGui, QtCore
from openlp.core.lib import Registry, ScreenList
-
+from tests.functional import MagicMock
SCREEN = {
'primary': False,
@@ -55,5 +81,6 @@
# THEN: The screen should have been added and the screens should be identical
new_screen_count = len(self.screens.screen_list)
- assert old_screen_count + 1 == new_screen_count, 'The new_screens list should be bigger'
- assert SCREEN == self.screens.screen_list.pop(), 'The 2nd screen should be identical to the first screen'
+ self.assertEqual(old_screen_count + 1, new_screen_count, 'The new_screens list should be bigger')
+ self.assertEqual(SCREEN, self.screens.screen_list.pop(),
+ 'The 2nd screen should be identical to the first screen')
=== modified file 'tests/functional/openlp_core_lib/test_serviceitem.py'
--- tests/functional/openlp_core_lib/test_serviceitem.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_serviceitem.py 2013-09-29 21:32:52 +0000
@@ -1,16 +1,40 @@
# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
- Package to test the openlp.core.lib package.
+Package to test the openlp.core.lib package.
"""
import os
-import json
-import tempfile
from unittest import TestCase
-from mock import MagicMock, patch
from openlp.core.lib import ItemCapabilities, ServiceItem, Registry
-from lxml import objectify, etree
+from tests.functional import MagicMock, patch
+from tests.utils import assert_length, convert_file_service_item
VERSE = 'The Lord said to {r}Noah{/r}: \n'\
'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\
@@ -20,7 +44,6 @@
'{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}'\
'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456']
-
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'resources'))
@@ -36,7 +59,7 @@
Registry().register('renderer', mocked_renderer)
Registry().register('image_manager', MagicMock())
- def serviceitem_basic_test(self):
+ def service_item_basic_test(self):
"""
Test the Service Item - basic test
"""
@@ -46,10 +69,10 @@
service_item = ServiceItem(None)
# THEN: We should get back a valid service item
- assert service_item.is_valid is True, 'The new service item should be valid'
- assert service_item.missing_frames() is True, 'There should not be any frames in the service item'
+ self.assertTrue(service_item.is_valid, 'The new service item should be valid')
+ self.assertTrue(service_item.missing_frames(), 'There should not be any frames in the service item')
- def serviceitem_load_custom_from_service_test(self):
+ def service_item_load_custom_from_service_test(self):
"""
Test the Service Item - adding a custom slide from a saved service
"""
@@ -57,24 +80,29 @@
service_item = ServiceItem(None)
service_item.add_icon = MagicMock()
- # WHEN: adding a custom from a saved Service
- line = self.convert_file_service_item('serviceitem_custom_1.osj')
+ # WHEN: We add a custom from a saved service
+ line = convert_file_service_item(TEST_PATH, 'serviceitem_custom_1.osj')
service_item.set_from_service(line)
# THEN: We should get back a valid service item
- assert service_item.is_valid is True, 'The new service item should be valid'
- assert len(service_item._display_frames) == 0, 'The service item should have no display frames'
- assert len(service_item.capabilities) == 5, 'There should be 5 default custom item capabilities'
+ self.assertTrue(service_item.is_valid, 'The new service item should be valid')
+ assert_length(0, service_item._display_frames, 'The service item should have no display frames')
+ assert_length(5, service_item.capabilities, 'There should be 5 default custom item capabilities')
+
+ # WHEN: We render the frames of the service item
service_item.render(True)
- assert service_item.get_display_title() == 'Test Custom', 'The title should be "Test Custom"'
- assert service_item.get_frames()[0]['text'] == VERSE[:-1], \
- 'The returned text matches the input, except the last line feed'
- assert service_item.get_rendered_frame(1) == VERSE.split('\n', 1)[0], 'The first line has been returned'
- assert service_item.get_frame_title(0) == 'Slide 1', '"Slide 1" has been returned as the title'
- assert service_item.get_frame_title(1) == 'Slide 2', '"Slide 2" has been returned as the title'
- assert service_item.get_frame_title(2) == '', 'Blank has been returned as the title of slide 3'
-
- def serviceitem_load_image_from_service_test(self):
+
+ # THEN: The frames should also be valid
+ self.assertEqual('Test Custom', service_item.get_display_title(), 'The title should be "Test Custom"')
+ self.assertEqual(VERSE[:-1], service_item.get_frames()[0]['text'],
+ 'The returned text matches the input, except the last line feed')
+ self.assertEqual(VERSE.split('\n', 1)[0], service_item.get_rendered_frame(1),
+ 'The first line has been returned')
+ self.assertEqual('Slide 1', service_item.get_frame_title(0), '"Slide 1" has been returned as the title')
+ self.assertEqual('Slide 2', service_item.get_frame_title(1), '"Slide 2" has been returned as the title')
+ self.assertEqual('', service_item.get_frame_title(2), 'Blank has been returned as the title of slide 3')
+
+ def service_item_load_image_from_service_test(self):
"""
Test the Service Item - adding an image from a saved service
"""
@@ -87,29 +115,34 @@
service_item.add_icon = MagicMock()
# WHEN: adding an image from a saved Service and mocked exists
- line = self.convert_file_service_item('serviceitem_image_1.osj')
+ line = convert_file_service_item(TEST_PATH, 'serviceitem_image_1.osj')
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
mocked_exists.return_value = True
service_item.set_from_service(line, TEST_PATH)
# THEN: We should get back a valid service item
- assert service_item.is_valid is True, 'The new service item should be valid'
- assert service_item.get_rendered_frame(0) == test_file, 'The first frame should match the path to the image'
- assert service_item.get_frames()[0] == frame_array, 'The return should match frame array1'
- assert service_item.get_frame_path(0) == test_file, 'The frame path should match the full path to the image'
- assert service_item.get_frame_title(0) == image_name, 'The frame title should match the image name'
- assert service_item.get_display_title() == image_name, 'The display title should match the first image name'
- assert service_item.is_image() is True, 'This service item should be of an "image" type'
- assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
- 'This service item should be able to be Maintained'
- assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
- 'This service item should be able to be be Previewed'
- assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
- 'This service item should be able to be run in a can be made to Loop'
- assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
- 'This service item should be able to have new items added to it'
+ self.assertTrue(service_item.is_valid, 'The new service item should be valid')
+ self.assertEqual(test_file, service_item.get_rendered_frame(0),
+ 'The first frame should match the path to the image')
+ self.assertEqual(frame_array, service_item.get_frames()[0],
+ 'The return should match frame array1')
+ self.assertEqual(test_file, service_item.get_frame_path(0),
+ 'The frame path should match the full path to the image')
+ self.assertEqual(image_name, service_item.get_frame_title(0),
+ 'The frame title should match the image name')
+ self.assertEqual(image_name, service_item.get_display_title(),
+ 'The display title should match the first image name')
+ self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
+ 'This service item should be able to be Maintained')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
+ 'This service item should be able to be be Previewed')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
+ 'This service item should be able to be run in a can be made to Loop')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
+ 'This service item should be able to have new items added to it')
- def serviceitem_load_image_from_local_service_test(self):
+ def service_item_load_image_from_local_service_test(self):
"""
Test the Service Item - adding an image from a saved local service
"""
@@ -128,50 +161,42 @@
service_item2.add_icon = MagicMock()
# WHEN: adding an image from a saved Service and mocked exists
- line = self.convert_file_service_item('serviceitem_image_2.osj')
- line2 = self.convert_file_service_item('serviceitem_image_2.osj', 1)
+ line = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj')
+ line2 = convert_file_service_item(TEST_PATH, 'serviceitem_image_2.osj', 1)
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists:
mocked_exists.return_value = True
service_item2.set_from_service(line2)
service_item.set_from_service(line)
-
# THEN: We should get back a valid service item
# This test is copied from service_item.py, but is changed since to conform to
# new layout of service item. The layout use in serviceitem_image_2.osd is actually invalid now.
- assert service_item.is_valid is True, 'The first service item should be valid'
- assert service_item2.is_valid is True, 'The second service item should be valid'
- assert service_item.get_rendered_frame(0) == test_file1, 'The first frame should match the path to the image'
- assert service_item2.get_rendered_frame(0) == test_file2, 'The Second frame should match the path to the image'
- assert service_item.get_frames()[0] == frame_array1, 'The return should match the frame array1'
- assert service_item2.get_frames()[0] == frame_array2, 'The return should match the frame array2'
- assert service_item.get_frame_path(0) == test_file1, 'The frame path should match the full path to the image'
- assert service_item2.get_frame_path(0) == test_file2, 'The frame path should match the full path to the image'
- assert service_item.get_frame_title(0) == image_name1, 'The 1st frame title should match the image name'
- assert service_item2.get_frame_title(0) == image_name2, 'The 2nd frame title should match the image name'
- assert service_item.title.lower() == service_item.name, \
- 'The plugin name should match the display title, as there are > 1 Images'
- assert service_item.is_image() is True, 'This service item should be of an "image" type'
- assert service_item.is_capable(ItemCapabilities.CanMaintain) is True, \
- 'This service item should be able to be Maintained'
- assert service_item.is_capable(ItemCapabilities.CanPreview) is True, \
- 'This service item should be able to be be Previewed'
- assert service_item.is_capable(ItemCapabilities.CanLoop) is True, \
- 'This service item should be able to be run in a can be made to Loop'
- assert service_item.is_capable(ItemCapabilities.CanAppend) is True, \
- 'This service item should be able to have new items added to it'
-
- def convert_file_service_item(self, name, row=0):
- service_file = os.path.join(TEST_PATH, name)
- try:
- open_file = open(service_file, 'r')
- items = json.load(open_file)
- first_line = items[row]
- except IOError:
- first_line = ''
- finally:
- open_file.close()
- return first_line
-
+ self.assertTrue(service_item.is_valid, 'The first service item should be valid')
+ self.assertTrue(service_item2.is_valid, 'The second service item should be valid')
+ self.assertEqual(test_file1, service_item.get_rendered_frame(0),
+ 'The first frame should match the path to the image')
+ self.assertEqual(test_file2, service_item2.get_rendered_frame(0),
+ 'The Second frame should match the path to the image')
+ self.assertEqual(frame_array1, service_item.get_frames()[0], 'The return should match the frame array1')
+ self.assertEqual(frame_array2, service_item2.get_frames()[0], 'The return should match the frame array2')
+ self.assertEqual(test_file1, service_item.get_frame_path(0),
+ 'The frame path should match the full path to the image')
+ self.assertEqual(test_file2, service_item2.get_frame_path(0),
+ 'The frame path should match the full path to the image')
+ self.assertEqual(image_name1, service_item.get_frame_title(0),
+ 'The 1st frame title should match the image name')
+ self.assertEqual(image_name2, service_item2.get_frame_title(0),
+ 'The 2nd frame title should match the image name')
+ self.assertEqual(service_item.name, service_item.title.lower(),
+ 'The plugin name should match the display title, as there are > 1 Images')
+ self.assertTrue(service_item.is_image(), 'This service item should be of an "image" type')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanMaintain),
+ 'This service item should be able to be Maintained')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanPreview),
+ 'This service item should be able to be be Previewed')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanLoop),
+ 'This service item should be able to be run in a can be made to Loop')
+ self.assertTrue(service_item.is_capable(ItemCapabilities.CanAppend),
+ 'This service item should be able to have new items added to it')
=== modified file 'tests/functional/openlp_core_lib/test_settings.py'
--- tests/functional/openlp_core_lib/test_settings.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_lib/test_settings.py 2013-09-29 21:32:52 +0000
@@ -1,14 +1,42 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
- Package to test the openlp.core.lib.settings package.
+Package to test the openlp.core.lib.settings package.
"""
import os
from unittest import TestCase
from tempfile import mkstemp
+from PyQt4 import QtGui
+
from openlp.core.lib import Settings
-from PyQt4 import QtGui
-
class TestSettings(TestCase):
"""
@@ -40,13 +68,13 @@
default_value = Settings().value('core/has run wizard')
# THEN the default value is returned
- assert default_value is False, 'The default value should be False'
+ self.assertFalse(default_value, 'The default value should be False')
# WHEN a new value is saved into config
Settings().setValue('core/has run wizard', True)
# THEN the new value is returned when re-read
- assert Settings().value('core/has run wizard') is True, 'The saved value should have been returned'
+ self.assertTrue(Settings().value('core/has run wizard'), 'The saved value should have been returned')
def settings_override_test(self):
"""
@@ -62,13 +90,13 @@
extend = Settings().value('test/extend')
# THEN the default value is returned
- assert extend == 'very wide', 'The default value of "very wide" should be returned'
+ self.assertEqual('very wide', extend, 'The default value of "very wide" should be returned')
# WHEN a new value is saved into config
Settings().setValue('test/extend', 'very short')
# THEN the new value is returned when re-read
- assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
+ self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned')
def settings_override_with_group_test(self):
"""
@@ -86,10 +114,10 @@
extend = settings.value('extend')
# THEN the default value is returned
- assert extend == 'very wide', 'The default value defined should be returned'
+ self.assertEqual('very wide', extend, 'The default value defined should be returned')
# WHEN a new value is saved into config
Settings().setValue('test/extend', 'very short')
# THEN the new value is returned when re-read
- assert Settings().value('test/extend') == 'very short', 'The saved value should be returned'
+ self.assertEqual('very short', Settings().value('test/extend'), 'The saved value should be returned')
=== modified file 'tests/functional/openlp_core_lib/test_uistrings.py'
--- tests/functional/openlp_core_lib/test_uistrings.py 2013-03-30 06:56:28 +0000
+++ tests/functional/openlp_core_lib/test_uistrings.py 2013-09-29 21:32:52 +0000
@@ -1,7 +1,34 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.lib.uistrings package.
"""
-
from unittest import TestCase
from openlp.core.lib import UiStrings
@@ -18,6 +45,6 @@
second_instance = UiStrings()
# THEN: Check if the instances are the same.
- assert first_instance is second_instance, "They should be the same instance!"
+ self.assertIs(first_instance, second_instance, 'Two UiStrings objects should be the same instance')
=== modified file 'tests/functional/openlp_core_utils/test_actions.py'
--- tests/functional/openlp_core_utils/test_actions.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_utils/test_actions.py 2013-09-29 21:32:52 +0000
@@ -1,3 +1,31 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Package to test the openlp.core.utils.actions package.
"""
@@ -12,6 +40,9 @@
class TestActionList(TestCase):
+ """
+ Test the ActionList class
+ """
def setUp(self):
"""
=== modified file 'tests/functional/openlp_core_utils/test_applocation.py'
--- tests/functional/openlp_core_utils/test_applocation.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_core_utils/test_applocation.py 2013-09-29 21:32:52 +0000
@@ -1,13 +1,39 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Functional tests to test the AppLocation class and related methods.
"""
import copy
from unittest import TestCase
-from mock import patch
-
from openlp.core.utils import AppLocation
-
+from tests.functional import patch
FILE_LIST = ['file1', 'file2', 'file3.txt', 'file4.txt', 'file5.mp3', 'file6.mp3']
@@ -38,7 +64,7 @@
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_get_directory.assert_called_with(AppLocation.DataDir)
mocked_check_directory_exists.assert_called_with('test/dir')
- assert data_path == 'test/dir', 'Result should be "test/dir"'
+ self.assertEqual('test/dir', data_path, 'Result should be "test/dir"')
def get_data_path_with_custom_location_test(self):
"""
@@ -58,7 +84,7 @@
# THEN: the mocked Settings methods were called and the value returned was our set up value
mocked_settings.contains.assert_called_with('advanced/data path')
mocked_settings.value.assert_called_with('advanced/data path')
- assert data_path == 'custom/dir', 'Result should be "custom/dir"'
+ self.assertEqual('custom/dir', data_path, 'Result should be "custom/dir"')
def get_files_no_section_no_extension_test(self):
"""
@@ -74,7 +100,7 @@
result = AppLocation.get_files()
# Then: check if the file lists are identical.
- assert result == FILE_LIST, 'The file lists should be identical.'
+ self.assertListEqual(FILE_LIST, result, 'The file lists should be identical.')
def get_files_test(self):
"""
@@ -93,7 +119,7 @@
mocked_listdir.assert_called_with('test/dir/section')
# Then: check if the file lists are identical.
- assert result == ['file5.mp3', 'file6.mp3'], 'The file lists should be identical.'
+ self.assertListEqual(['file5.mp3', 'file6.mp3'], result, 'The file lists should be identical.')
def get_section_data_path_test(self):
"""
@@ -110,25 +136,27 @@
# THEN: check that all the correct methods were called, and the result is correct
mocked_check_directory_exists.assert_called_with('test/dir/section')
- assert data_path == 'test/dir/section', 'Result should be "test/dir/section"'
+ self.assertEqual('test/dir/section', data_path, 'Result should be "test/dir/section"')
def get_directory_for_app_dir_test(self):
"""
Test the AppLocation.get_directory() method for AppLocation.AppDir
"""
+ # GIVEN: A mocked out _get_frozen_path function
with patch('openlp.core.utils.applocation._get_frozen_path') as mocked_get_frozen_path:
mocked_get_frozen_path.return_value = 'app/dir'
# WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.AppDir)
- # THEN:
- assert directory == 'app/dir', 'Directory should be "app/dir"'
+ # THEN: check that the correct directory is returned
+ self.assertEqual('app/dir', directory, 'Directory should be "app/dir"')
def get_directory_for_plugins_dir_test(self):
"""
Test the AppLocation.get_directory() method for AppLocation.PluginsDir
"""
+ # GIVEN: _get_frozen_path, abspath, split and sys are mocked out
with patch('openlp.core.utils.applocation._get_frozen_path') as mocked_get_frozen_path, \
patch('openlp.core.utils.applocation.os.path.abspath') as mocked_abspath, \
patch('openlp.core.utils.applocation.os.path.split') as mocked_split, \
@@ -142,6 +170,5 @@
# WHEN: We call AppLocation.get_directory
directory = AppLocation.get_directory(AppLocation.PluginsDir)
- # THEN:
- assert directory == 'plugins/dir', 'Directory should be "plugins/dir"'
-
+ # THEN: The correct directory should be returned
+ self.assertEqual('plugins/dir', directory, 'Directory should be "plugins/dir"')
=== modified file 'tests/functional/openlp_core_utils/test_utils.py'
--- tests/functional/openlp_core_utils/test_utils.py 2013-09-11 15:09:36 +0000
+++ tests/functional/openlp_core_utils/test_utils.py 2013-09-29 21:32:52 +0000
@@ -1,25 +1,52 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
Functional tests to test the AppLocation class and related methods.
"""
from unittest import TestCase
-from mock import patch
-
from openlp.core.utils import clean_filename, get_filesystem_encoding, _get_frozen_path, get_locale_key, \
get_natural_key, split_filename
+from tests.functional import patch
class TestUtils(TestCase):
"""
A test suite to test out various methods around the AppLocation class.
"""
- def get_filesystem_encoding_test(self):
- """
- Test the get_filesystem_encoding() function
- """
+ def get_filesystem_encoding_sys_function_not_called_test(self):
+ """
+ Test the get_filesystem_encoding() function does not call the sys.getdefaultencoding() function
+ """
+ # GIVEN: sys.getfilesystemencoding returns "cp1252"
with patch('openlp.core.utils.sys.getfilesystemencoding') as mocked_getfilesystemencoding, \
patch('openlp.core.utils.sys.getdefaultencoding') as mocked_getdefaultencoding:
- # GIVEN: sys.getfilesystemencoding returns "cp1252"
mocked_getfilesystemencoding.return_value = 'cp1252'
# WHEN: get_filesystem_encoding() is called
@@ -27,10 +54,16 @@
# THEN: getdefaultencoding should have been called
mocked_getfilesystemencoding.assert_called_with()
- assert not mocked_getdefaultencoding.called
- assert result == 'cp1252', 'The result should be "cp1252"'
+ self.assertEqual(0, mocked_getdefaultencoding.called, 'getdefaultencoding should not have been called')
+ self.assertEqual('cp1252', result, 'The result should be "cp1252"')
- # GIVEN: sys.getfilesystemencoding returns None and sys.getdefaultencoding returns "utf-8"
+ def get_filesystem_encoding_sys_function_is_called_test(self):
+ """
+ Test the get_filesystem_encoding() function calls the sys.getdefaultencoding() function
+ """
+ # GIVEN: sys.getfilesystemencoding returns None and sys.getdefaultencoding returns "utf-8"
+ with patch('openlp.core.utils.sys.getfilesystemencoding') as mocked_getfilesystemencoding, \
+ patch('openlp.core.utils.sys.getdefaultencoding') as mocked_getdefaultencoding:
mocked_getfilesystemencoding.return_value = None
mocked_getdefaultencoding.return_value = 'utf-8'
@@ -40,23 +73,35 @@
# THEN: getdefaultencoding should have been called
mocked_getfilesystemencoding.assert_called_with()
mocked_getdefaultencoding.assert_called_with()
- assert result == 'utf-8', 'The result should be "utf-8"'
+ self.assertEqual('utf-8', result, 'The result should be "utf-8"')
- def get_frozen_path_test(self):
+ def get_frozen_path_in_unfrozen_app_test(self):
"""
- Test the _get_frozen_path() function
+ Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller)
"""
with patch('openlp.core.utils.sys') as mocked_sys:
# GIVEN: The sys module "without" a "frozen" attribute
mocked_sys.frozen = None
+
# WHEN: We call _get_frozen_path() with two parameters
+ frozen_path = _get_frozen_path('frozen', 'not frozen')
+
# THEN: The non-frozen parameter is returned
- assert _get_frozen_path('frozen', 'not frozen') == 'not frozen', 'Should return "not frozen"'
+ self.assertEqual('not frozen', frozen_path, '_get_frozen_path should return "not frozen"')
+
+ def get_frozen_path_in_frozen_app_test(self):
+ """
+ Test the _get_frozen_path() function when the application is frozen (compiled by PyInstaller)
+ """
+ with patch('openlp.core.utils.sys') as mocked_sys:
# GIVEN: The sys module *with* a "frozen" attribute
mocked_sys.frozen = 1
+
# WHEN: We call _get_frozen_path() with two parameters
+ frozen_path = _get_frozen_path('frozen', 'not frozen')
+
# THEN: The frozen parameter is returned
- assert _get_frozen_path('frozen', 'not frozen') == 'frozen', 'Should return "frozen"'
+ self.assertEqual('frozen', frozen_path, 'Should return "frozen"')
def split_filename_with_file_path_test(self):
"""
@@ -72,7 +117,7 @@
result = split_filename(file_path)
# THEN: A tuple should be returned.
- assert result == wanted_result, 'A tuple with the directory and file name should have been returned.'
+ self.assertEqual(wanted_result, result, 'A tuple with the dir and file name should have been returned')
def split_filename_with_dir_path_test(self):
"""
@@ -88,8 +133,8 @@
result = split_filename(file_path)
# THEN: A tuple should be returned.
- assert result == wanted_result, \
- 'A two-entry tuple with the directory and file name (empty) should have been returned.'
+ self.assertEqual(wanted_result, result,
+ 'A two-entry tuple with the directory and file name (empty) should have been returned.')
def clean_filename_test(self):
"""
@@ -103,7 +148,7 @@
result = clean_filename(invalid_name)
# THEN: The file name should be cleaned.
- assert result == wanted_name, 'The file name should not contain any special characters.'
+ self.assertEqual(wanted_name, result, 'The file name should not contain any special characters.')
def get_locale_key_windows_test(self):
"""
@@ -116,13 +161,15 @@
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
+ sorted_list = sorted(unsorted_list, key=get_locale_key)
+
# 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'
+ self.assertEqual(['Aushang', '\u00C4u\u00DFerung', 'Auszug'], sorted_list,
+ 'Strings should be sorted properly')
def get_locale_key_linux_test(self):
-
"""
Test the get_locale_key(string) function
"""
@@ -134,9 +181,11 @@
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
+ sorted_list = sorted(unsorted_list, key=get_locale_key)
+
# 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'
+ self.assertEqual(['Aushang', '\u00C4u\u00DFerung', 'Auszug'], sorted_list,
+ 'Strings should be sorted properly')
def get_natural_key_test(self):
"""
@@ -146,7 +195,9 @@
# GIVEN: The language is English (a language, which sorts digits before letters)
mocked_get_language.return_value = 'en'
unsorted_list = ['item 10a', 'item 3b', '1st item']
+
# WHEN: We sort the list and use get_natural_key() to generate the sorting keys
+ sorted_list = sorted(unsorted_list, key=get_natural_key)
+
# THEN: We get a properly sorted list
- test_passes = sorted(unsorted_list, key=get_natural_key) == ['1st item', 'item 3b', 'item 10a']
- assert test_passes, 'Numbers should be sorted naturally'
+ self.assertEqual(['1st item', 'item 3b', 'item 10a'], sorted_list, 'Numbers should be sorted naturally')
=== modified file 'tests/functional/openlp_plugins/bibles/test_lib.py'
--- tests/functional/openlp_plugins/bibles/test_lib.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/bibles/test_lib.py 2013-09-29 21:32:52 +0000
@@ -1,3 +1,31 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Bibles plugin.
"""
=== modified file 'tests/functional/openlp_plugins/bibles/test_versereferencelist.py'
--- tests/functional/openlp_plugins/bibles/test_versereferencelist.py 2013-08-31 20:04:36 +0000
+++ tests/functional/openlp_plugins/bibles/test_versereferencelist.py 2013-09-29 21:32:52 +0000
@@ -1,15 +1,43 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the versereferencelist submodule of the Bibles plugin.
"""
from unittest import TestCase
+
from openlp.plugins.bibles.lib.versereferencelist import VerseReferenceList
+
class TestVerseReferenceList(TestCase):
- def setUp(self):
- """
- Initializes all we need
- """
-
+ """
+ Test the VerseReferenceList class
+ """
def add_first_verse_test(self):
"""
Test the addition of a verse to the empty list
@@ -20,12 +48,12 @@
chapter = 1
verse = 1
version = 'testVersion'
- copyright = 'testCopyright'
+ copyright_ = 'testCopyright'
permission = 'testPermision'
-
+
# WHEN: We add it to the verse list
- reference_list.add(book, chapter, verse, version, copyright, permission)
-
+ reference_list.add(book, chapter, verse, version, copyright_, permission)
+
# THEN: The entries should be in the first entry of the list
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
self.assertEqual(reference_list.verse_list[0]['book'], book, 'The book in first entry should be %s' % book)
@@ -33,7 +61,7 @@
self.assertEqual(reference_list.verse_list[0]['start'], verse, 'The start in first entry should be %u' % verse)
self.assertEqual(reference_list.verse_list[0]['version'], version, 'The version in first entry should be %s' % version)
self.assertEqual(reference_list.verse_list[0]['end'], verse, 'The end in first entry should be %u' % verse)
-
+
def add_next_verse_test(self):
"""
Test the addition of the following verse
@@ -44,14 +72,14 @@
verse = 1
next_verse = 2
version = 'testVersion'
- copyright = 'testCopyright'
+ copyright_ = 'testCopyright'
permission = 'testPermision'
reference_list = VerseReferenceList()
- reference_list.add(book, chapter, verse, version, copyright, permission)
+ reference_list.add(book, chapter, verse, version, copyright_, permission)
# WHEN: We add the following verse to the verse list
- reference_list.add(book, chapter, next_verse, version, copyright, permission)
-
+ reference_list.add(book, chapter, next_verse, version, copyright_, permission)
+
# THEN: The current index should be 0 and the end pointer of the entry should be '2'
self.assertEqual(reference_list.current_index, 0, 'The current index should be 0')
self.assertEqual(reference_list.verse_list[0]['end'], next_verse, 'The end in first entry should be %u' % next_verse)
@@ -64,19 +92,18 @@
book = 'testBook'
chapter = 1
verse = 1
- next_verse = 2
another_book = 'testBook2'
another_chapter = 2
another_verse = 5
version = 'testVersion'
- copyright = 'testCopyright'
+ copyright_ = 'testCopyright'
permission = 'testPermision'
reference_list = VerseReferenceList()
- reference_list.add(book, chapter, verse, version, copyright, permission)
+ reference_list.add(book, chapter, verse, version, copyright_, permission)
# WHEN: We add a verse of another book to the verse list
- reference_list.add(another_book, another_chapter, another_verse, version, copyright, permission)
-
+ reference_list.add(another_book, another_chapter, another_verse, version, copyright_, permission)
+
# THEN: the current index should be 1
self.assertEqual(reference_list.current_index, 1, 'The current index should be 1')
@@ -87,17 +114,18 @@
# GIVEN: version, copyright and permission
reference_list = VerseReferenceList()
version = 'testVersion'
- copyright = 'testCopyright'
+ copyright_ = 'testCopyright'
permission = 'testPermision'
# WHEN: a not existing version will be added
- reference_list.add_version(version, copyright, permission)
-
+ reference_list.add_version(version, copyright_, permission)
+
# THEN: the data will be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should be appended')
- self.assertEqual(reference_list.version_list[0], {'version': version, 'copyright': copyright, 'permission': permission},
- 'The version data should be appended')
-
+ self.assertEqual(reference_list.version_list[0],
+ {'version': version, 'copyright': copyright_, 'permission': permission},
+ 'The version data should be appended')
+
def add_existing_version_test(self):
"""
Test the addition of an existing version to the list
@@ -105,12 +133,12 @@
# GIVEN: version, copyright and permission, added to the version list
reference_list = VerseReferenceList()
version = 'testVersion'
- copyright = 'testCopyright'
+ copyright_ = 'testCopyright'
permission = 'testPermision'
- reference_list.add_version(version, copyright, permission)
-
+ reference_list.add_version(version, copyright_, permission)
+
# WHEN: an existing version will be added
- reference_list.add_version(version, copyright, permission)
-
+ reference_list.add_version(version, copyright_, permission)
+
# THEN: the data will not be appended to the list
self.assertEqual(len(reference_list.version_list), 1, 'The version data should not be appended')
=== modified file 'tests/functional/openlp_plugins/images/test_lib.py'
--- tests/functional/openlp_plugins/images/test_lib.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/images/test_lib.py 2013-09-29 21:32:52 +0000
@@ -1,16 +1,40 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Images plugin.
"""
-
from unittest import TestCase
-from mock import MagicMock, patch
-
from openlp.core.lib import Registry
from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups
from openlp.plugins.images.lib.mediaitem import ImageMediaItem
+from tests.functional import MagicMock, patch
class TestImageMediaItem(TestCase):
@@ -36,7 +60,7 @@
"""
# GIVEN: An empty image_list
image_list = []
- with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
+ with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list'):
self.media_item.manager = MagicMock()
# WHEN: We run save_new_images_list with the empty list
@@ -50,8 +74,8 @@
"""
Test that the save_new_images_list() calls load_full_list() when reload_list is set to True
"""
- # GIVEN: A list with 1 image
- image_list = [ 'test_image.jpg' ]
+ # GIVEN: A list with 1 image and a mocked out manager
+ image_list = ['test_image.jpg']
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
ImageFilenames.filename = ''
self.media_item.manager = MagicMock()
@@ -69,8 +93,8 @@
"""
Test that the save_new_images_list() doesn't call load_full_list() when reload_list is set to False
"""
- # GIVEN: A list with 1 image
- image_list = [ 'test_image.jpg' ]
+ # GIVEN: A list with 1 image and a mocked out manager
+ image_list = ['test_image.jpg']
with patch('openlp.plugins.images.lib.mediaitem.ImageMediaItem.load_full_list') as mocked_load_full_list:
self.media_item.manager = MagicMock()
@@ -126,9 +150,35 @@
self.media_item.reset_action.setVisible.assert_called_with(False)
self.media_item.live_controller.display.reset_image.assert_called_with()
+ def recursively_delete_group_test(self):
+ """
+ Test that recursively_delete_group() works
+ """
+ # GIVEN: An ImageGroups object and mocked functions
+ with patch('openlp.core.utils.delete_file') as mocked_delete_file:
+ ImageFilenames.group_id = 1
+ ImageGroups.parent_id = 1
+ self.media_item.manager = MagicMock()
+ self.media_item.manager.get_all_objects.side_effect = self._recursively_delete_group_side_effect
+ self.media_item.servicePath = ""
+ test_group = ImageGroups()
+ test_group.id = 1
+
+ # WHEN: recursively_delete_group() is called
+ self.media_item.recursively_delete_group(test_group)
+
+ # THEN:
+ assert mocked_delete_file.call_count == 0, 'delete_file() should not be called'
+ assert self.media_item.manager.delete_object.call_count == 7, \
+ 'manager.delete_object() should be called exactly 7 times'
+
+ # CLEANUP: Remove added attribute from ImageFilenames and ImageGroups
+ delattr(ImageFilenames, 'group_id')
+ delattr(ImageGroups, 'parent_id')
+
def _recursively_delete_group_side_effect(*args, **kwargs):
"""
- Side effect method that creates custom retun values for the recursively_delete_group method
+ Side effect method that creates custom return values for the recursively_delete_group method
"""
if args[1] == ImageFilenames and args[2]:
# Create some fake objects that should be removed
@@ -150,29 +200,3 @@
returned_object1.id = 1
return [returned_object1]
return []
-
- def recursively_delete_group_test(self):
- """
- Test that recursively_delete_group() works
- """
- # GIVEN: An ImageGroups object and mocked functions
- with patch('openlp.core.utils.delete_file') as mocked_delete_file:
- ImageFilenames.group_id = 1
- ImageGroups.parent_id = 1
- self.media_item.manager = MagicMock()
- self.media_item.manager.get_all_objects.side_effect = self._recursively_delete_group_side_effect
- self.media_item.servicePath = ""
- test_group = ImageGroups()
- test_group.id = 1
-
- # WHEN: recursively_delete_group() is called
- self.media_item.recursively_delete_group(test_group)
-
- # THEN:
- assert mocked_delete_file.call_count == 0, 'delete_file() should not be called'
- assert self.media_item.manager.delete_object.call_count == 7, \
- 'manager.delete_object() should be called exactly 7 times'
-
- # CLEANUP: Remove added attribute from ImageFilenames and ImageGroups
- delattr(ImageFilenames, 'group_id')
- delattr(ImageGroups, 'parent_id')
=== modified file 'tests/functional/openlp_plugins/presentations/test_mediaitem.py'
--- tests/functional/openlp_plugins/presentations/test_mediaitem.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/presentations/test_mediaitem.py 2013-09-29 21:32:52 +0000
@@ -1,17 +1,41 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Presentations plugin.
"""
-import os
-from tempfile import mkstemp
from unittest import TestCase
-from mock import patch, MagicMock
-
from PyQt4 import QtGui
from openlp.core.lib import Registry
-
from openlp.plugins.presentations.lib.mediaitem import PresentationMediaItem
+from tests.functional import patch, MagicMock
class TestMediaItem(TestCase):
@@ -68,4 +92,3 @@
# THEN: The file mask should be generated.
assert self.media_item.on_new_file_masks == 'Presentations (*.odp *.ppt )', \
'The file mask should contain the odp and ppt extensions'
-
=== modified file 'tests/functional/openlp_plugins/remotes/test_remotetab.py'
--- tests/functional/openlp_plugins/remotes/test_remotetab.py 2013-09-10 18:18:53 +0000
+++ tests/functional/openlp_plugins/remotes/test_remotetab.py 2013-09-29 21:32:52 +0000
@@ -1,17 +1,44 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Remotes plugin.
"""
import os
import re
-
from unittest import TestCase
from tempfile import mkstemp
-from mock import patch
+
+from PyQt4 import QtGui
from openlp.core.lib import Settings
from openlp.plugins.remotes.lib.remotetab import RemoteTab
-
-from PyQt4 import QtGui
+from tests.functional import patch
__default_settings__ = {
'remotes/twelve hour': True,
@@ -23,9 +50,7 @@
'remotes/authentication enabled': False,
'remotes/ip address': '0.0.0.0'
}
-
ZERO_URL = '0.0.0.0'
-
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
@@ -60,7 +85,8 @@
# WHEN: the default ip address is given
ip_address = self.form.get_ip_address(ZERO_URL)
# THEN: the default ip address will be returned
- self.assertTrue(re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address), 'The return value should be a valid ip address')
+ self.assertTrue(re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address),
+ 'The return value should be a valid ip address')
def get_ip_address_with_ip_test(self):
"""
@@ -80,9 +106,9 @@
"""
# GIVEN: A mocked location
with patch('openlp.core.utils.applocation.Settings') as mocked_class, \
- patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
- patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
- patch('openlp.core.utils.applocation.os') as mocked_os:
+ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
+ patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
+ patch('openlp.core.utils.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
@@ -96,7 +122,7 @@
# THEN: the following screen values should be set
self.assertEqual(self.form.address_edit.text(), ZERO_URL, 'The default URL should be set on the screen')
self.assertEqual(self.form.https_settings_group_box.isEnabled(), False,
- 'The Https box should not be enabled')
+ 'The Https box should not be enabled')
self.assertEqual(self.form.https_settings_group_box.isChecked(), False,
'The Https checked box should note be Checked')
self.assertEqual(self.form.user_login_group_box.isChecked(), False,
@@ -108,9 +134,9 @@
"""
# GIVEN: A mocked location
with patch('openlp.core.utils.applocation.Settings') as mocked_class, \
- patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
- patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
- patch('openlp.core.utils.applocation.os') as mocked_os:
+ patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \
+ patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \
+ patch('openlp.core.utils.applocation.os') as mocked_os:
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
mocked_settings = mocked_class.return_value
mocked_settings.contains.return_value = False
=== modified file 'tests/functional/openlp_plugins/remotes/test_router.py'
--- tests/functional/openlp_plugins/remotes/test_router.py 2013-09-14 21:00:58 +0000
+++ tests/functional/openlp_plugins/remotes/test_router.py 2013-09-29 21:32:52 +0000
@@ -1,15 +1,43 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Remotes plugin.
"""
import os
-
from unittest import TestCase
from tempfile import mkstemp
-from mock import MagicMock
+
+from PyQt4 import QtGui
from openlp.core.lib import Settings
from openlp.plugins.remotes.lib.httpserver import HttpRouter
-from PyQt4 import QtGui
+from tests.functional import MagicMock
__default_settings__ = {
'remotes/twelve hour': True,
=== modified file 'tests/functional/openlp_plugins/songs/test_ewimport.py'
--- tests/functional/openlp_plugins/songs/test_ewimport.py 2013-09-07 18:36:33 +0000
+++ tests/functional/openlp_plugins/songs/test_ewimport.py 2013-09-29 21:32:52 +0000
@@ -1,13 +1,39 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the EasyWorship song importer.
"""
import os
from unittest import TestCase
-from mock import patch, MagicMock
+
+from tests.functional import MagicMock, patch
from openlp.plugins.songs.lib.ewimport import EasyWorshipSongImport, FieldDescEntry, FieldType
@@ -43,6 +69,7 @@
'Just to bow and receive a new blessing,\nIn the beautiful garden of prayer.', 'v3')],
'verse_order_list': []}]
+
class EasyWorshipSongImportLogger(EasyWorshipSongImport):
"""
This class logs changes in the title instance variable
@@ -60,6 +87,7 @@
def title(self, title):
self._title_assignment_list.append(title)
+
class TestFieldDesc:
def __init__(self, name, field_type, size):
self.name = name
=== modified file 'tests/functional/openlp_plugins/songs/test_foilpresenterimport.py'
--- tests/functional/openlp_plugins/songs/test_foilpresenterimport.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/songs/test_foilpresenterimport.py 2013-09-29 21:32:52 +0000
@@ -32,9 +32,8 @@
import os
from unittest import TestCase
-from mock import patch, MagicMock
+from tests.functional import patch, MagicMock
-from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.foilpresenterimport import FoilPresenter
TEST_PATH = os.path.abspath(
@@ -192,4 +191,4 @@
# THEN: _process_lyrics should return None and the song_import logError method should have been called once
self.assertIsNone(result)
self.mocked_song_import.logError.assert_called_once_with('Element Text', 'Translated String')
- self.process_lyrics_patcher.start()
\ No newline at end of file
+ self.process_lyrics_patcher.start()
=== modified file 'tests/functional/openlp_plugins/songs/test_lib.py'
--- tests/functional/openlp_plugins/songs/test_lib.py 2013-09-08 03:50:51 +0000
+++ tests/functional/openlp_plugins/songs/test_lib.py 2013-09-29 21:32:52 +0000
@@ -1,13 +1,39 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the lib submodule of the Songs plugin.
"""
-
from unittest import TestCase
-from mock import patch, MagicMock
-
from openlp.plugins.songs.lib import VerseType, clean_string, clean_title, strip_rtf
from openlp.plugins.songs.lib.songcompare import songs_probably_equal, _remove_typos, _op_length
+from tests.functional import patch, MagicMock
class TestLib(TestCase):
@@ -68,10 +94,10 @@
# GIVEN: Two equal songs.
self.song1.search_lyrics = self.full_lyrics
self.song2.search_lyrics = self.full_lyrics
-
+
# WHEN: We compare those songs for equality.
result = songs_probably_equal(self.song1, self.song2)
-
+
# THEN: The result should be True.
assert result == True, 'The result should be True'
@@ -82,10 +108,10 @@
# GIVEN: A song and a short version of the same song.
self.song1.search_lyrics = self.full_lyrics
self.song2.search_lyrics = self.short_lyrics
-
+
# WHEN: We compare those songs for equality.
result = songs_probably_equal(self.song1, self.song2)
-
+
# THEN: The result should be True.
assert result == True, 'The result should be True'
@@ -96,10 +122,10 @@
# GIVEN: A song and the same song with lots of errors.
self.song1.search_lyrics = self.full_lyrics
self.song2.search_lyrics = self.error_lyrics
-
+
# WHEN: We compare those songs for equality.
result = songs_probably_equal(self.song1, self.song2)
-
+
# THEN: The result should be True.
assert result == True, 'The result should be True'
@@ -110,10 +136,10 @@
# GIVEN: Two different songs.
self.song1.search_lyrics = self.full_lyrics
self.song2.search_lyrics = self.different_lyrics
-
+
# WHEN: We compare those songs for equality.
result = songs_probably_equal(self.song1, self.song2)
-
+
# THEN: The result should be False.
assert result == False, 'The result should be False'
=== modified file 'tests/functional/openlp_plugins/songs/test_mediaitem.py'
--- tests/functional/openlp_plugins/songs/test_mediaitem.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/songs/test_mediaitem.py 2013-09-29 21:32:52 +0000
@@ -5,13 +5,11 @@
from tempfile import mkstemp
from unittest import TestCase
-from mock import patch, MagicMock
-
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Registry, ServiceItem, Settings
-
from openlp.plugins.songs.lib.mediaitem import SongMediaItem
+from tests.functional import patch, MagicMock
class TestMediaItem(TestCase):
=== modified file 'tests/functional/openlp_plugins/songs/test_songshowplusimport.py'
--- tests/functional/openlp_plugins/songs/test_songshowplusimport.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/songs/test_songshowplusimport.py 2013-09-29 21:32:52 +0000
@@ -1,13 +1,41 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the SongShow Plus song importer.
"""
import os
from unittest import TestCase
-from mock import patch, MagicMock
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.songshowplusimport import SongShowPlusImport
+from tests.functional import patch, MagicMock
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../resources/songshowplussongs'))
SONG_TEST_DATA = {'Amazing Grace.sbsong':
=== modified file 'tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py'
--- tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/songs/test_worshipcenterproimport.py 2013-09-29 21:32:52 +0000
@@ -1,15 +1,45 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
"""
This module contains tests for the WorshipCenter Pro song importer.
"""
-
-from unittest import TestCase
-from mock import patch, MagicMock
+import os
+from unittest import TestCase, SkipTest
+
+if os.name != 'nt':
+ raise SkipTest('Not Windows, skipping test')
+
import pyodbc
from openlp.plugins.songs.lib.worshipcenterproimport import WorshipCenterProImport
+from tests.functional import patch, MagicMock
+
class TestRecord(object):
"""
@@ -23,6 +53,7 @@
self.Field = field
self.Value = value
+
class WorshipCenterProImportLogger(WorshipCenterProImport):
"""
This class logs changes in the title instance variable
@@ -189,4 +220,4 @@
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')
=== modified file 'tests/utils/__init__.py'
--- tests/utils/__init__.py 2013-04-27 09:54:57 +0000
+++ tests/utils/__init__.py 2013-09-29 21:32:52 +0000
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
+
+###############################################################################
+# OpenLP - Open Source Lyrics Projection #
+# --------------------------------------------------------------------------- #
+# Copyright (c) 2008-2013 Raoul Snyman #
+# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
+# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
+# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
+# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
+# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
+# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
+# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
+# --------------------------------------------------------------------------- #
+# This program is free software; you can redistribute it and/or modify it #
+# under the terms of the GNU General Public License as published by the Free #
+# Software Foundation; version 2 of the License. #
+# #
+# This program is distributed in the hope that it will be useful, but WITHOUT #
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
+# more details. #
+# #
+# You should have received a copy of the GNU General Public License along #
+# with this program; if not, write to the Free Software Foundation, Inc., 59 #
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+###############################################################################
+import os
+import json
+
+
+def assert_length(expected, iterable, msg=None):
+ if len(iterable) != expected:
+ if not msg:
+ msg = 'Expected length %s, got %s' % (expected, len(iterable))
+ raise AssertionError(msg)
+
+
+def convert_file_service_item(test_path, name, row=0):
+ service_file = os.path.join(test_path, name)
+ open_file = open(service_file, 'r')
+ try:
+ items = json.load(open_file)
+ first_line = items[row]
+ except IOError:
+ first_line = ''
+ finally:
+ open_file.close()
+ return first_line
+
Follow ups