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

GaudiConfig2: assign non-string to string property is TypeError (and not ValueError)

parent 26958ad5
No related branches found
No related tags found
1 merge request!1468Fix missing Property name in error messages
......@@ -121,7 +121,7 @@ class StringSemantics(PropertySemantics):
def store(self, value):
if not isinstance(value, str):
raise ValueError("cannot set property {} to {!r}".format(self.name, value))
raise TypeError("cannot set property {} to {!r}".format(self.name, value))
return value
......@@ -171,7 +171,7 @@ class IntSemantics(PropertySemantics):
if not isinstance(value, Number):
raise TypeError(
"number expected, got {!r} in assignemnt to {}".format(value, self.name)
"number expected, got {!r} in assignment to {}".format(value, self.name)
)
v = int(value)
if v != value:
......
#####################################################################################
# (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations #
# (c) Copyright 1998-2023 CERN for the benefit of the LHCb and ATLAS collaborations #
# #
# This software is distributed under the terms of the Apache version 2 licence, #
# copied verbatim in the file "LICENSE". #
......@@ -95,13 +95,13 @@ def test_access():
assert d.get("q", "Q") == "Q"
@raises(ValueError)
@raises(TypeError)
def test_assignment_bad_value():
s = S.getSemanticsFor("std::map<std::string, std::string>")
s.store({"a": "A", "b": "B", "c": 1})
@raises(ValueError)
@raises(TypeError)
def test_assignment_bad_key():
s = S.getSemanticsFor("std::map<std::string, std::string>")
s.store({"a": "A", "b": "B", 1: "C"})
......
......@@ -39,7 +39,7 @@ def test_string_ok():
assert s.store("something") == "something"
@raises(ValueError)
@raises(TypeError)
def test_string_bad():
getSemanticsFor("std::string").store(123)
......@@ -50,7 +50,7 @@ def test_semantics_delegation():
assert p.AStringProp == "something"
@raises(ValueError)
@raises(TypeError)
def test_semantics_delegation_bad():
MyAlg(AStringProp=123)
......@@ -61,8 +61,8 @@ def test_no_change_after_exception():
assert p.AStringProp == "something"
try:
p.AStringProp = 123
assert False, "ValueError expected"
except ValueError:
assert False, "TypeError expected"
except TypeError:
pass
assert p.AStringProp == "something"
......
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