From 9067b16e0e4ac6ce90ed252264f108ac0e46168d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 21:59:45 +0000 Subject: [PATCH] fix up some tests --- openlp/core/lib/registry.py | 1 - .../openlp_core_lib/test_registry.py | 33 +++++++++++++++++++ .../openlp_core_lib/test_serviceitem.py | 22 +++++++------ 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_registry.py diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index 8ea0fc056..f5029828a 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -41,7 +41,6 @@ class Registry(object): log.info(u'Registry loaded') __instance__ = None - def __new__(cls): if not cls.__instance__: cls.__instance__ = object.__new__(cls) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py new file mode 100644 index 000000000..44515ae98 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -0,0 +1,33 @@ +""" + Package to test the openlp.core.lib package. +""" +import os + +from unittest import TestCase +from mock import MagicMock +from openlp.core.lib import ServiceItem, Registry + +TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + +class TestServiceItem(TestCase): + + def registry_basic_test(self): + """ + Test the Service Item basic test + """ + # GIVEN: A new registry + registry = Registry.create() + + # WHEN:A service item is created (without a plugin) + mock_1 = MagicMock() + Registry().register(u'test1', mock_1) + + # THEN: we should be able retrieve the saved object + assert Registry().get(u'test1') == mock_1, u'The saved object can be retrieved' + #assert service_item.missing_frames() is True, u'There should not be any frames in the service item' + + # THEN: We should get back a valid service item + try: + assert Registry().get(u'test2') == mock_1, u'This should not be fired' + except Exception, e: + pass \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index c2b9aacb1..43f05ed25 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -5,7 +5,7 @@ import os from unittest import TestCase from mock import MagicMock -from openlp.core.lib import ServiceItem +from openlp.core.lib import ServiceItem, Registry VERSE = u'The Lord said to {r}Noah{/r}: \n'\ 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\ @@ -20,6 +20,17 @@ TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', class TestServiceItem(TestCase): + def setUp(self): + """ + Set up the Registry + """ + registry = Registry.create() + mocked_renderer = MagicMock() + mocked_image_manager = MagicMock() + mocked_renderer.format_slide.return_value = [VERSE] + Registry().register(u'renderer', mocked_renderer) + Registry().register(u'image_manager', mocked_image_manager) + def serviceitem_basic_test(self): """ Test the Service Item basic test @@ -48,11 +59,6 @@ class TestServiceItem(TestCase): assert service_item.is_valid is True, u'The new service item should be valid' assert service_item.missing_frames() is False, u'check frames loaded ' - # GIVEN: A service item with text - mocked_renderer = MagicMock() - mocked_renderer.format_slide.return_value = [VERSE] - service_item.renderer = mocked_renderer - # WHEN: Render called assert len(service_item._display_frames) == 0, u'A blank Service Item with no display frames' service_item.render(True) @@ -68,8 +74,6 @@ class TestServiceItem(TestCase): # GIVEN: A new service item and a mocked renderer service_item = ServiceItem(None) service_item.name = u'test' - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer # WHEN: adding image to a service item test_image = os.path.join(TESTPATH, u'church.jpg') @@ -125,8 +129,6 @@ class TestServiceItem(TestCase): # GIVEN: A new service item and a mocked renderer service_item = ServiceItem(None) service_item.name = u'test' - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer # WHEN: adding image to a service item test_file = os.path.join(TESTPATH, u'church.jpg')