change to new visibility spec
+ visibiliy is no longer an EnumType, as this would break the specs Change-Id: I1197c82f31c33c210fdcda0b49a0c38027880d77 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/36088 Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de> Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch> Tested-by: Jenkins Automated Tests <pedersen+jenkins@frm2.tum.de>
This commit is contained in:
parent
9545cb4188
commit
e0bd84cc3b
@ -1238,6 +1238,16 @@ class OrType(DataType):
|
|||||||
raise WrongTypeError(f"Invalid Value, must conform to one of {', '.join(str(t) for t in self.types)}")
|
raise WrongTypeError(f"Invalid Value, must conform to one of {', '.join(str(t) for t in self.types)}")
|
||||||
|
|
||||||
|
|
||||||
|
LEGACY_VISIBILITY = {'user': 'www', 1: 'www', 'advanced': 'ww-', 2: 'ww-', 'expert': 'w--', 3: 'w--'}
|
||||||
|
|
||||||
|
|
||||||
|
def visibility_validator(value):
|
||||||
|
value = LEGACY_VISIBILITY.get(value, value)
|
||||||
|
if len(value) == 3 and set(value) <= set('wr-'):
|
||||||
|
return value
|
||||||
|
raise RangeError(f'{value!r} is not a valid visibility')
|
||||||
|
|
||||||
|
|
||||||
Int8 = IntRange(-(1 << 7), (1 << 7) - 1)
|
Int8 = IntRange(-(1 << 7), (1 << 7) - 1)
|
||||||
Int16 = IntRange(-(1 << 15), (1 << 15) - 1)
|
Int16 = IntRange(-(1 << 15), (1 << 15) - 1)
|
||||||
Int32 = IntRange(-(1 << 31), (1 << 31) - 1)
|
Int32 = IntRange(-(1 << 31), (1 << 31) - 1)
|
||||||
|
@ -27,9 +27,9 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from frappy.datatypes import ArrayOf, BoolType, EnumType, FloatRange, \
|
from frappy.datatypes import ArrayOf, BoolType, FloatRange, IntRange, NoneOr, \
|
||||||
IntRange, StringType, TextType, TupleOf, \
|
StringType, TextType, TupleOf, ValueType, visibility_validator
|
||||||
NoneOr
|
|
||||||
from frappy.errors import BadValueError, CommunicationFailedError, ConfigError, \
|
from frappy.errors import BadValueError, CommunicationFailedError, ConfigError, \
|
||||||
ProgrammingError, SECoPError, secop_error, RangeError
|
ProgrammingError, SECoPError, secop_error, RangeError
|
||||||
from frappy.lib import formatException, mkthread, UniqueObject
|
from frappy.lib import formatException, mkthread, UniqueObject
|
||||||
@ -306,8 +306,8 @@ class Module(HasAccessibles):
|
|||||||
description = Property('description of the module', TextType(), extname='description', mandatory=True)
|
description = Property('description of the module', TextType(), extname='description', mandatory=True)
|
||||||
meaning = Property('optional meaning indicator', TupleOf(StringType(), IntRange(0, 50)),
|
meaning = Property('optional meaning indicator', TupleOf(StringType(), IntRange(0, 50)),
|
||||||
default=('', 0), extname='meaning')
|
default=('', 0), extname='meaning')
|
||||||
visibility = Property('optional visibility hint', EnumType('visibility', user=1, advanced=2, expert=3),
|
visibility = Property('optional visibility hint', ValueType(visibility_validator),
|
||||||
default='user', extname='visibility')
|
default='www', extname='visibility')
|
||||||
implementation = Property('internal name of the implementation class of the module', StringType(),
|
implementation = Property('internal name of the implementation class of the module', StringType(),
|
||||||
extname='implementation')
|
extname='implementation')
|
||||||
interface_classes = Property('offical highest interface-class of the module', ArrayOf(StringType()),
|
interface_classes = Property('offical highest interface-class of the module', ArrayOf(StringType()),
|
||||||
|
@ -26,7 +26,7 @@ import inspect
|
|||||||
|
|
||||||
from frappy.datatypes import ArrayOf, BoolType, CommandType, DataType, \
|
from frappy.datatypes import ArrayOf, BoolType, CommandType, DataType, \
|
||||||
DataTypeType, EnumType, FloatRange, NoneOr, OrType, StringType, StructOf, \
|
DataTypeType, EnumType, FloatRange, NoneOr, OrType, StringType, StructOf, \
|
||||||
TextType, TupleOf, ValueType
|
TextType, TupleOf, ValueType, visibility_validator
|
||||||
from frappy.errors import BadValueError, ProgrammingError, WrongTypeError
|
from frappy.errors import BadValueError, ProgrammingError, WrongTypeError
|
||||||
from frappy.lib import generalConfig
|
from frappy.lib import generalConfig
|
||||||
from frappy.properties import HasProperties, Property
|
from frappy.properties import HasProperties, Property
|
||||||
@ -152,8 +152,8 @@ class Parameter(Accessible):
|
|||||||
'optional parameter group this parameter belongs to', StringType(),
|
'optional parameter group this parameter belongs to', StringType(),
|
||||||
extname='group', default='')
|
extname='group', default='')
|
||||||
visibility = Property(
|
visibility = Property(
|
||||||
'optional visibility hint', EnumType('visibility', user=1, advanced=2, expert=3),
|
'optional visibility hint', ValueType(visibility_validator),
|
||||||
extname='visibility', default=1)
|
extname='visibility', default='www')
|
||||||
constant = Property(
|
constant = Property(
|
||||||
'optional constant value for constant parameters', ValueType(),
|
'optional constant value for constant parameters', ValueType(),
|
||||||
extname='constant', default=None)
|
extname='constant', default=None)
|
||||||
@ -367,8 +367,8 @@ class Command(Accessible):
|
|||||||
'optional command group of the command.', StringType(),
|
'optional command group of the command.', StringType(),
|
||||||
extname='group', export=True, default='')
|
extname='group', export=True, default='')
|
||||||
visibility = Property(
|
visibility = Property(
|
||||||
'optional visibility hint', EnumType('visibility', user=1, advanced=2, expert=3),
|
'optional visibility hint', ValueType(visibility_validator),
|
||||||
extname='visibility', export=True, default=1)
|
extname='visibility', export=True, default='www')
|
||||||
export = Property(
|
export = Property(
|
||||||
'''[internal] export settings
|
'''[internal] export settings
|
||||||
|
|
||||||
|
@ -318,17 +318,17 @@ def test_command_inheritance():
|
|||||||
"""third"""
|
"""third"""
|
||||||
|
|
||||||
assert Sub1.accessibles['cmd'].for_export() == {
|
assert Sub1.accessibles['cmd'].for_export() == {
|
||||||
'description': 'first', 'group': 'grp', 'visibility': 2,
|
'description': 'first', 'group': 'grp', 'visibility': 'ww-',
|
||||||
'datainfo': {'type': 'command', 'argument': {'type': 'bool'}}
|
'datainfo': {'type': 'command', 'argument': {'type': 'bool'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert Sub2.accessibles['cmd'].for_export() == {
|
assert Sub2.accessibles['cmd'].for_export() == {
|
||||||
'description': 'second', 'group': 'grp', 'visibility': 2,
|
'description': 'second', 'group': 'grp', 'visibility': 'ww-',
|
||||||
'datainfo': {'type': 'command', 'result': {'type': 'bool'}}
|
'datainfo': {'type': 'command', 'result': {'type': 'bool'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert Sub3.accessibles['cmd'].for_export() == {
|
assert Sub3.accessibles['cmd'].for_export() == {
|
||||||
'description': 'third', 'visibility': 2,
|
'description': 'third', 'visibility': 'ww-',
|
||||||
'datainfo': {'type': 'command', 'result': {'type': 'double'}}
|
'datainfo': {'type': 'command', 'result': {'type': 'double'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ def test_command_check():
|
|||||||
'cmd': {'argument': {'type': 'double', 'min': 1, 'max': 0}},
|
'cmd': {'argument': {'type': 'double', 'min': 1, 'max': 0}},
|
||||||
}, srv)
|
}, srv)
|
||||||
|
|
||||||
with pytest.raises(ProgrammingError):
|
with pytest.raises(ConfigError):
|
||||||
BadDatatype('o', logger, {
|
BadDatatype('o', logger, {
|
||||||
'description': '',
|
'description': '',
|
||||||
'cmd': {'visibility': 'invalid'},
|
'cmd': {'visibility': 'invalid'},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user