feat: can link regexp variable
This commit is contained in:
parent
dc311466a2
commit
1858eeeb06
10 changed files with 110 additions and 1 deletions
|
|
@ -47,6 +47,7 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
self.objectspace = objectspace
|
||||
self.convert_value()
|
||||
self.valid_choices()
|
||||
self.valid_regexp()
|
||||
|
||||
def convert_value(self) -> None:
|
||||
"""convert value"""
|
||||
|
|
@ -114,7 +115,7 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
if isinstance(variable.choices, Calculation):
|
||||
continue
|
||||
if variable.choices is None:
|
||||
msg = f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice'
|
||||
msg = _(f'the variable "{variable.path}" is a "choice" variable but don\'t have any choice')
|
||||
raise DictConsistencyError(msg, 19, variable.xmlfiles)
|
||||
if not variable.mandatory and not variable.multi:
|
||||
self.add_choice_nil(variable)
|
||||
|
|
@ -125,3 +126,11 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
if choice is None:
|
||||
return
|
||||
variable.choices.append(None)
|
||||
|
||||
def valid_regexp(self) -> None:
|
||||
for variable in self.get_variables():
|
||||
if variable.type != "regexp":
|
||||
continue
|
||||
if variable.regexp is None:
|
||||
msg = _(f'the variable "{variable.path}" is a "regexp" variable but don\'t have any regexp')
|
||||
raise DictConsistencyError(msg, 66, variable.xmlfiles)
|
||||
|
|
|
|||
|
|
@ -156,6 +156,8 @@ class Annotator(Walk): # pylint: disable=R0903
|
|||
variable.params = calculated_variable.params
|
||||
if variable.type == 'choice' and variable.choices is None:
|
||||
variable.choices = calculated_variable.choices
|
||||
if variable.type == 'regexp' and variable.regexp is None:
|
||||
variable.regexp = calculated_variable.regexp
|
||||
# copy multi attribut
|
||||
if variable.multi is None:
|
||||
calculated_path = calculated_variable.path
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"rougail.var1": {
|
||||
"owner": "default",
|
||||
"value": [
|
||||
"a",
|
||||
"b",
|
||||
"c"
|
||||
]
|
||||
},
|
||||
"rougail.var2": {
|
||||
"owner": "default",
|
||||
"value": "a"
|
||||
},
|
||||
"rougail.family.var3": {
|
||||
"owner": "default",
|
||||
"value": "a"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"rougail.var1": [
|
||||
"a",
|
||||
"b",
|
||||
"c"
|
||||
],
|
||||
"rougail.var2": "a",
|
||||
"rougail.family.var3": "a"
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"rougail.var1": {
|
||||
"owner": "default",
|
||||
"value": [
|
||||
"a",
|
||||
"b",
|
||||
"c"
|
||||
]
|
||||
},
|
||||
"rougail.var2": {
|
||||
"owner": "default",
|
||||
"value": "a"
|
||||
},
|
||||
"rougail.family.var3": {
|
||||
"owner": "default",
|
||||
"value": "a"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
[]
|
||||
26
tests/dictionaries/00_6regexp_link/tiramisu/base.py
Normal file
26
tests/dictionaries/00_6regexp_link/tiramisu/base.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from re import compile as re_compile
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('../rougail-tests/funcs/test.py')
|
||||
try:
|
||||
groups.namespace
|
||||
except:
|
||||
groups.addgroup('namespace')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
class Regexp_option_2(RegexpOption):
|
||||
__slots__ = tuple()
|
||||
_type = 'value'
|
||||
Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
|
||||
|
||||
class Regexp_option_3(RegexpOption):
|
||||
__slots__ = tuple()
|
||||
_type = 'value'
|
||||
Regexp_option_3._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
|
||||
|
||||
option_2 = Regexp_option_2(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')})
|
||||
option_3 = Regexp_option_3(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_2)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'})
|
||||
optiondescription_1 = OptionDescription(name="rougail", doc="Rougail", group_type=groups.namespace, children=[option_2, option_3], properties=frozenset({"standard"}))
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[optiondescription_1])
|
||||
21
tests/dictionaries/00_6regexp_link/tiramisu/no_namespace.py
Normal file
21
tests/dictionaries/00_6regexp_link/tiramisu/no_namespace.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from tiramisu import *
|
||||
from tiramisu.setting import ALLOWED_LEADER_PROPERTIES
|
||||
from re import compile as re_compile
|
||||
from rougail.tiramisu import func, dict_env, load_functions, ConvertDynOptionDescription
|
||||
load_functions('../rougail-tests/funcs/test.py')
|
||||
ALLOWED_LEADER_PROPERTIES.add("basic")
|
||||
ALLOWED_LEADER_PROPERTIES.add("standard")
|
||||
ALLOWED_LEADER_PROPERTIES.add("advanced")
|
||||
class Regexp_option_1(RegexpOption):
|
||||
__slots__ = tuple()
|
||||
_type = 'value'
|
||||
Regexp_option_1._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
|
||||
|
||||
class Regexp_option_2(RegexpOption):
|
||||
__slots__ = tuple()
|
||||
_type = 'value'
|
||||
Regexp_option_2._regexp = re_compile(r"^#(?:[0-9a-f]{3}){1,2}$")
|
||||
|
||||
option_1 = Regexp_option_1(name="var1", doc="a first variable", default="#a1a1a1", properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp', 'test': ('#b1b1b1', '#b2b2b2')})
|
||||
option_2 = Regexp_option_2(name="var2", doc="a second variable", default=Calculation(func['calc_value'], Params((ParamOption(option_1)))), properties=frozenset({"mandatory", "standard"}), informations={'type': 'regexp'})
|
||||
option_0 = OptionDescription(name="baseoption", doc="baseoption", children=[option_1, option_2])
|
||||
0
tests/errors/20_test_regexp_without_regexp/errno_66
Normal file
0
tests/errors/20_test_regexp_without_regexp/errno_66
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
version: '1.1'
|
||||
var:
|
||||
description: a first variable
|
||||
type: regexp
|
||||
Loading…
Reference in a new issue