Skip to content
Snippets Groups Projects
Commit ea1795f3 authored by Jan David Mol's avatar Jan David Mol
Browse files

Merge branch 'L2SS-1437_raise_exceptions_instead_of_None' into 'master'

L2SS-1437: Hiearchy_device raise exceptions upon error

Closes L2SS-1437

See merge request !688
parents f3250fb3 ed368c7b
No related branches found
No related tags found
1 merge request!688L2SS-1437: Hiearchy_device raise exceptions upon error
...@@ -410,7 +410,7 @@ class AbstractHierarchyDevice: ...@@ -410,7 +410,7 @@ class AbstractHierarchyDevice:
if self._parent: if self._parent:
return self._parent.dev_name().casefold() return self._parent.dev_name().casefold()
return None raise NotFoundException(f"Could not find parent for {self}")
def read_parent_attribute(self, attribute: str) -> any: def read_parent_attribute(self, attribute: str) -> any:
"""Allow to read attribute from parent without direct access """Allow to read attribute from parent without direct access
...@@ -420,7 +420,7 @@ class AbstractHierarchyDevice: ...@@ -420,7 +420,7 @@ class AbstractHierarchyDevice:
:raises tango.DevFailed: The exception from the DeviceProxy if raised :raises tango.DevFailed: The exception from the DeviceProxy if raised
""" """
if not self._parent: if not self._parent:
return None raise NotFoundException(f"Could not find parent for {self}")
return getattr(self._parent, attribute) return getattr(self._parent, attribute)
...@@ -431,7 +431,7 @@ class AbstractHierarchyDevice: ...@@ -431,7 +431,7 @@ class AbstractHierarchyDevice:
:raises tango.DevFailed: The exception from the DeviceProxy if raised :raises tango.DevFailed: The exception from the DeviceProxy if raised
""" """
if not self._parent: if not self._parent:
return None raise NotFoundException(f"Could not find parent for {self}")
return self._parent.state() return self._parent.state()
......
...@@ -73,7 +73,7 @@ class TestHierarchyDevice(device_base.DeviceTestCase): ...@@ -73,7 +73,7 @@ class TestHierarchyDevice(device_base.DeviceTestCase):
self.assertEqual(None, test_hierarchy._parent) self.assertEqual(None, test_hierarchy._parent)
self.assertEqual({}, test_hierarchy.children()) self.assertEqual({}, test_hierarchy.children())
self.assertEqual(None, test_hierarchy.parent()) self.assertRaises(hierarchy_device.NotFoundException, test_hierarchy.parent)
def test_get_or_create_proxy_cache(self): def test_get_or_create_proxy_cache(self):
"""Test if get_or_create_proxy caches without duplicates""" """Test if get_or_create_proxy caches without duplicates"""
...@@ -124,7 +124,11 @@ class TestHierarchyDevice(device_base.DeviceTestCase): ...@@ -124,7 +124,11 @@ class TestHierarchyDevice(device_base.DeviceTestCase):
test = TestHierarchyDevice.ConcreteHierarchy() test = TestHierarchyDevice.ConcreteHierarchy()
test.init("TestDevice", self.TEST_PROPERTY_NAME) test.init("TestDevice", self.TEST_PROPERTY_NAME)
self.assertIsNone(test.read_parent_attribute("FPGA_firmware_version_R")) self.assertRaises(
hierarchy_device.NotFoundException,
test.read_parent_attribute,
"FPGA_firmware_version_R",
)
def test_parent_get_state(self): def test_parent_get_state(self):
"""Ensure that we can get parent state""" """Ensure that we can get parent state"""
...@@ -147,7 +151,7 @@ class TestHierarchyDevice(device_base.DeviceTestCase): ...@@ -147,7 +151,7 @@ class TestHierarchyDevice(device_base.DeviceTestCase):
test = TestHierarchyDevice.ConcreteHierarchy() test = TestHierarchyDevice.ConcreteHierarchy()
test.init("TestDevice", self.TEST_PROPERTY_NAME) test.init("TestDevice", self.TEST_PROPERTY_NAME)
self.assertIsNone(test.parent_state()) self.assertRaises(hierarchy_device.NotFoundException, test.parent_state)
def children_test_base( def children_test_base(
self, self,
...@@ -297,7 +301,10 @@ class TestHierarchyDevice(device_base.DeviceTestCase): ...@@ -297,7 +301,10 @@ class TestHierarchyDevice(device_base.DeviceTestCase):
mock_parent.dev_name.return_value = "stat/parent/1" mock_parent.dev_name.return_value = "stat/parent/1"
test_hierarchy._parents = [mock_parent] test_hierarchy._parents = [mock_parent]
try:
_ = test_hierarchy.parent() _ = test_hierarchy.parent()
except hierarchy_device.NotFoundException:
pass
TEST_CHILDREN_ROOT = ["stat/ccd/1", "stat/psoc/1", "stat/antennafield/1"] TEST_CHILDREN_ROOT = ["stat/ccd/1", "stat/psoc/1", "stat/antennafield/1"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment