Skip to content
Snippets Groups Projects
Commit ac2e65ac authored by Stefano Borini's avatar Stefano Borini
Browse files

Changed exception when not found

parent 6297b43e
No related branches found
No related tags found
1 merge request!60Moved parameters into MCO
...@@ -55,13 +55,13 @@ class BundleRegistryPlugin(Plugin): ...@@ -55,13 +55,13 @@ class BundleRegistryPlugin(Plugin):
Raises Raises
------ ------
ValueError: if the entry is not found. KeyError: if the entry is not found.
""" """
for ds in self.data_source_bundles: for ds in self.data_source_bundles:
if ds.id == id: if ds.id == id:
return ds return ds
raise ValueError( raise KeyError(
"Requested data source {} but don't know how " "Requested data source {} but don't know how "
"to find it.".format(id)) "to find it.".format(id))
...@@ -77,13 +77,13 @@ class BundleRegistryPlugin(Plugin): ...@@ -77,13 +77,13 @@ class BundleRegistryPlugin(Plugin):
Raises Raises
------ ------
ValueError: if the entry is not found. KeyError: if the entry is not found.
""" """
for kpic in self.kpi_calculator_bundles: for kpic in self.kpi_calculator_bundles:
if kpic.id == id: if kpic.id == id:
return kpic return kpic
raise ValueError( raise KeyError(
"Requested kpi calculator {} but don't know how " "Requested kpi calculator {} but don't know how "
"to find it.".format(id)) "to find it.".format(id))
...@@ -99,14 +99,14 @@ class BundleRegistryPlugin(Plugin): ...@@ -99,14 +99,14 @@ class BundleRegistryPlugin(Plugin):
Raises Raises
------ ------
ValueError: if the entry is not found. KeyError: if the entry is not found.
""" """
for mco in self.mco_bundles: for mco in self.mco_bundles:
if mco.id == id: if mco.id == id:
return mco return mco
raise ValueError("Requested MCO {} but don't know how " raise KeyError("Requested MCO {} but don't know how "
"to find it.".format(id)) "to find it.".format(id))
def mco_parameter_factory_by_id(self, mco_id, parameter_id): def mco_parameter_factory_by_id(self, mco_id, parameter_id):
"""Retrieves the MCO parameter factory for a given MCO id and """Retrieves the MCO parameter factory for a given MCO id and
...@@ -125,7 +125,7 @@ class BundleRegistryPlugin(Plugin): ...@@ -125,7 +125,7 @@ class BundleRegistryPlugin(Plugin):
Raises Raises
------ ------
ValueError: KeyError:
if the entry is not found if the entry is not found
""" """
mco_bundle = self.mco_bundle_by_id(mco_id) mco_bundle = self.mco_bundle_by_id(mco_id)
...@@ -134,5 +134,5 @@ class BundleRegistryPlugin(Plugin): ...@@ -134,5 +134,5 @@ class BundleRegistryPlugin(Plugin):
if factory.id == parameter_id: if factory.id == parameter_id:
return factory return factory
raise ValueError("Requested MCO parameter {}:{} but don't know" raise KeyError("Requested MCO parameter {}:{} but don't know"
" how to find it.".format(mco_id, parameter_id)) " how to find it.".format(mco_id, parameter_id))
...@@ -89,6 +89,31 @@ class TestBundleRegistryWithContent(unittest.TestCase): ...@@ -89,6 +89,31 @@ class TestBundleRegistryWithContent(unittest.TestCase):
self.assertEqual(self.plugin.kpi_calculator_bundle_by_id(id).id, self.assertEqual(self.plugin.kpi_calculator_bundle_by_id(id).id,
id) id)
with self.assertRaises(KeyError):
self.plugin.mco_bundle_by_id(
bundle_id("enthought", "foo"))
with self.assertRaises(KeyError):
self.plugin.mco_parameter_factory_by_id(
mco_id,
mco_parameter_id("enthought", "mco1", "foo")
)
with self.assertRaises(KeyError):
self.plugin.data_source_bundle_by_id(
bundle_id("enthought", "foo")
)
with self.assertRaises(KeyError):
self.plugin.data_source_bundle_by_id(
bundle_id("enthought", "foo")
)
with self.assertRaises(KeyError):
self.plugin.kpi_calculator_bundle_by_id(
bundle_id("enthought", "foo")
)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment