core: simplify test for methods names

The test for method names 'read_<param>' and 'write_<param>'
without a defined parameter is simplified. We do not check
anymore method names from base classes. Base classes
inheriting from HasAccessible are checked anyway at the
place they are defined.

+ add a test for it
+ move some tests to a new file test_all_modules.py, as
  test_modules.py is getting too long
+ fix missing doc string (frappy.simulation.SimDrivable.stop)

Change-Id: Id8a9afe5c977ae3b1371bd40c6da52be2fc79eb9
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/35503
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2025-01-29 09:00:08 +01:00
parent a43590a3ff
commit 4aec05c86b
5 changed files with 80 additions and 32 deletions

View File

@ -60,14 +60,12 @@ class HasAccessibles(HasProperties):
(so the dispatcher will get notified of changed values)
"""
isWrapped = False
checkedMethods = ()
@classmethod
def __init_subclass__(cls): # pylint: disable=too-many-branches
super().__init_subclass__()
if cls.isWrapped:
return
cls.checkedMethods = set(cls.checkedMethods) # might be initial empty tuple
# merge accessibles from all sub-classes, treat overrides
# for now, allow to use also the old syntax (parameters/commands dict)
accessibles = OrderedDict() # dict of accessibles
@ -200,16 +198,15 @@ class HasAccessibles(HasProperties):
new_wfunc.__module__ = cls.__module__
cls.wrappedAttributes[wname] = new_wfunc
cls.checkedMethods.update(cls.wrappedAttributes)
# check for programming errors
for attrname in cls.__dict__:
for attrname, func in cls.__dict__.items():
prefix, _, pname = attrname.partition('_')
if not pname:
continue
if prefix == 'do':
raise ProgrammingError(f'{cls.__name__!r}: old style command {attrname!r} not supported anymore')
if prefix in ('read', 'write') and attrname not in cls.checkedMethods:
if (prefix in ('read', 'write') and attrname not in cls.wrappedAttributes
and not hasattr(func, 'poll')): # may be a handler, which always has a poll attribute
raise ProgrammingError(f'{cls.__name__}.{attrname} defined, but {pname!r} is no parameter')
try:

View File

@ -102,9 +102,6 @@ class Handler:
"""create the wrapped read_* or write_* methods"""
# at this point, this 'method_names' entry is no longer used -> delete
self.method_names.discard((self.func.__module__, self.func.__qualname__))
# avoid complain about read_<name> or write_<name> method without parameter <name>
# can not use .add() here, as owner.checkedMethods might be an empty tuple
owner.checkedMethods = set(owner.checkedMethods) | {name}
for key in self.keys:
wrapped = self.wrap(key)
method_name = self.prefix + key

View File

@ -142,4 +142,5 @@ class SimDrivable(SimReadable, Drivable):
@Command
def stop(self):
"""set target to value"""
self.target = self.value