Skip to content
Snippets Groups Projects
Commit e256ff86 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

Fix report of property name in exceptions for sequence and mapping semantics

parent ae35fe76
No related branches found
No related tags found
No related merge requests found
Pipeline #6187039 passed
...@@ -28,9 +28,17 @@ class PropertySemantics(object): ...@@ -28,9 +28,17 @@ class PropertySemantics(object):
__handled_types__ = () __handled_types__ = ()
def __init__(self, cpp_type, name=None): def __init__(self, cpp_type, name=None):
self.name = None self._name = name
self.cpp_type = cpp_type self.cpp_type = cpp_type
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
@property @property
def cpp_type(self): def cpp_type(self):
return self._cpp_type return self._cpp_type
...@@ -341,6 +349,16 @@ class SequenceSemantics(PropertySemantics): ...@@ -341,6 +349,16 @@ class SequenceSemantics(PropertySemantics):
self.value_semantics = valueSem or getSemanticsFor( self.value_semantics = valueSem or getSemanticsFor(
list(extract_template_args(cpp_type))[0] list(extract_template_args(cpp_type))[0]
) )
self.value_semantics.name = name
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
self.value_semantics.name = "{} element".format(self._name)
def store(self, value): def store(self, value):
new_value = _ListHelper(self.value_semantics) new_value = _ListHelper(self.value_semantics)
...@@ -464,7 +482,19 @@ class MappingSemantics(PropertySemantics): ...@@ -464,7 +482,19 @@ class MappingSemantics(PropertySemantics):
super(MappingSemantics, self).__init__(cpp_type, name) super(MappingSemantics, self).__init__(cpp_type, name)
template_args = list(extract_template_args(cpp_type)) template_args = list(extract_template_args(cpp_type))
self.key_semantics = getSemanticsFor(template_args[0]) self.key_semantics = getSemanticsFor(template_args[0])
self.key_semantics.name = "{} key".format(name)
self.value_semantics = getSemanticsFor(template_args[1]) self.value_semantics = getSemanticsFor(template_args[1])
self.value_semantics.name = "{} value".format(name)
@property
def name(self):
return self._name
@name.setter
def name(self, value):
self._name = value
self.key_semantics.name = "{} key".format(self._name)
self.value_semantics.name = "{} value".format(self._name)
def store(self, value): def store(self, value):
new_value = _DictHelper(self.key_semantics, self.value_semantics) new_value = _DictHelper(self.key_semantics, self.value_semantics)
......
...@@ -12,8 +12,17 @@ import pytest ...@@ -12,8 +12,17 @@ import pytest
def test_1(): def test_1():
from GaudiConfig2.Configurables.TestConf import AlgWithVectors from GaudiConfig2.Configurables.TestConf import AlgWithMaps, AlgWithVectors
alg = AlgWithVectors() alg = AlgWithVectors()
with pytest.raises(TypeError, match=r"cannot set property VS .*"): with pytest.raises(TypeError, match=r"cannot set property VS .*"):
alg.VS = [3] alg.VS = [3]
alg = AlgWithMaps()
with pytest.raises(TypeError, match=r"cannot set property MSS key .*"):
alg.MSS[3] = "value"
with pytest.raises(TypeError, match=r"cannot set property MSS value .*"):
alg.MSS["key"] = 3
alg.MIV[3] = []
with pytest.raises(TypeError, match=r"cannot set property MIV value element.*"):
alg.MIV[3].append(5)
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