issues with StructOf

- depending whether client or server side, handling of optional is different
- fix issues when struct is used as keyworded command arguments

Change-Id: I72b347b1a96ee3bce1f67dace4862c313c12c7a9
Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/30972
Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
This commit is contained in:
2023-04-13 16:06:56 +02:00
parent d6d564f4aa
commit 6c02f37bbb
4 changed files with 73 additions and 33 deletions

View File

@ -23,10 +23,10 @@
import random
from frappy.datatypes import FloatRange, StringType, ValueType
from frappy.modules import Communicator, Drivable, Parameter, Property, \
Readable
from frappy.datatypes import FloatRange, StringType, ValueType, TupleOf, StructOf, ArrayOf
from frappy.modules import Communicator, Drivable, Parameter, Property, Readable, Module
from frappy.params import Command
from frappy.errors import RangeError
class LN2(Readable):
@ -95,9 +95,36 @@ class Lower(Communicator):
"""lowercase a string"""
return str(command).lower()
class Mapped(Readable):
value = Parameter(datatype=StringType())
choices = Property('List of choices',
datatype=ValueType(list))
def read_value(self):
return self.choices[random.randrange(len(self.choices))]
class Commands(Module):
"""Command argument tests"""
@Command(argument=TupleOf(FloatRange(0, 1), StringType()), result=StringType())
def t(self, f, s):
"""a command with positional arguments (tuple)"""
return '%g %r' % (f, s)
@Command(argument=StructOf(a=FloatRange(0, 1), b=StringType()), result=StringType())
def s(self, a=0, b=''):
"""a command with keyword arguments (struct)"""
return 'a=%r b=%r' % (a, b)
@Command(result=FloatRange(0, 1))
def n(self):
"""no args, but returning a value"""
return 2 # returning a value outside range should be allowed
@Command(argument=ArrayOf(FloatRange()))
def a(self, a):
"""array argument. raises an error when sum is negativ"""
if sum(a) < 0:
raise RangeError('sum must be >= 0')