valid_entier (with mini or maxi parameter) configure min_number or max_number for IntOption
This commit is contained in:
parent
331e386470
commit
2742774aa9
8 changed files with 54 additions and 37 deletions
|
@ -68,6 +68,7 @@ PROPERTIES = ('hidden', 'frozen', 'auto_freeze', 'auto_save', 'force_default_on_
|
|||
CONVERT_PROPERTIES = {'auto_save': ['force_store_value'], 'auto_freeze': ['force_store_value', 'auto_freeze']}
|
||||
|
||||
RENAME_ATTIBUTES = {'description': 'doc'}
|
||||
INTERNAL_FUNCTIONS = ['valid_enum', 'valid_in_network', 'valid_differ', 'valid_entier']
|
||||
|
||||
class SpaceAnnotator:
|
||||
"""Transformations applied on a CreoleObjSpace instance
|
||||
|
@ -498,6 +499,10 @@ class VariableAnnotator:
|
|||
families.doc = families.name
|
||||
for family in families.family.values():
|
||||
family.doc = family.name
|
||||
for key, value in RENAME_ATTIBUTES.items():
|
||||
if hasattr(family, key):
|
||||
setattr(family, value, getattr(family, key))
|
||||
setattr(family, key, None)
|
||||
family.name = normalize_family(family.name)
|
||||
if hasattr(family, 'variable'):
|
||||
for variable in family.variable.values():
|
||||
|
@ -621,7 +626,7 @@ class ConstraintAnnotator:
|
|||
def check_check(self):
|
||||
remove_indexes = []
|
||||
functions = dir(self.eosfunc)
|
||||
functions.extend(['valid_enum', 'valid_in_network', 'valid_differ'])
|
||||
functions.extend(INTERNAL_FUNCTIONS)
|
||||
for check_idx, check in enumerate(self.objectspace.space.constraints.check):
|
||||
if not check.name in functions:
|
||||
raise DictConsistencyError(_('cannot find check function {}').format(check.name))
|
||||
|
@ -959,8 +964,22 @@ class ConstraintAnnotator:
|
|||
def convert_check(self):
|
||||
for check in self.objectspace.space.constraints.check:
|
||||
variable = self.objectspace.paths.get_variable_obj(check.target)
|
||||
check_ = self.objectspace.check()
|
||||
name = check.name
|
||||
if name == 'valid_entier':
|
||||
if not hasattr(check, 'param'):
|
||||
raise DictConsistencyError(_('{} must have, at least, 1 param').format(name))
|
||||
for param in check.param:
|
||||
if param.type not in ['string', 'number']:
|
||||
raise DictConsistencyError(_(f'param in "valid_entier" must not be a "{param.type}"'))
|
||||
if param.name == 'mini':
|
||||
variable.min_number = int(param.text)
|
||||
elif param.name == 'maxi':
|
||||
print('pppp', param.text)
|
||||
variable.max_number = int(param.text)
|
||||
else:
|
||||
raise DictConsistencyError(_(f'unknown parameter {param.text} in check "valid_entier" for variable {check.target}'))
|
||||
else:
|
||||
check_ = self.objectspace.check()
|
||||
if name == 'valid_differ':
|
||||
name = 'valid_not_equal'
|
||||
elif name == 'valid_network_netmask':
|
||||
|
|
|
@ -337,6 +337,8 @@ class Variable(Common):
|
|||
for key in self.get_attributes(self.elt):
|
||||
value = getattr(self.elt, key)
|
||||
if key in FORCE_INFORMATIONS:
|
||||
if key == 'test' and self.object_type == 'IntOption':
|
||||
value = int(value)
|
||||
self.informations[key] = value
|
||||
else:
|
||||
self.attrib[key] = value
|
||||
|
|
|
@ -24,10 +24,6 @@ def get_mount_point_device(*args, **kwargs):
|
|||
pass
|
||||
|
||||
|
||||
def valid_entier(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
def valid_differ(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from rougail.tiramisu import ConvertDynOptionDescription
|
|||
import imp
|
||||
func = imp.load_source('func', 'tests/flattener_dicos/../eosfunc/test.py')
|
||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='b')
|
||||
option_4 = IntOption(properties=frozenset({'normal'}), validators=[Calculation(func.valid_entier, Params((ParamSelfOption()), kwargs={'mini': ParamValue("0"), 'maxi': ParamValue("100")}), warnings_only=False)], name='int', doc='No change', multi=False)
|
||||
option_4 = IntOption(properties=frozenset({'normal'}), name='int', doc='No change', multi=False, max_number=100, min_number=0)
|
||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
</variables>
|
||||
|
||||
<constraints>
|
||||
<check name="valid_entier" target="int"/>
|
||||
<check name="valid_lower" target="int"/>
|
||||
</constraints>
|
||||
|
||||
<help/>
|
||||
|
|
|
@ -3,7 +3,7 @@ from rougail.tiramisu import ConvertDynOptionDescription
|
|||
import imp
|
||||
func = imp.load_source('func', 'tests/flattener_dicos/../eosfunc/test.py')
|
||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='b')
|
||||
option_4 = IntOption(properties=frozenset({'normal'}), validators=[Calculation(func.valid_entier, Params((ParamSelfOption()), kwargs={}), warnings_only=False)], name='int', doc='No change', multi=False)
|
||||
option_4 = IntOption(properties=frozenset({'normal'}), validators=[Calculation(func.valid_lower, Params((ParamSelfOption()), kwargs={}), warnings_only=False)], name='int', doc='No change', multi=False)
|
||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</variables>
|
||||
|
||||
<constraints>
|
||||
<check name="valid_entier" target="int">
|
||||
<check name="valid_lower" target="int">
|
||||
<param name="mini">0</param>
|
||||
<param name="maxi" type="variable">int2</param>
|
||||
</check>
|
||||
|
|
|
@ -4,7 +4,7 @@ import imp
|
|||
func = imp.load_source('func', 'tests/flattener_dicos/../eosfunc/test.py')
|
||||
option_3 = StrOption(properties=frozenset({'mandatory', 'normal'}), name='mode_conteneur_actif', doc='No change', multi=False, default='b')
|
||||
option_4 = IntOption(properties=frozenset({'mandatory', 'normal'}), name='int2', doc='No change', multi=False, default=100)
|
||||
option_5 = IntOption(properties=frozenset({'normal'}), validators=[Calculation(func.valid_entier, Params((ParamSelfOption()), kwargs={'mini': ParamValue("0"), 'maxi': ParamOption(option_4, notraisepropertyerror=False, todict=False)}), warnings_only=False)], name='int', doc='No change', multi=False)
|
||||
option_5 = IntOption(properties=frozenset({'normal'}), validators=[Calculation(func.valid_lower, Params((ParamSelfOption()), kwargs={'mini': ParamValue("0"), 'maxi': ParamOption(option_4, notraisepropertyerror=False, todict=False)}), warnings_only=False)], name='int', doc='No change', multi=False)
|
||||
option_2 = OptionDescription(name='general', doc='general', properties=frozenset({'normal'}), children=[option_3, option_4, option_5])
|
||||
option_1 = OptionDescription(name='rougail', doc='rougail', children=[option_2])
|
||||
option_0 = OptionDescription(name='baseoption', doc='baseoption', children=[option_1])
|
||||
|
|
Loading…
Reference in a new issue