From b76a04dd19ed06f81322f4e7da4fdd106dc43e14 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 30 Jan 2021 17:32:21 +0100 Subject: [PATCH] remove todict --- src/rougail/tiramisureflector.py | 8 ++------ .../dictionaries/01base_domainname/00-base.xml | 12 ++++++++++++ .../dictionaries/01base_domainname/__init__.py | 0 .../01base_domainname/makedict/base.json | 1 + .../01base_domainname/tiramisu/base.py | 18 ++++++++++++++++++ .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../11disabled_if_in_filelist/tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 4 ++-- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- .../tiramisu/base.py | 2 +- 15 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 tests/dictionaries/01base_domainname/00-base.xml create mode 100644 tests/dictionaries/01base_domainname/__init__.py create mode 100644 tests/dictionaries/01base_domainname/makedict/base.json create mode 100644 tests/dictionaries/01base_domainname/tiramisu/base.py diff --git a/src/rougail/tiramisureflector.py b/src/rougail/tiramisureflector.py index c9382907..de07bf9c 100644 --- a/src/rougail/tiramisureflector.py +++ b/src/rougail/tiramisureflector.py @@ -32,9 +32,6 @@ from .annotator import CONVERT_OPTION from .objspace import RootRougailObject -FUNC_TO_DICT = ['calc_value'] - - class Root(): # pylint: disable=R0903 """Root classes """ @@ -275,6 +272,8 @@ class Variable(Common): if hasattr(self.elt, key): keys[key] = getattr(self.elt, key) for key, value in CONVERT_OPTION[self.elt.type].get('initkwargs', {}).items(): + if isinstance(value, str): + value = f"'{value}'" keys[key] = value def calculation_value(self, @@ -329,7 +328,6 @@ class Variable(Common): """build variable parameters """ option_name = param.text.reflector_object.get() - todict = function in FUNC_TO_DICT params = [f'{option_name}'] if hasattr(param, 'suffix'): param_type = 'ParamDynOption' @@ -338,8 +336,6 @@ class Variable(Common): param_type = 'ParamOption' if param.notraisepropertyerror: params.append(f'notraisepropertyerror={param.notraisepropertyerror}') - if todict: - params.append(f'todict={todict}') return "{}({})".format(param_type, ', '.join(params)) diff --git a/tests/dictionaries/01base_domainname/00-base.xml b/tests/dictionaries/01base_domainname/00-base.xml new file mode 100644 index 00000000..72bd71cf --- /dev/null +++ b/tests/dictionaries/01base_domainname/00-base.xml @@ -0,0 +1,12 @@ + + + + + + my.domain.name + + + + + diff --git a/tests/dictionaries/01base_domainname/__init__.py b/tests/dictionaries/01base_domainname/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/dictionaries/01base_domainname/makedict/base.json b/tests/dictionaries/01base_domainname/makedict/base.json new file mode 100644 index 00000000..c593c56f --- /dev/null +++ b/tests/dictionaries/01base_domainname/makedict/base.json @@ -0,0 +1 @@ +{"rougail.general.domain": "my.domain.name"} diff --git a/tests/dictionaries/01base_domainname/tiramisu/base.py b/tests/dictionaries/01base_domainname/tiramisu/base.py new file mode 100644 index 00000000..3db95f5b --- /dev/null +++ b/tests/dictionaries/01base_domainname/tiramisu/base.py @@ -0,0 +1,18 @@ +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 * +from rougail.tiramisu import ConvertDynOptionDescription +option_3 = DomainnameOption(name="domain", doc="Description", default="my.domain.name", type='domainname', allow_ip=False, properties=frozenset({"mandatory", "normal"})) +option_2 = OptionDescription(name="general", doc="general", children=[option_3], properties=frozenset({"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/10load_disabled_if_in_multi_param/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py index 0e6a5dc7..694ddefd 100644 --- a/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py +++ b/tests/dictionaries/10load_disabled_if_in_multi_param/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file1") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file1") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3, todict=True), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param2/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_in_multi_param2/tiramisu/base.py index ac861601..52cbc9e6 100644 --- a/tests/dictionaries/10load_disabled_if_in_multi_param2/tiramisu/base.py +++ b/tests/dictionaries/10load_disabled_if_in_multi_param2/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file1") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file1") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("yes"), 'condition_1': ParamOption(option_3, todict=True), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR"), 'condition_2': ParamOption(option_4, todict=True), 'expected_2': ParamValue("yes"), 'condition_3': ParamOption(option_4, todict=True), 'expected_3': ParamValue("maybe")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("yes"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR"), 'condition_2': ParamOption(option_4), 'expected_2': ParamValue("yes"), 'condition_3': ParamOption(option_4), 'expected_3': ParamValue("maybe")}))) option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py index 54dff254..f1872fcc 100644 --- a/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py +++ b/tests/dictionaries/10load_disabled_if_in_multi_param_disabled/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file1") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file1") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3, todict=True), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui"), 'condition_1': ParamOption(option_3), 'expected_1': ParamValue("maybe"), 'condition_operator': ParamValue("OR")}))) option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabled_if_in_filelist/tiramisu/base.py b/tests/dictionaries/11disabled_if_in_filelist/tiramisu/base.py index 8fd25cb5..9a2845c5 100644 --- a/tests/dictionaries/11disabled_if_in_filelist/tiramisu/base.py +++ b/tests/dictionaries/11disabled_if_in_filelist/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/etc/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabled_if_in_filelist_disabled/tiramisu/base.py b/tests/dictionaries/11disabled_if_in_filelist_disabled/tiramisu/base.py index 9fd5468c..183b570b 100644 --- a/tests/dictionaries/11disabled_if_in_filelist_disabled/tiramisu/base.py +++ b/tests/dictionaries/11disabled_if_in_filelist_disabled/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/etc/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabled_if_in_filelist_multi/tiramisu/base.py b/tests/dictionaries/11disabled_if_in_filelist_multi/tiramisu/base.py index b6d862ed..7b968e92 100644 --- a/tests/dictionaries/11disabled_if_in_filelist_multi/tiramisu/base.py +++ b/tests/dictionaries/11disabled_if_in_filelist_multi/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file1") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file1") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui")}))) option_9 = OptionDescription(name="file1", doc="file1", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_18 = StrOption(name="group", doc="group", default="root") option_19 = StrOption(name="mode", doc="mode", default="0644") @@ -31,7 +31,7 @@ option_20 = StrOption(name="name", doc="name", default="/tmp/file2") option_21 = StrOption(name="owner", doc="owner", default="root") option_22 = StrOption(name="source", doc="source", default="file2") option_23 = BoolOption(name="templating", doc="templating", default=True) -option_24 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("oui")}))) +option_24 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(False)), kwargs={'default': ParamValue(True), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("oui")}))) option_17 = OptionDescription(name="file2", doc="file2", children=[option_18, option_19, option_20, option_21, option_22, option_23, option_24]) option_8 = OptionDescription(name="files", doc="files", children=[option_9, option_17]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabledifin_filelist_notexist/tiramisu/base.py b/tests/dictionaries/11disabledifin_filelist_notexist/tiramisu/base.py index 0a2bd873..d69923f4 100644 --- a/tests/dictionaries/11disabledifin_filelist_notexist/tiramisu/base.py +++ b/tests/dictionaries/11disabledifin_filelist_notexist/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("unpossible")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist/tiramisu/base.py b/tests/dictionaries/11disabledifnotin_filelist_notexist/tiramisu/base.py index 0a2bd873..d69923f4 100644 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist/tiramisu/base.py +++ b/tests/dictionaries/11disabledifnotin_filelist_notexist/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("unpossible")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py b/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py index 7ad94100..4fa49b3d 100644 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py +++ b/tests/dictionaries/11disabledifnotin_filelist_notexist_multi/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5, todict=True), 'expected_1': ParamValue("oui"), 'condition_operator': ParamValue("OR")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("unpossible"), 'condition_1': ParamOption(option_5), 'expected_1': ParamValue("oui"), 'condition_operator': ParamValue("OR")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8]) diff --git a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py b/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py index cd215381..0da6aab5 100644 --- a/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py +++ b/tests/dictionaries/11disabledifnotin_filelist_notexist_validenum/tiramisu/base.py @@ -23,7 +23,7 @@ option_12 = StrOption(name="name", doc="name", default="/tmp/file") option_13 = StrOption(name="owner", doc="owner", default="root") option_14 = StrOption(name="source", doc="source", default="file") option_15 = BoolOption(name="templating", doc="templating", default=True) -option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3, todict=True), 'expected_0': ParamValue("statique")}))) +option_16 = BoolOption(name="activate", doc="activate", default=Calculation(func.calc_value, Params((ParamValue(True)), kwargs={'default': ParamValue(False), 'condition_0': ParamOption(option_3), 'expected_0': ParamValue("statique")}))) option_9 = OptionDescription(name="file", doc="file", children=[option_10, option_11, option_12, option_13, option_14, option_15, option_16]) option_8 = OptionDescription(name="files", doc="files", children=[option_9]) option_7 = OptionDescription(name="test", doc="test", children=[option_8])