From 796be752b7b6cffd80b7ebd851216afdbc72a57a Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 10 Nov 2021 17:54:31 +0100 Subject: [PATCH] fix command inheritance Command.ownProperties must be definead in __init__ + add test for this Change-Id: I283331be6439a49ec61d28f04869a5b44704236f Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/27104 Tested-by: Jenkins Automated Tests Reviewed-by: Enrico Faulhaber Reviewed-by: Markus Zolliker --- secop/params.py | 2 +- test/test_params.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/secop/params.py b/secop/params.py index 86e6bd0..6efebaa 100644 --- a/secop/params.py +++ b/secop/params.py @@ -364,6 +364,7 @@ class Command(Accessible): self.description = inspect.cleandoc(argument.__doc__) self.name = self.func.__name__ self._inherit = inherit # save for __set_name__ + self.ownProperties = self.propertyValues.copy() def __set_name__(self, owner, name): self.name = name @@ -372,7 +373,6 @@ class Command(Accessible): (owner.__name__, name)) self.datatype = CommandType(self.argument, self.result) - self.ownProperties = self.propertyValues.copy() if self.export is True: predefined_cls = PREDEFINED_ACCESSIBLES.get(name, None) if predefined_cls is Command: diff --git a/test/test_params.py b/test/test_params.py index ab9f6e3..091eb24 100644 --- a/test/test_params.py +++ b/test/test_params.py @@ -103,3 +103,30 @@ def test_Export(): class Mod(HasAccessibles): param = Parameter('description1', datatype=BoolType, default=False) assert Mod.param.export == '_param' + + +def test_Command_Inheritance(): + class Base(HasAccessibles): + @Command(BoolType(), visibility=2) + def cmd(self, arg): + """first""" + + class Sub(Base): + @Command(group='grp') + def cmd(self, arg): + """second""" + + class Sub2(Base): + @Command(FloatRange()) + def cmd(self, arg): + """third""" + + assert Sub.accessibles['cmd'].for_export() == { + 'description': 'second', 'group': 'grp', 'visibility': 2, + 'datainfo': {'type': 'command', 'argument': {'type': 'bool'}} + } + + assert Sub2.accessibles['cmd'].for_export() == { + 'description': 'third', 'visibility': 2, + 'datainfo': {'type': 'command', 'argument': {'type': 'double'}} + }