add more tests and fixes for command inheritance

- fix CommandType.__repr__
- secop/modules.py: command properties are allowed to be configured:
   - section 2: remove comment and rename
   - section 3: all accessible properties should be checked
- command description should be inherited also when taken from docstring
- move test for command inheritance to test_modules.py
- added tests to check for valid properties of commands

Change-Id: I5fd04e03be1faec5e54fed9735620bc5dc0f89c0
This commit is contained in:
2021-11-12 17:07:11 +01:00
parent 9058ef054b
commit 1d9e07edb4
5 changed files with 157 additions and 24 deletions

View File

@ -346,6 +346,9 @@ class Command(Accessible):
def __init__(self, argument=False, *, result=None, inherit=True, **kwds):
super().__init__()
if 'datatype' in kwds:
# self.init will complain about invalid keywords except 'datatype', as this is a property
raise ProgrammingError("Command() got an invalid keyword 'datatype'")
self.init(kwds)
if result or kwds or isinstance(argument, DataType) or not callable(argument):
# normal case
@ -362,7 +365,7 @@ class Command(Accessible):
self.func = argument # this is the wrapped method!
if argument.__doc__:
self.description = inspect.cleandoc(argument.__doc__)
self.name = self.func.__name__
self.name = self.func.__name__ # this is probably not needed
self._inherit = inherit # save for __set_name__
def __set_name__(self, owner, name):
@ -397,6 +400,7 @@ class Command(Accessible):
"""called when used as decorator"""
if 'description' not in self.propertyValues and func.__doc__:
self.description = inspect.cleandoc(func.__doc__)
self.ownProperties['description'] = self.description
self.func = func
return self