From 3b2d96566b5c53b002b8fccb529dc6d850380c2e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 17 Feb 2021 17:30:06 +0100 Subject: [PATCH] valid value in param --- src/rougail/annotator/param.py | 8 ++++-- .../dictionaries/70port_portlist/00-base.xml | 1 - .../70port_portlist/tiramisu/base.py | 4 +-- .../70port_portlist_optional/00-base.xml | 17 ++++++++++++ .../70port_portlist_optional/__init__.py | 0 .../makedict/base.json | 1 + .../70port_portlist_optional/tiramisu/base.py | 16 ++++++++++++ tests/dictionaries/80invalid_port/00-base.xml | 26 +++++++++++++++++++ tests/dictionaries/80invalid_port/__init__.py | 0 tests/dictionaries/80invalid_port/errno_13 | 0 10 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 tests/dictionaries/70port_portlist_optional/00-base.xml create mode 100644 tests/dictionaries/70port_portlist_optional/__init__.py create mode 100644 tests/dictionaries/70port_portlist_optional/makedict/base.json create mode 100644 tests/dictionaries/70port_portlist_optional/tiramisu/base.py create mode 100644 tests/dictionaries/80invalid_port/00-base.xml create mode 100644 tests/dictionaries/80invalid_port/__init__.py create mode 100644 tests/dictionaries/80invalid_port/errno_13 diff --git a/src/rougail/annotator/param.py b/src/rougail/annotator/param.py index a6e763b1..0b684e84 100644 --- a/src/rougail/annotator/param.py +++ b/src/rougail/annotator/param.py @@ -24,6 +24,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ +import tiramisu + from .variable import CONVERT_OPTION from ..i18n import _ @@ -104,9 +106,11 @@ class ParamAnnotator: f'with type "{variable_type}"') raise DictConsistencyError(msg, 7, param.xmlfiles) try: - param.text = CONVERT_OPTION[variable_type].get('func', str)(param.text) + option = CONVERT_OPTION[variable_type] + param.text = option.get('func', str)(param.text) + getattr(tiramisu, option['opttype'])('test', 'Object to valid value', param.text, **option.get('initkwargs', {})) except ValueError as err: - msg = _(f'unable to change type of "{param.text}" ' + msg = _(f'unable to change type of value "{param.text}" ' f'is not a valid "{variable_type}"') raise DictConsistencyError(msg, 13, param.xmlfiles) from err param.type = variable_type diff --git a/tests/dictionaries/70port_portlist/00-base.xml b/tests/dictionaries/70port_portlist/00-base.xml index 1a7bf309..288580f3 100644 --- a/tests/dictionaries/70port_portlist/00-base.xml +++ b/tests/dictionaries/70port_portlist/00-base.xml @@ -17,7 +17,6 @@ - example diff --git a/tests/dictionaries/70port_portlist/tiramisu/base.py b/tests/dictionaries/70port_portlist/tiramisu/base.py index e568c1f3..a0d70a1b 100644 --- a/tests/dictionaries/70port_portlist/tiramisu/base.py +++ b/tests/dictionaries/70port_portlist/tiramisu/base.py @@ -15,11 +15,11 @@ option_2 = PortOption(name="my_variable", doc="my_variable", default="123", allo option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) option_7 = SymLinkOption(name="name", opt=option_2) option_8 = StrOption(name="protocol", doc="protocol", default="udp") -option_9 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue((None, '')), 'condition_operator': ParamValue("OR")}))) +option_9 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue(None)}))) option_6 = OptionDescription(name="my_variable", doc="my_variable", children=[option_7, option_8, option_9]) option_11 = SymLinkOption(name="name", opt=option_2) option_12 = StrOption(name="protocol", doc="protocol", default="tcp") -option_13 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue((None, '')), 'condition_operator': ParamValue("OR")}))) +option_13 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_2), 'expected_0': ParamValue(None)}))) option_10 = OptionDescription(name="my_variable_1", doc="my_variable_1", children=[option_11, option_12, option_13]) option_5 = OptionDescription(name="ports", doc="ports", children=[option_6, option_10]) option_4 = OptionDescription(name="ntp", doc="ntp", children=[option_5]) diff --git a/tests/dictionaries/70port_portlist_optional/00-base.xml b/tests/dictionaries/70port_portlist_optional/00-base.xml new file mode 100644 index 00000000..f885f1d9 --- /dev/null +++ b/tests/dictionaries/70port_portlist_optional/00-base.xml @@ -0,0 +1,17 @@ + + + + + + 123 + + + + + + example + + + + diff --git a/tests/dictionaries/70port_portlist_optional/__init__.py b/tests/dictionaries/70port_portlist_optional/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/70port_portlist_optional/makedict/base.json b/tests/dictionaries/70port_portlist_optional/makedict/base.json new file mode 100644 index 00000000..0ca5d8e4 --- /dev/null +++ b/tests/dictionaries/70port_portlist_optional/makedict/base.json @@ -0,0 +1 @@ +{"rougail.my_variable": "123"} diff --git a/tests/dictionaries/70port_portlist_optional/tiramisu/base.py b/tests/dictionaries/70port_portlist_optional/tiramisu/base.py new file mode 100644 index 00000000..a3699558 --- /dev/null +++ b/tests/dictionaries/70port_portlist_optional/tiramisu/base.py @@ -0,0 +1,16 @@ +from importlib.machinery import SourceFileLoader +from importlib.util import spec_from_loader, module_from_spec +loader = SourceFileLoader('func', 'tests/dictionaries/../eosfunc/test.py') +spec = spec_from_loader(loader.name, loader) +func = module_from_spec(spec) +loader.exec_module(func) +for key, value in dict(locals()).items(): + if key != ['SourceFileLoader', 'func']: + setattr(func, key, value) +try: + from tiramisu3 import * +except: + from tiramisu import * +option_2 = PortOption(name="my_variable", doc="my_variable", default="123", allow_private=True, properties=frozenset({"mandatory", "normal"})) +option_1 = OptionDescription(name="rougail", doc="rougail", children=[option_2]) +option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1]) diff --git a/tests/dictionaries/80invalid_port/00-base.xml b/tests/dictionaries/80invalid_port/00-base.xml new file mode 100644 index 00000000..5baa3e01 --- /dev/null +++ b/tests/dictionaries/80invalid_port/00-base.xml @@ -0,0 +1,26 @@ + + + + + + + my_variable + my_variable + + + + + + 123 + + + + + + aaa + example + + + + diff --git a/tests/dictionaries/80invalid_port/__init__.py b/tests/dictionaries/80invalid_port/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/80invalid_port/errno_13 b/tests/dictionaries/80invalid_port/errno_13 new file mode 100644 index 00000000..e69de29b