convert integer to string for port variable (#31 and #32)

Reviewed-on: #32
This commit is contained in:
egarette@silique.fr 2024-09-04 16:33:02 +02:00 committed by gwen
parent ea93bc55fc
commit 7bdc39e370
10 changed files with 98 additions and 0 deletions

View file

@ -55,6 +55,8 @@ class Annotator(Walk): # pylint: disable=R0903
for variable in self.get_variables():
if variable.type == "symlink":
continue
if variable.version != '1.0' and variable.type == 'port':
self._convert_port(variable)
self._convert_value(variable)
def _convert_value(
@ -98,6 +100,14 @@ class Annotator(Walk): # pylint: disable=R0903
self.objectspace.default_multi[variable.path] = variable.default
variable.default = None
def _convert_port(self, variable) -> None:
if variable.multi is False and isinstance(variable.default, int):
variable.default = str(variable.default)
elif variable.multi is True and variable.default:
for idx, value in enumerate(variable.default):
if isinstance(value, int):
variable.default[idx] = str(value)
def valid_choices(self) -> None:
"""A variable with type "Choice" that is not mandatory must has "nil" value"""
for variable in self.get_variables():

View file

View file

@ -0,0 +1,13 @@
---
version: '1.1'
variable1:
description: a port variable
type: port
variable2:
description: a port variable with default value
type: port
default: '8080'
variable3:
description: a port variable with integer default value
type: port
default: 8080

View file

@ -0,0 +1,14 @@
{
"rougail.variable1": {
"owner": "default",
"value": null
},
"rougail.variable2": {
"owner": "default",
"value": "8080"
},
"rougail.variable3": {
"owner": "default",
"value": "8080"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail.variable1": null,
"rougail.variable2": "8080",
"rougail.variable3": "8080"
}

View file

@ -0,0 +1,14 @@
{
"rougail.variable1": {
"owner": "default",
"value": null
},
"rougail.variable2": {
"owner": "default",
"value": "8080"
},
"rougail.variable3": {
"owner": "default",
"value": "8080"
}
}

View file

@ -0,0 +1 @@
["rougail.variable1"]

View file

@ -0,0 +1,12 @@
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
load_functions('tests/dictionaries/../eosfunc/test.py')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_2 = PortOption(name="variable1", doc="a port variable", allow_private=True, properties=frozenset({"basic", "mandatory"}), informations={'type': 'port'})
option_3 = PortOption(name="variable2", doc="a port variable with default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
option_4 = PortOption(name="variable3", doc="a port variable with integer default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", children=[option_2, option_3, option_4], properties=frozenset({"basic"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])

View file

@ -0,0 +1,18 @@
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
load_functions('tests/dictionaries/../eosfunc/test.py')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_3 = PortOption(name="variable1", doc="a port variable", allow_private=True, properties=frozenset({"basic", "mandatory"}), informations={'type': 'port'})
option_4 = PortOption(name="variable2", doc="a port variable with default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
option_5 = PortOption(name="variable3", doc="a port variable with integer default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
optiondescription_2 = OptionDescription(name="rougail", doc="Rougail", children=[option_3, option_4, option_5], properties=frozenset({"basic"}))
optiondescription_1 = OptionDescription(name="1", doc="1", children=[optiondescription_2], properties=frozenset({"basic"}))
option_8 = PortOption(name="variable1", doc="a port variable", allow_private=True, properties=frozenset({"basic", "mandatory"}), informations={'type': 'port'})
option_9 = PortOption(name="variable2", doc="a port variable with default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
option_10 = PortOption(name="variable3", doc="a port variable with integer default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
optiondescription_7 = OptionDescription(name="rougail", doc="Rougail", children=[option_8, option_9, option_10], properties=frozenset({"basic"}))
optiondescription_6 = OptionDescription(name="2", doc="2", children=[optiondescription_7], properties=frozenset({"basic"}))
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1, optiondescription_6])

View file

@ -0,0 +1,11 @@
from tiramisu import *
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
load_functions('tests/dictionaries/../eosfunc/test.py')
ALLOWED_LEADER_PROPERTIES.add("basic")
ALLOWED_LEADER_PROPERTIES.add("standard")
ALLOWED_LEADER_PROPERTIES.add("advanced")
option_1 = PortOption(name="variable1", doc="a port variable", allow_private=True, properties=frozenset({"basic", "mandatory"}), informations={'type': 'port'})
option_2 = PortOption(name="variable2", doc="a port variable with default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
option_3 = PortOption(name="variable3", doc="a port variable with integer default value", default="8080", allow_private=True, properties=frozenset({"mandatory", "standard"}), informations={'type': 'port'})
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2, option_3])