up to date with mlz
Change-Id: I205ccc9847771ebe5622a45792a4dbe8d8e02b82
This commit is contained in:
parent
37d28c9f35
commit
11d1ad546f
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user