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

View file

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

View file

@ -1,7 +1,6 @@
{ {
"rougail": { "_errors": [
"variable": [ "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 = []
#excludes = set([ #excludes = [
# '60_5family_dynamic_unknown_suffix', # '60_5family_dynamic_unknown_suffix',
# '60_5family_dynamic_variable_outside_sub_suffix', # '60_5family_dynamic_variable_outside_sub_suffix',
#]) #]
test_ok = get_structures_list(excludes) 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): def idfn(fixture_value):
@ -42,18 +42,22 @@ def _test_dictionaries(test_dir, namespace, ext, *, read_write=True, mandatory=F
dir_name += '_namespace' dir_name += '_namespace'
elif (test_dir / 'force_namespace').is_file(): elif (test_dir / 'force_namespace').is_file():
return return
##################################
if read_write: if read_write:
dir_name += '_read_write' dir_name += '_read_write'
if mandatory: if mandatory:
dir_name += '_mandatory' dir_name += '_mandatory'
if not do_calc: if not do_calc:
dir_name += '_errors' dir_name += '_errors'
##################################
rougail = Rougail(rougailconfig) rougail = Rougail(rougailconfig)
config = rougail.run() config = rougail.run()
##################################
if do_calc and (mandatory or not read_write): if do_calc and (mandatory or not read_write):
get_values_for_config(config) get_values_for_config(config)
##################################
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run() 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.is_file():
if not output_file.parent.is_dir(): if not output_file.parent.is_dir():
output_file.parent.mkdir() output_file.parent.mkdir()