forked from openlp/openlp
Fix up tests and amened Register
This commit is contained in:
parent
80a2a7449e
commit
9719645edd
@ -30,6 +30,7 @@
|
||||
Provide Registry Services
|
||||
"""
|
||||
import logging
|
||||
import sys
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -54,8 +55,13 @@ class Registry(object):
|
||||
log.info(u'Registry Initialising')
|
||||
registry = cls()
|
||||
registry.service_list = {}
|
||||
registry.running_under_test = False
|
||||
# Allow the tests to remove Registry entries but not the live system
|
||||
if u'nosetest' in sys.argv[0]:
|
||||
registry.running_under_test = True
|
||||
return registry
|
||||
|
||||
|
||||
def get(self, key):
|
||||
"""
|
||||
Extracts the registry value from the list based on the key passed in
|
||||
@ -75,3 +81,16 @@ class Registry(object):
|
||||
raise KeyError(u'Duplicate service exception %s' % key)
|
||||
else:
|
||||
self.service_list[key] = reference
|
||||
|
||||
def remove(self, key):
|
||||
"""
|
||||
Removes the registry value from the list based on the key passed in
|
||||
(Only valid and active for testing framework)
|
||||
"""
|
||||
if self.running_under_test == False:
|
||||
log.error(u'Invalid Method call for key %s' % key)
|
||||
raise KeyError(u'Invalid Method call for key %s' % key)
|
||||
return
|
||||
if key in self.service_list:
|
||||
del self.service_list[key]
|
||||
|
||||
|
@ -38,3 +38,11 @@ class TestRegistry(TestCase):
|
||||
temp = Registry().get(u'test2')
|
||||
self.assertEqual(context.exception[0], u'Service test2 not found in list',
|
||||
u'The correct exception has been thrown')
|
||||
|
||||
# WHEN I try to replace a component I should be allowed (testing only)
|
||||
Registry().remove(u'test1')
|
||||
# THEN I will get an exception
|
||||
with self.assertRaises(KeyError) as context:
|
||||
temp = Registry().get(u'test1')
|
||||
self.assertEqual(context.exception[0], u'Service test1 not found in list',
|
||||
u'The correct exception has been thrown as I deleted it!')
|
||||
|
@ -30,10 +30,9 @@ class TestServiceItem(TestCase):
|
||||
"""
|
||||
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)
|
||||
Registry().register(u'image_manager', MagicMock())
|
||||
|
||||
def serviceitem_basic_test(self):
|
||||
"""
|
||||
|
@ -60,7 +60,7 @@ class TestStartTimeDialog(TestCase):
|
||||
self.form.item = {u'service_item': mocked_serviceitem}
|
||||
with patch(u'PyQt4.QtGui.QDialog') as mocked_exec:
|
||||
self.form.exec_()
|
||||
okWidget = self.form.buttonBox.button(self.form.buttonBox.Ok)
|
||||
okWidget = self.form.button_box.button(self.form.button_box.Ok)
|
||||
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
||||
|
||||
# THEN the following input values are returned
|
||||
@ -75,7 +75,7 @@ class TestStartTimeDialog(TestCase):
|
||||
self.form.exec_()
|
||||
self.form.minuteSpinBox.setValue(2)
|
||||
self.form.secondSpinBox.setValue(3)
|
||||
okWidget = self.form.buttonBox.button(self.form.buttonBox.Ok)
|
||||
okWidget = self.form.button_box.button(self.form.button_box.Ok)
|
||||
QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton)
|
||||
|
||||
# THEN the following values are returned
|
||||
|
Loading…
Reference in New Issue
Block a user