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):
Raises
------
ValueError: if the entry is not found.
KeyError: if the entry is not found.
"""
for ds in self.data_source_bundles:
if ds.id == id:
return ds
raise ValueError(
raise KeyError(
"Requested data source {} but don't know how "
"to find it.".format(id))
......@@ -77,13 +77,13 @@ class BundleRegistryPlugin(Plugin):
Raises
------
ValueError: if the entry is not found.
KeyError: if the entry is not found.
"""
for kpic in self.kpi_calculator_bundles:
if kpic.id == id:
return kpic
raise ValueError(
raise KeyError(
"Requested kpi calculator {} but don't know how "
"to find it.".format(id))
......@@ -99,14 +99,14 @@ class BundleRegistryPlugin(Plugin):
Raises
------
ValueError: if the entry is not found.
KeyError: if the entry is not found.
"""
for mco in self.mco_bundles:
if mco.id == id:
return mco
raise ValueError("Requested MCO {} but don't know how "
"to find it.".format(id))
raise KeyError("Requested MCO {} but don't know how "
"to find it.".format(id))
def mco_parameter_factory_by_id(self, mco_id, parameter_id):
"""Retrieves the MCO parameter factory for a given MCO id and
......@@ -125,7 +125,7 @@ class BundleRegistryPlugin(Plugin):
Raises
------
ValueError:
KeyError:
if the entry is not found
"""
mco_bundle = self.mco_bundle_by_id(mco_id)
......@@ -134,5 +134,5 @@ class BundleRegistryPlugin(Plugin):
if factory.id == parameter_id:
return factory
raise ValueError("Requested MCO parameter {}:{} but don't know"
" how to find it.".format(mco_id, parameter_id))
raise KeyError("Requested MCO parameter {}:{} but don't know"
" how to find it.".format(mco_id, parameter_id))
......@@ -89,6 +89,31 @@ class TestBundleRegistryWithContent(unittest.TestCase):
self.assertEqual(self.plugin.kpi_calculator_bundle_by_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__':
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