simple possiblity for overriding properties

When a class attribute is assigned with the same name as a property
from an inherited class, the property default is overridden.
If the type does not match, a ProgrammingError is raised.

Change-Id: Ifdab5c8bbdaae008370a9b297c770f5c04db9311
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/21989
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
This commit is contained in:
2019-12-10 17:25:57 +01:00
parent 1521e0a34b
commit f5af074015
2 changed files with 53 additions and 7 deletions

View File

@ -114,6 +114,36 @@ def test_Property_checks():
o.checkProperties()
o = cl()
o.checkProperties()
# test for min/max check
o.setProperty('maxabc', 1)
with pytest.raises(ConfigError):
o.checkProperties()
def test_Property_override():
o1 = c()
class co(c):
a = 3
o2 = co()
assert o1.a == 1
assert o2.a == 3
with pytest.raises(ProgrammingError) as e:
class cx(c): # pylint: disable=unused-variable
def a(self):
pass
assert 'collides with method' in str(e.value)
with pytest.raises(ProgrammingError) as e:
class cy(c): # pylint: disable=unused-variable
properties = {
'b' : Property('', FloatRange(), 3.14),
}
b = 1.5
assert 'name collision with property' in str(e.value)
with pytest.raises(ProgrammingError) as e:
class cz(c): # pylint: disable=unused-variable
a = 's'
assert 'can not be set to' in str(e.value)