better test with valid_enum and number

This commit is contained in:
2020-05-26 15:41:17 +02:00
parent dfa0b5678b
commit 2e0e17705b
5 changed files with 49 additions and 6 deletions

View File

@ -75,6 +75,7 @@ KEY_TYPE = {'variable': 'symlink',
TYPE_PARAM_CHECK = ('string', 'python', 'eole', 'variable')
TYPE_PARAM_CONDITION = ('string', 'python', 'number', 'eole', 'variable')
TYPE_PARAM_FILL = ('string', 'eole', 'number', 'context', 'variable')
CONVERSION = {'number': int}
ERASED_FAMILY_ACTION_ATTRIBUTES = ('index', 'action')
@ -685,7 +686,13 @@ class SpaceAnnotator(object):
choices = []
for value in values:
choice = self.objectspace.choice()
choice.name = str(value)
try:
if type_ in CONVERSION:
choice.name = CONVERSION[type_](value)
else:
choice.name = str(value)
except:
raise CreoleDictConsistencyError(_(f'unable to change type of a valid_enum entry "{value}" is not a valid "{type_}" for "{variable.name}"'))
choices.append(choice.name)
choice.type = type_
variable.choice.append(choice)
@ -694,7 +701,11 @@ class SpaceAnnotator(object):
if hasattr(variable, 'value'):
for value in variable.value:
value.type = type_
if value.name not in choices:
if type_ in CONVERSION:
cvalue = CONVERSION[type_](value.name)
else:
cvalue = value.name
if cvalue not in choices:
raise CreoleDictConsistencyError(_('value "{}" of variable "{}" is not in list of all expected values ({})').format(value.name, variable.name, choices))
else:
new_value = self.objectspace.value()

View File

@ -44,8 +44,8 @@ mo_location = LOCALE_DIR
gettext.find(APP_NAME, mo_location)
gettext.textdomain(APP_NAME)
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
gettext.translation(APP_NAME, fallback=True)
#gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
#gettext.translation(APP_NAME, fallback=True)
t = gettext.translation(APP_NAME, fallback=True)