From e256ff86876667e4b7d9ceefcde2595a21bb0d34 Mon Sep 17 00:00:00 2001 From: Marco Clemencic <marco.clemencic@cern.ch> Date: Tue, 12 Sep 2023 19:10:38 +0200 Subject: [PATCH] Fix report of property name in exceptions for sequence and mapping semantics --- .../python/GaudiConfig2/semantics.py | 32 ++++++++++++++++++- .../tests/python/test_error_conditions.py | 11 ++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/GaudiConfiguration/python/GaudiConfig2/semantics.py b/GaudiConfiguration/python/GaudiConfig2/semantics.py index 137feab28f..576851d7da 100644 --- a/GaudiConfiguration/python/GaudiConfig2/semantics.py +++ b/GaudiConfiguration/python/GaudiConfig2/semantics.py @@ -28,9 +28,17 @@ class PropertySemantics(object): __handled_types__ = () def __init__(self, cpp_type, name=None): - self.name = None + self._name = name self.cpp_type = cpp_type + @property + def name(self): + return self._name + + @name.setter + def name(self, value): + self._name = value + @property def cpp_type(self): return self._cpp_type @@ -341,6 +349,16 @@ class SequenceSemantics(PropertySemantics): self.value_semantics = valueSem or getSemanticsFor( 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): new_value = _ListHelper(self.value_semantics) @@ -464,7 +482,19 @@ class MappingSemantics(PropertySemantics): super(MappingSemantics, self).__init__(cpp_type, name) template_args = list(extract_template_args(cpp_type)) self.key_semantics = getSemanticsFor(template_args[0]) + self.key_semantics.name = "{} key".format(name) 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): new_value = _DictHelper(self.key_semantics, self.value_semantics) diff --git a/GaudiConfiguration/tests/python/test_error_conditions.py b/GaudiConfiguration/tests/python/test_error_conditions.py index 123c069224..3e187023d3 100644 --- a/GaudiConfiguration/tests/python/test_error_conditions.py +++ b/GaudiConfiguration/tests/python/test_error_conditions.py @@ -12,8 +12,17 @@ import pytest def test_1(): - from GaudiConfig2.Configurables.TestConf import AlgWithVectors + from GaudiConfig2.Configurables.TestConf import AlgWithMaps, AlgWithVectors alg = AlgWithVectors() with pytest.raises(TypeError, match=r"cannot set property VS .*"): 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) -- GitLab