From ac2e65ac7c2f83a7fc256b540098c98663c3da53 Mon Sep 17 00:00:00 2001 From: Stefano Borini <sborini@enthought.com> Date: Mon, 31 Jul 2017 13:48:55 +0100 Subject: [PATCH] Changed exception when not found --- force_bdss/bundle_registry_plugin.py | 20 +++++++-------- .../tests/test_bundle_registry_plugin.py | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/force_bdss/bundle_registry_plugin.py b/force_bdss/bundle_registry_plugin.py index b4d100b..44e7d48 100644 --- a/force_bdss/bundle_registry_plugin.py +++ b/force_bdss/bundle_registry_plugin.py @@ -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)) diff --git a/force_bdss/tests/test_bundle_registry_plugin.py b/force_bdss/tests/test_bundle_registry_plugin.py index 4bed99e..3050087 100644 --- a/force_bdss/tests/test_bundle_registry_plugin.py +++ b/force_bdss/tests/test_bundle_registry_plugin.py @@ -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() -- GitLab