diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index f69eeb3a6..a30ed4ba3 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -64,7 +64,7 @@ class Registry(object): return self.service_list[key] else: log.error(u'Service %s not found in list' % key) - return None + raise KeyError(u'Service %s not found in list' % key) def register(self, key, reference): """ @@ -72,6 +72,6 @@ class Registry(object): """ if key in self.service_list: log.error(u'Duplicate service exception %s' % key) - raise Exception(u'Duplicate service exception %s' % key) + raise KeyError(u'Duplicate service exception %s' % key) else: self.service_list[key] = reference diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index b9729ace1..16d0de52a 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -9,7 +9,7 @@ from openlp.core.lib import Registry TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) -class TestServiceItem(TestCase): +class TestRegistry(TestCase): def registry_basic_test(self): """ @@ -25,17 +25,14 @@ class TestServiceItem(TestCase): # THEN: we should be able retrieve the saved object assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches' - # WHEN: I add a service it should save it a second time + # WHEN: I add a service for the second time I am mad. # THEN I will get an exception - try: + with self.assertRaises(KeyError) as context: Registry().register(u'test1', mock_1) - except Exception, e: - pass - + self.assertEqual(context.exception[0], u'Duplicate service exception test1') # WHEN I try to get back a non existent service # THEN I will get an exception - try: - assert Registry().get(u'test2') == mock_1, u'This should not be fired' - except Exception, e: - pass \ No newline at end of file + with self.assertRaises(KeyError) as context: + temp = Registry().get(u'test2') + self.assertEqual(context.exception[0], u'Service test2 not found in list') \ No newline at end of file