check for bad read_* and write_* methods

raise a ProgrammingError when a read_<param> or write_<param>
method is defined, but <param> is no parameter.

Change-Id: Iae4e617d078229182a90b202a6f81ebc49050118
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/27386
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
zolliker 2022-01-06 17:35:32 +01:00
parent 8f7fb1e45b
commit 9b38db7706
2 changed files with 28 additions and 2 deletions

View File

@ -176,11 +176,17 @@ class HasAccessibles(HasProperties):
setattr(cls, 'write_' + pname, wrapped_wfunc)
wrapped_wfunc.__wrapped__ = True
# check information about Command's
# check for programming errors
for attrname in cls.__dict__:
if attrname.startswith('do_'):
prefix, _, pname = attrname.partition('_')
if not pname:
continue
if prefix == 'do':
raise ProgrammingError('%r: old style command %r not supported anymore'
% (cls.__name__, attrname))
if prefix in ('read', 'write') and not isinstance(accessibles.get(pname), Parameter):
raise ProgrammingError('%s.%s defined, but %r is no parameter'
% (cls.__name__, attrname, pname))
res = {}
# collect info about properties

View File

@ -458,3 +458,23 @@ def test_command_none():
assert 'stop' in Mod('o', logger, {'description': ''}, srv).accessibles
assert 'stop' not in Mod2('o', logger, {'description': ''}, srv).accessibles
def test_bad_method():
class Mod0(Drivable): # pylint: disable=unused-variable
def write_target(self, value):
pass
with pytest.raises(ProgrammingError):
class Mod1(Drivable): # pylint: disable=unused-variable
def write_taget(self, value):
pass
class Mod2(Drivable): # pylint: disable=unused-variable
def read_value(self, value):
pass
with pytest.raises(ProgrammingError):
class Mod3(Drivable): # pylint: disable=unused-variable
def read_valu(self, value):
pass