feat(#21): add examples attributes

This commit is contained in:
egarette@silique.fr 2024-08-29 08:34:51 +02:00 committed by gwen
parent a827ca2225
commit b21c13fea7

View file

@ -77,6 +77,7 @@ class Annotator(Walk): # pylint: disable=R0903
self.basic_types = {str: "string", int: "number", bool: "boolean", float: "float"}
self.convert_variable()
self.convert_test()
self.convert_examples()
self.convert_help()
self.verify_choices()
@ -105,6 +106,8 @@ class Annotator(Walk): # pylint: disable=R0903
# choice type inference from the `choices` attribute
if variable.choices is not None:
variable.type = "choice"
elif variable.regexp is not None:
variable.type = "regexp"
elif variable.default not in [None, []]:
if isinstance(variable.default, list):
tested_value = variable.default[0]
@ -143,8 +146,11 @@ class Annotator(Walk): # pylint: disable=R0903
variable.hidden = family.hidden
variable.hidden = None
if variable.choices is not None and variable.type != 'choice':
msg = _(f'the variable "{variable.path}" has choice attribut but has not the "choice" type')
msg = _(f'the variable "{variable.path}" has choices attribut but has not the "choice" type')
raise DictConsistencyError(msg, 11, variable.xmlfiles)
if variable.regexp is not None and variable.type != 'regexp':
msg = _(f'the variable "{variable.path}" has regexp attribut but has not the "regexp" type')
raise DictConsistencyError(msg, 37, variable.xmlfiles)
def convert_test(self):
"""Convert variable tests value"""
@ -152,12 +158,22 @@ class Annotator(Walk): # pylint: disable=R0903
if variable.type == "symlink":
continue
if variable.test is None:
# with we want remove test, we set "" has test value
continue
self.objectspace.informations.add(
variable.path, "test", tuple(variable.test)
)
def convert_examples(self):
"""Convert variable tests value"""
for variable in self.get_variables():
if variable.type == "symlink":
continue
if variable.examples is None:
continue
self.objectspace.informations.add(
variable.path, "examples", tuple(variable.examples)
)
def convert_help(self):
"""Convert variable help"""
for variable in self.get_variables():