From f6ecadc9ac1e541d68146a98f7d428759e3e72bb Mon Sep 17 00:00:00 2001 From: Marco Clemencic <marco.clemencic@cern.ch> Date: Thu, 12 Apr 2018 14:14:17 +0000 Subject: [PATCH] Handle incompatible values for DataObjectHandleBase props (mr !650) Closes #22 (cherry picked from commit 2106633f967ddde1e1cf48d9d7f4dca2f7b5dd56) 672c80ae Handle incompatible values for DataObjectHandleBase props --- .../python/GaudiKernel/PropertyProxy.py | 3 +++ GaudiKernel/tests/nose/test_Configurables.py | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/GaudiKernel/python/GaudiKernel/PropertyProxy.py b/GaudiKernel/python/GaudiKernel/PropertyProxy.py index aa2477e15e..935dd4bc04 100644 --- a/GaudiKernel/python/GaudiKernel/PropertyProxy.py +++ b/GaudiKernel/python/GaudiKernel/PropertyProxy.py @@ -385,6 +385,9 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy): return DataObjectHandleBase(value) elif isinstance(value, DataObjectHandleBase): return DataObjectHandleBase(value.__str__()) + else: + raise ValueError("received an instance of %s, but %s expected" % + (type(value), 'str or DataObjectHandleBase')) def PropertyProxyFactory(descr, doc, default): diff --git a/GaudiKernel/tests/nose/test_Configurables.py b/GaudiKernel/tests/nose/test_Configurables.py index 9ea4cd18bd..a9a4c0341a 100644 --- a/GaudiKernel/tests/nose/test_Configurables.py +++ b/GaudiKernel/tests/nose/test_Configurables.py @@ -1,10 +1,12 @@ # Prepare dummy configurables from GaudiKernel.Configurable import ConfigurableAlgorithm, Configurable +from GaudiKernel.DataObjectHandleBase import DataObjectHandleBase class MyAlg(ConfigurableAlgorithm): __slots__ = {'Text': 'some text', - 'Int': 23} + 'Int': 23, + 'DataHandle': DataObjectHandleBase('Location')} def getDlls(self): return 'Dummy' @@ -26,7 +28,10 @@ def test_correct(): a = MyAlg() a.Int = 42 a.Text = 'value' - assert a.getValuedProperties() == {'Int': 42, 'Text': 'value'} + a.DataHandle = '/Event/X' + assert a.getValuedProperties() == { + 'Int': 42, 'Text': 'value', + 'DataHandle': DataObjectHandleBase('/Event/X')} def test_invalid_value(): @@ -53,6 +58,17 @@ def test_invalid_value(): assert False, 'ValueError exception expected, got %s' % type( x).__name__ + try: + a.DataHandle = [123] + assert False, 'exception expected' + except AssertionError: + raise + except ValueError: + pass + except Exception, x: + assert False, 'ValueError exception expected, got %s' % type( + x).__name__ + def test_invalid_key(): a = MyAlg() -- GitLab