Skip to content
Snippets Groups Projects
Commit 672c80ae authored by Rosen Matev's avatar Rosen Matev :sunny:
Browse files

Handle incompatible values for DataObjectHandleBase props

Fixes gaudi/Gaudi#22
parent 2ca77dcb
No related branches found
Tags v52r0
No related merge requests found
Pipeline #
...@@ -393,6 +393,9 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy): ...@@ -393,6 +393,9 @@ class DataObjectHandleBasePropertyProxy(PropertyProxy):
return DataObjectHandleBase(value) return DataObjectHandleBase(value)
elif isinstance(value, DataObjectHandleBase): elif isinstance(value, DataObjectHandleBase):
return DataObjectHandleBase(value.__str__()) 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): def PropertyProxyFactory(descr, doc, default):
......
# Prepare dummy configurables # Prepare dummy configurables
from GaudiKernel.Configurable import ConfigurableAlgorithm, Configurable from GaudiKernel.Configurable import ConfigurableAlgorithm, Configurable
from GaudiKernel.DataObjectHandleBase import DataObjectHandleBase
class MyAlg(ConfigurableAlgorithm): class MyAlg(ConfigurableAlgorithm):
__slots__ = {'Text': 'some text', __slots__ = {'Text': 'some text',
'Int': 23} 'Int': 23,
'DataHandle': DataObjectHandleBase('Location')}
def getDlls(self): def getDlls(self):
return 'Dummy' return 'Dummy'
...@@ -26,7 +28,10 @@ def test_correct(): ...@@ -26,7 +28,10 @@ def test_correct():
a = MyAlg() a = MyAlg()
a.Int = 42 a.Int = 42
a.Text = 'value' 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(): def test_invalid_value():
...@@ -53,6 +58,17 @@ def test_invalid_value(): ...@@ -53,6 +58,17 @@ def test_invalid_value():
assert False, 'ValueError exception expected, got %s' % type( assert False, 'ValueError exception expected, got %s' % type(
x).__name__ 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(): def test_invalid_key():
a = MyAlg() a = MyAlg()
......
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