fix: update tests

This commit is contained in:
egarette@silique.fr 2024-12-02 20:24:01 +01:00
parent 889a4899a3
commit ec4419287c
6 changed files with 59 additions and 40 deletions

View file

@ -22,30 +22,63 @@ from json import dumps
from tiramisu import undefined
from tiramisu.error import PropertiesOptionError, ConfigError
from rougail.error import ExtentionError
from .i18n import _
class RougailOutputJson:
output_name = 'json'
def __init__(
self,
config: "Config",
*,
rougailconfig: "RougailConfig" = None,
user_data_errors: Optional[list] = None,
user_data_warnings: Optional[list] = None,
) -> None:
if rougailconfig is None:
from rougail import RougailConfig
rougailconfig = RougailConfig
rougailconfig["step.output"] = self.output_name
if rougailconfig["step.output"] != self.output_name:
raise ExtentionError(_('the "step.output" is not set to "{0}"').format(self.output_name))
self.rougailconfig = rougailconfig
self.config = config
self.errors = []
self.warnings = []
if user_data_errors:
self.errors = user_data_errors
else:
self.errors = []
if user_data_warnings:
self.warnings = user_data_warnings
else:
self.warnings = []
self.read_write = self.rougailconfig["json.read_write"]
self.is_mandatory = self.rougailconfig["json.mandatory"]
self.dico = {}
def run(self) -> None:
self.exporter()
return dumps(self.dico, ensure_ascii=False, indent=2) + '\n'
def print(self) -> str:
print(self.run())
def exporter(self) -> None:
self.config.property.read_write()
self.mandatory()
self.manage_warnings()
self.config.property.read_only()
if self.manage_errors():
return
if self.read_write:
self.config.property.read_write()
self.parse_family(
self.config,
self.dico,
)
def mandatory(self):
if not self.is_mandatory:
return
@ -79,29 +112,15 @@ class RougailOutputJson:
)
self.errors.append(f" - {option.description()}")
def exporter(self) -> None:
self.config.property.read_write()
self.mandatory()
if self.errors:
self.dico = {"_errors": self.errors}
return
def manage_warnings(self) -> None:
if self.warnings:
self.dico["_warnings"] = self.warnings
if self.read_write:
self.config.property.read_write()
else:
self.config.property.read_only()
self.parse_family(
self.config,
self.dico,
)
def run(self) -> None:
self.exporter()
return dumps(self.dico, ensure_ascii=False, indent=2) + '\n'
def print(self) -> str:
print(self.run())
def manage_errors(self) -> bool:
if not self.errors:
return False
self.dico = {"_errors": self.errors}
return True
def parse_family(
self,

View file

@ -1,7 +1,5 @@
{
"rougail": {
"variable": [
"[]"
]
"variable": []
}
}

View file

@ -1,7 +1,6 @@
{
"rougail": {
"variable": [
"[]"
]
}
"_errors": [
"The following variables are mandatory but have no value:",
" - rougail.variable (a variable)"
]
}

View file

@ -1,5 +1,3 @@
{
"variable": [
"[]"
]
"variable": []
}

View file

@ -1,5 +1,6 @@
{
"variable": [
"[]"
"_errors": [
"The following variables are mandatory but have no value:",
" - variable (a variable)"
]
}

View file

@ -10,13 +10,13 @@ EXT = 'json'
excludes = []
#excludes = set([
#excludes = [
# '60_5family_dynamic_unknown_suffix',
# '60_5family_dynamic_variable_outside_sub_suffix',
#])
#]
test_ok = get_structures_list(excludes)
# test_ok = ['60_0family_dynamic_variable_suffix']
#test_ok = [Path('../rougail-tests/structures/00_0version_underscore')]
def idfn(fixture_value):
@ -42,18 +42,22 @@ def _test_dictionaries(test_dir, namespace, ext, *, read_write=True, mandatory=F
dir_name += '_namespace'
elif (test_dir / 'force_namespace').is_file():
return
##################################
if read_write:
dir_name += '_read_write'
if mandatory:
dir_name += '_mandatory'
if not do_calc:
dir_name += '_errors'
##################################
rougail = Rougail(rougailconfig)
config = rougail.run()
##################################
if do_calc and (mandatory or not read_write):
get_values_for_config(config)
##################################
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()
output_file = Path(__file__).parent / 'results' / dir_name / (test_dir.name + "." + EXT)
output_file = Path(__file__).parent / 'results' / dir_name / (test_dir.name + "." + ext)
if not output_file.is_file():
if not output_file.parent.is_dir():
output_file.parent.mkdir()