up to date with mlz

Change-Id: I205ccc9847771ebe5622a45792a4dbe8d8e02b82
This commit is contained in:
zolliker 2023-05-31 14:29:25 +02:00
parent 37d28c9f35
commit 11d1ad546f

View File

@ -23,10 +23,10 @@
import random import random
from frappy.datatypes import FloatRange, StringType, ValueType from frappy.datatypes import FloatRange, StringType, ValueType, TupleOf, StructOf, ArrayOf
from frappy.modules import Communicator, Drivable, Parameter, Property, \ from frappy.modules import Communicator, Drivable, Parameter, Property, Readable, Module
Readable
from frappy.params import Command from frappy.params import Command
from frappy.errors import RangeError
class LN2(Readable): class LN2(Readable):
@ -95,9 +95,36 @@ class Lower(Communicator):
"""lowercase a string""" """lowercase a string"""
return str(command).lower() return str(command).lower()
class Mapped(Readable): class Mapped(Readable):
value = Parameter(datatype=StringType()) value = Parameter(datatype=StringType())
choices = Property('List of choices', choices = Property('List of choices',
datatype=ValueType(list)) datatype=ValueType(list))
def read_value(self): def read_value(self):
return self.choices[random.randrange(len(self.choices))] 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')