Skip to content

Commit

Permalink
GaudiConfig2: assign non-string to string property is TypeError (and …
Browse files Browse the repository at this point in the history
…not ValueError)
  • Loading branch information
pikacic committed Sep 12, 2023
1 parent 26958ad commit 0e96fb2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions GaudiConfiguration/python/GaudiConfig2/semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -171,7 +171,7 @@ def store(self, value):

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:
Expand Down
6 changes: 3 additions & 3 deletions GaudiConfiguration/tests/nose/test_mapping_semantics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#####################################################################################
# (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". #
Expand Down Expand Up @@ -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"})
Expand Down
8 changes: 4 additions & 4 deletions GaudiConfiguration/tests/nose/test_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -50,7 +50,7 @@ def test_semantics_delegation():
assert p.AStringProp == "something"


@raises(ValueError)
@raises(TypeError)
def test_semantics_delegation_bad():
MyAlg(AStringProp=123)

Expand All @@ -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"

Expand Down

0 comments on commit 0e96fb2

Please sign in to comment.