From 9d478ab76adf5016f98ae98fa4684f85c5ea7e96 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 29 Sep 2025 10:47:05 +0200 Subject: [PATCH] feat: remove json.read_write option --- src/rougail/output_json/__init__.py | 15 +++++---------- src/rougail/output_json/config.py | 14 ++++++++------ tests/test_load.py | 5 ++++- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/rougail/output_json/__init__.py b/src/rougail/output_json/__init__.py index e34e3d2..e6f6677 100644 --- a/src/rougail/output_json/__init__.py +++ b/src/rougail/output_json/__init__.py @@ -57,7 +57,6 @@ class RougailOutputJson: self.warnings = user_data_warnings else: self.warnings = [] - self.read_write = self.rougailconfig["json.read_write"] self.is_mandatory = self.rougailconfig["json.mandatory"] self.get = self.rougailconfig["json.get"] self.dico = {} @@ -76,14 +75,14 @@ class RougailOutputJson: return ret def exporter(self) -> None: - self.config.property.read_write() - self.mandatory() - self.config.property.read_only() + if self.is_mandatory: + ori_properties = self.config.property.exportation() + self.config.property.read_write() + self.mandatory() + self.config.property.importation(ori_properties) if self.manage_errors(): return False self.manage_warnings() - if self.read_write: - self.config.property.read_write() if self.get: config = self.config.option(self.get) if not config.isoptiondescription(): @@ -98,8 +97,6 @@ class RougailOutputJson: return True def mandatory(self): - if not self.is_mandatory: - return title = False options_with_error = [] try: @@ -114,7 +111,6 @@ class RougailOutputJson: try: option.value.get() if not title: - # self.errors.append("Les variables suivantes sont obligatoires mais n'ont pas de valeur :") self.errors.append( _("The following variables are mandatory but have no value:") ) @@ -125,7 +121,6 @@ class RougailOutputJson: if not title: for idx, option in enumerate(options_with_error): if not idx: - # self.errors.append("Les variables suivantes sont inaccessibles mais sont vides et obligatoires :") self.errors.append( _( "The following variables are inaccessible but are empty and mandatory :" diff --git a/src/rougail/output_json/config.py b/src/rougail/output_json/config.py index ca0c199..281461d 100644 --- a/src/rougail/output_json/config.py +++ b/src/rougail/output_json/config.py @@ -28,19 +28,21 @@ def get_rougail_config( json: description: {_('configuration rougail-json')} disabled: - type: jinja jinja: | {{% if step.output is propertyerror or step.output != 'json' %}} disabled {{% endif %}} - read_write: - description: {_('display variables available in read_write mode')} - default: false - mandatory: description: {_('test mandatories variables before display in json')} - default: true + type: boolean + default: + jinja: |- + {{% if cli.read_write is defined and cli.read_write %}} + false + {{% else %}} + true + {{% endif %}} get: description: {_('get value for a variable or a family')} diff --git a/tests/test_load.py b/tests/test_load.py index 4ccc8a5..2af3279 100644 --- a/tests/test_load.py +++ b/tests/test_load.py @@ -34,7 +34,6 @@ def _test_structural_files(test_dir, namespace, ext, *, read_write=True, mandato return ################################## rougailconfig['step.output'] = 'json' - rougailconfig["json.read_write"] = read_write rougailconfig["json.mandatory"] = mandatory ################################## dir_name = 'test' @@ -56,6 +55,10 @@ def _test_structural_files(test_dir, namespace, ext, *, read_write=True, mandato if do_calc and (mandatory or not read_write): get_values_for_config(config) ################################## + if read_write: + config.property.read_write() + else: + config.property.read_only() generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1] output_file = Path(__file__).parent / 'results' / dir_name / (test_dir.name + "." + ext) if not output_file.is_file():