Compare commits
3 commits
878fc246dd
...
a4c1d36d6c
| Author | SHA256 | Date | |
|---|---|---|---|
| a4c1d36d6c | |||
| 53c7d29585 | |||
| 871a0932f5 |
17 changed files with 156 additions and 24 deletions
|
|
@ -24,4 +24,3 @@ RougailOutput = RougailOutputEnvironment
|
||||||
|
|
||||||
|
|
||||||
__all__ = ("RougailOutputEnvironment", "__version__")
|
__all__ = ("RougailOutputEnvironment", "__version__")
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1 +1,3 @@
|
||||||
|
# version of this module, use for example in rougail commandline to display versions
|
||||||
|
# (with --cli.versions option)
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.0"
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -24,7 +23,8 @@ def get_rougail_config(
|
||||||
*,
|
*,
|
||||||
backward_compatibility=True,
|
backward_compatibility=True,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
options = [f"""
|
options = [
|
||||||
|
f"""
|
||||||
environment:
|
environment:
|
||||||
exists: true
|
exists: true
|
||||||
redefine: true
|
redefine: true
|
||||||
|
|
@ -36,7 +36,8 @@ environment:
|
||||||
return_type: boolean
|
return_type: boolean
|
||||||
description: >-
|
description: >-
|
||||||
{_('if environment is not in "step.output" and not in "step.user_data"')}
|
{_('if environment is not in "step.output" and not in "step.user_data"')}
|
||||||
""", f"""
|
""",
|
||||||
|
f"""
|
||||||
environment:
|
environment:
|
||||||
exists: false
|
exists: false
|
||||||
type: family
|
type: family
|
||||||
|
|
@ -51,7 +52,8 @@ environment:
|
||||||
variable: step.output
|
variable: step.output
|
||||||
when_not: environment
|
when_not: environment
|
||||||
propertyerror: false
|
propertyerror: false
|
||||||
""", f"""
|
""",
|
||||||
|
f"""
|
||||||
environment:
|
environment:
|
||||||
|
|
||||||
output:
|
output:
|
||||||
|
|
@ -117,7 +119,8 @@ environment:
|
||||||
{{% endif %}}
|
{{% endif %}}
|
||||||
description: >-
|
description: >-
|
||||||
{_('if "_.multi_in_array" the value is ";" otherwise the value is ","')}
|
{_('if "_.multi_in_array" the value is ";" otherwise the value is ","')}
|
||||||
"""]
|
""",
|
||||||
|
]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"name": "environment",
|
"name": "environment",
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ You should have received a copy of the GNU Lesser General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
from rougail.error import ExtensionError
|
from rougail.error import ExtensionError
|
||||||
|
|
||||||
|
|
@ -24,6 +26,7 @@ from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
class RougailOutputEnvironment:
|
class RougailOutputEnvironment:
|
||||||
|
"""Rougail output that generate environment variables"""
|
||||||
output_name = "environment"
|
output_name = "environment"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
@ -67,15 +70,23 @@ class RougailOutputEnvironment:
|
||||||
else:
|
else:
|
||||||
self.booleans = {True: 1, False: 0}
|
self.booleans = {True: 1, False: 0}
|
||||||
self.upper = self.rougailconfig["environment.output.upper"]
|
self.upper = self.rougailconfig["environment.output.upper"]
|
||||||
self.path_is_variable_name = self.rougailconfig["environment.output.path_is_variable_name"]
|
self.path_is_variable_name = self.rougailconfig[
|
||||||
|
"environment.output.path_is_variable_name"
|
||||||
|
]
|
||||||
if self.path_is_variable_name:
|
if self.path_is_variable_name:
|
||||||
self.custom_separator = self.rougailconfig["environment.output.custom_separator"]
|
self.custom_separator = self.rougailconfig[
|
||||||
|
"environment.output.custom_separator"
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
self.custom_separator = None
|
self.custom_separator = None
|
||||||
self.multi_in_array = self.rougailconfig["environment.output.multi_in_array"]
|
self.multi_in_array = self.rougailconfig["environment.output.multi_in_array"]
|
||||||
if not self.multi_in_array:
|
if not self.multi_in_array:
|
||||||
self.multi_separator = self.rougailconfig["environment.output.multi_separator"]
|
self.multi_separator = self.rougailconfig[
|
||||||
self.submulti_separator = self.rougailconfig["environment.output.submulti_separator"]
|
"environment.output.multi_separator"
|
||||||
|
]
|
||||||
|
self.submulti_separator = self.rougailconfig[
|
||||||
|
"environment.output.submulti_separator"
|
||||||
|
]
|
||||||
ret = self.exporter()
|
ret = self.exporter()
|
||||||
if isinstance(self.dico, str):
|
if isinstance(self.dico, str):
|
||||||
value = self.dico
|
value = self.dico
|
||||||
|
|
@ -157,8 +168,10 @@ class RougailOutputEnvironment:
|
||||||
|
|
||||||
def set_value(self, name, values):
|
def set_value(self, name, values):
|
||||||
if name in self.dico:
|
if name in self.dico:
|
||||||
raise ExtensionError(_('The variable name "{0}" is duplicated').format(name))
|
raise ExtensionError(
|
||||||
self.dico[name] = f'{name}={self.conv_values(name, values)}'
|
_('The variable name "{0}" is duplicated').format(name)
|
||||||
|
)
|
||||||
|
self.dico[name] = f"{name}={self.conv_values(name, values)}"
|
||||||
|
|
||||||
def conv_values(self, name, values):
|
def conv_values(self, name, values):
|
||||||
if isinstance(values, list):
|
if isinstance(values, list):
|
||||||
|
|
@ -175,12 +188,22 @@ class RougailOutputEnvironment:
|
||||||
for value in values:
|
for value in values:
|
||||||
value = self.conv_to_string(value)
|
value = self.conv_to_string(value)
|
||||||
if self.submulti_separator in value:
|
if self.submulti_separator in value:
|
||||||
raise ExtensionError(_('the character "{0}" is a sub multi separator, this character must not in the "{1}" value').format(self.submulti_separator, name))
|
raise ExtensionError(
|
||||||
|
_(
|
||||||
|
'the character "{0}" is a sub multi separator, '
|
||||||
|
'this character must not in the "{1}" value'
|
||||||
|
).format(self.submulti_separator, name)
|
||||||
|
)
|
||||||
new_values.append(value)
|
new_values.append(value)
|
||||||
values = self.submulti_separator.join(new_values)
|
values = self.submulti_separator.join(new_values)
|
||||||
values = self.conv_to_string(values)
|
values = self.conv_to_string(values)
|
||||||
if not self.multi_in_array and self.multi_separator in values:
|
if not self.multi_in_array and self.multi_separator in values:
|
||||||
raise ExtensionError(_('the character "{0}" is a multi separator, this character must not in the "{1}" value').format(self.multi_separator, name))
|
raise ExtensionError(
|
||||||
|
_(
|
||||||
|
'the character "{0}" is a multi separator, '
|
||||||
|
'this character must not in the "{1}" value'
|
||||||
|
).format(self.multi_separator, name)
|
||||||
|
)
|
||||||
return quote(values)
|
return quote(values)
|
||||||
|
|
||||||
def conv_to_string(self, values):
|
def conv_to_string(self, values):
|
||||||
|
|
@ -207,10 +230,15 @@ class RougailOutputEnvironment:
|
||||||
if not follower_name:
|
if not follower_name:
|
||||||
follower_name = self.get_name(follower)
|
follower_name = self.get_name(follower)
|
||||||
followers_name[follower_path] = follower_name
|
followers_name[follower_path] = follower_name
|
||||||
followers_data.setdefault(follower_name, {})[follower.index()] = follower.value.get()
|
followers_data.setdefault(follower_name, {})[
|
||||||
|
follower.index()
|
||||||
|
] = follower.value.get()
|
||||||
leader_len = len(leader_values)
|
leader_len = len(leader_values)
|
||||||
for name, values in followers_data.items():
|
for name, values in followers_data.items():
|
||||||
self.set_value(name, [values[idx] if idx in values else "" for idx in range(leader_len)])
|
self.set_value(
|
||||||
|
name,
|
||||||
|
[values[idx] if idx in values else "" for idx in range(leader_len)],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
RougailOutput = RougailOutputEnvironment
|
RougailOutput = RougailOutputEnvironment
|
||||||
|
|
|
||||||
Binary file not shown.
12
tests/errors/duplicate/rougail/00-file.yml
Normal file
12
tests/errors/duplicate/rougail/00-file.yml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
family_1: # A family
|
||||||
|
|
||||||
|
variable: # A variable
|
||||||
|
|
||||||
|
family_2: # An other family
|
||||||
|
|
||||||
|
variable: # A variable
|
||||||
|
...
|
||||||
8
tests/errors/multi_separator/rougail/00-file.yml
Normal file
8
tests/errors/multi_separator/rougail/00-file.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
variable: # A variable
|
||||||
|
- val1
|
||||||
|
- val;2
|
||||||
|
...
|
||||||
20
tests/errors/multi_separator2/rougail/00-file.yml
Normal file
20
tests/errors/multi_separator2/rougail/00-file.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
sequence:
|
||||||
|
description: A sequence
|
||||||
|
type: sequence
|
||||||
|
|
||||||
|
variable1:
|
||||||
|
description: A variable 1
|
||||||
|
default:
|
||||||
|
- val1
|
||||||
|
- val2
|
||||||
|
|
||||||
|
variable2:
|
||||||
|
description: A variable 2
|
||||||
|
default:
|
||||||
|
- val1
|
||||||
|
- val;2
|
||||||
|
...
|
||||||
20
tests/errors/submulti_separator/rougail/00-file.yml
Normal file
20
tests/errors/submulti_separator/rougail/00-file.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
sequence:
|
||||||
|
description: A sequence
|
||||||
|
type: sequence
|
||||||
|
|
||||||
|
variable1:
|
||||||
|
description: A variable 1
|
||||||
|
default:
|
||||||
|
- val1
|
||||||
|
- val2
|
||||||
|
|
||||||
|
variable2:
|
||||||
|
description: A variable 2
|
||||||
|
default:
|
||||||
|
- val1
|
||||||
|
- val,2
|
||||||
|
...
|
||||||
43
tests/test_error.py
Normal file
43
tests/test_error.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
from pathlib import Path
|
||||||
|
from pytest import raises
|
||||||
|
from rougail_tests.utils import get_rougail_config, get_values_for_config
|
||||||
|
#########################
|
||||||
|
from rougail.output_environment import RougailOutputEnvironment as RougailOutput
|
||||||
|
#########################
|
||||||
|
from rougail.error import ExtensionError
|
||||||
|
from rougail import Rougail
|
||||||
|
|
||||||
|
|
||||||
|
def _test_error(test_dir):
|
||||||
|
rougailconfig = get_rougail_config(test_dir, False)
|
||||||
|
if not rougailconfig:
|
||||||
|
return
|
||||||
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
||||||
|
##################################
|
||||||
|
rougailconfig['step.output'] = 'environment'
|
||||||
|
rougailconfig["environment.output.path_is_variable_name"] = False
|
||||||
|
rougailconfig["environment.output.multi_in_array"] = False
|
||||||
|
##################################
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
##################################
|
||||||
|
get_values_for_config(config, level="mandatory")
|
||||||
|
##################################
|
||||||
|
with raises(ExtensionError):
|
||||||
|
RougailOutput(config, rougailconfig=rougailconfig).run()
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_duplicate():
|
||||||
|
_test_error(Path("tests/errors/duplicate"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_multi_separator():
|
||||||
|
_test_error(Path("tests/errors/multi_separator"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_multi_separator2():
|
||||||
|
_test_error(Path("tests/errors/multi_separator2"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_submulti_separator():
|
||||||
|
_test_error(Path("tests/errors/submulti_separator"))
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
import os
|
|
||||||
from pytest import fixture, raises
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from rougail import Rougail, RougailConfig
|
from pytest import fixture
|
||||||
|
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config
|
||||||
#########################
|
#########################
|
||||||
from rougail.output_environment import RougailOutputEnvironment as RougailOutput
|
from rougail.output_environment import RougailOutputEnvironment as RougailOutput
|
||||||
from json import load, dump
|
|
||||||
#########################
|
#########################
|
||||||
|
from rougail import Rougail
|
||||||
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict
|
|
||||||
|
|
||||||
EXT = "env"
|
EXT = "env"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue