fix up some tests

This commit is contained in:
Tim Bentley 2013-01-22 21:59:45 +00:00
parent 064ca583ca
commit 9067b16e0e
3 changed files with 45 additions and 11 deletions

View File

@ -41,7 +41,6 @@ class Registry(object):
log.info(u'Registry loaded') log.info(u'Registry loaded')
__instance__ = None __instance__ = None
def __new__(cls): def __new__(cls):
if not cls.__instance__: if not cls.__instance__:
cls.__instance__ = object.__new__(cls) cls.__instance__ = object.__new__(cls)

View File

@ -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

View File

@ -5,7 +5,7 @@ import os
from unittest import TestCase from unittest import TestCase
from mock import MagicMock 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'\ VERSE = u'The Lord said to {r}Noah{/r}: \n'\
'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\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): 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): def serviceitem_basic_test(self):
""" """
Test the Service Item basic test 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.is_valid is True, u'The new service item should be valid'
assert service_item.missing_frames() is False, u'check frames loaded ' 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 # WHEN: Render called
assert len(service_item._display_frames) == 0, u'A blank Service Item with no display frames' assert len(service_item._display_frames) == 0, u'A blank Service Item with no display frames'
service_item.render(True) service_item.render(True)
@ -68,8 +74,6 @@ class TestServiceItem(TestCase):
# GIVEN: A new service item and a mocked renderer # GIVEN: A new service item and a mocked renderer
service_item = ServiceItem(None) service_item = ServiceItem(None)
service_item.name = u'test' service_item.name = u'test'
mocked_renderer = MagicMock()
service_item.renderer = mocked_renderer
# WHEN: adding image to a service item # WHEN: adding image to a service item
test_image = os.path.join(TESTPATH, u'church.jpg') 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 # GIVEN: A new service item and a mocked renderer
service_item = ServiceItem(None) service_item = ServiceItem(None)
service_item.name = u'test' service_item.name = u'test'
mocked_renderer = MagicMock()
service_item.renderer = mocked_renderer
# WHEN: adding image to a service item # WHEN: adding image to a service item
test_file = os.path.join(TESTPATH, u'church.jpg') test_file = os.path.join(TESTPATH, u'church.jpg')