core: better command handling
* check argument of do * automatically set optional struct members from function signature Change-Id: I95684f1826c1318ea92fad2bd4c9681d85ea72f5 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32501 Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de> Reviewed-by: Alexander Zaft <a.zaft@fz-juelich.de>
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
# no fixtures needed
|
||||
import pytest
|
||||
|
||||
from frappy.datatypes import BoolType, FloatRange, IntRange
|
||||
from frappy.datatypes import BoolType, FloatRange, IntRange, StructOf
|
||||
from frappy.errors import ProgrammingError
|
||||
from frappy.modules import HasAccessibles
|
||||
from frappy.params import Command, Parameter
|
||||
@ -57,6 +57,29 @@ def test_Command():
|
||||
'description': 'do some other thing'}
|
||||
|
||||
|
||||
def test_cmd_struct_opt():
|
||||
with pytest.raises(ProgrammingError):
|
||||
class WrongName(HasAccessibles): # pylint: disable=unused-variable
|
||||
@Command(StructOf(a=IntRange(), b=IntRange()))
|
||||
def cmd(self, a, c):
|
||||
pass
|
||||
class Mod(HasAccessibles):
|
||||
@Command(StructOf(a=IntRange(), b=IntRange()))
|
||||
def cmd(self, a=5, b=5):
|
||||
pass
|
||||
assert Mod.cmd.datatype.argument.optional == ['a', 'b']
|
||||
class Mod2(HasAccessibles):
|
||||
@Command(StructOf(a=IntRange(), b=IntRange()))
|
||||
def cmd(self, a, b=5):
|
||||
pass
|
||||
assert Mod2.cmd.datatype.argument.optional == ['b']
|
||||
class Mod3(HasAccessibles):
|
||||
@Command(StructOf(a=IntRange(), b=IntRange()))
|
||||
def cmd(self, a, b):
|
||||
pass
|
||||
assert Mod3.cmd.datatype.argument.optional == []
|
||||
|
||||
|
||||
def test_Parameter():
|
||||
class Mod(HasAccessibles):
|
||||
p1 = Parameter('desc1', datatype=FloatRange(), default=0)
|
||||
|
Reference in New Issue
Block a user