fix: better label block validation
This commit is contained in:
parent
2245638a8d
commit
fb21ae4dca
12 changed files with 91 additions and 12 deletions
|
|
@ -6,8 +6,8 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: \n"
|
"Project-Id-Version: \n"
|
||||||
"POT-Creation-Date: 2026-07-06 16:47+0200\n"
|
"POT-Creation-Date: 2026-09-08 09:55+0200\n"
|
||||||
"PO-Revision-Date: 2026-07-06 16:47+0200\n"
|
"PO-Revision-Date: 2026-09-08 09:56+0200\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: \n"
|
||||||
"Language-Team: \n"
|
"Language-Team: \n"
|
||||||
"Language: fr\n"
|
"Language: fr\n"
|
||||||
|
|
@ -17,15 +17,24 @@ msgstr ""
|
||||||
"Generated-By: pygettext.py 1.5\n"
|
"Generated-By: pygettext.py 1.5\n"
|
||||||
"X-Generator: Poedit 3.9\n"
|
"X-Generator: Poedit 3.9\n"
|
||||||
|
|
||||||
#: src/rougail/output_hcl/export.py:130
|
#: src/rougail/output_hcl/export.py:134
|
||||||
msgid "The family \"{0}\" has a hcl_type parameter but is not in a root config"
|
msgid "The family \"{0}\" has a hcl_type parameter but is not in a root config"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"La famille \"{0}\" has le paramètre hcl_type mais n'est pas dans la config "
|
"La famille \"{0}\" has le paramètre hcl_type mais n'est pas dans la config "
|
||||||
"racine"
|
"racine"
|
||||||
|
|
||||||
#: src/rougail/output_hcl/export.py:142
|
#: src/rougail/output_hcl/export.py:146 src/rougail/output_hcl/export.py:158
|
||||||
msgid ""
|
msgid ""
|
||||||
"The family \"{0}\" has a hcl_type parameter to label but is not in a block"
|
"The family \"{0}\" has a hcl_type parameter to label but is not in a block"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"La famille \"{0}\" has le paramètre hcl_type à label mais n'est pas dans un "
|
"La famille \"{0}\" has le paramètre hcl_type à label mais n'est pas dans un "
|
||||||
"block"
|
"block"
|
||||||
|
|
||||||
|
#: src/rougail/structural_hcl/annotator.py:55
|
||||||
|
#: src/rougail/structural_hcl/annotator.py:63
|
||||||
|
msgid ""
|
||||||
|
"the family \"{0}\" is a label but there are others families which are not "
|
||||||
|
"label in same parent family"
|
||||||
|
msgstr ""
|
||||||
|
"la famille \"{0}\" est un label mais il y a d'autres familles qui ne sont "
|
||||||
|
"pas des labels dans la même famille parente"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"POT-Creation-Date: 2026-07-06 16:48+0200\n"
|
"POT-Creation-Date: 2026-09-08 09:56+0200\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
@ -15,11 +15,16 @@ msgstr ""
|
||||||
"Generated-By: pygettext.py 1.5\n"
|
"Generated-By: pygettext.py 1.5\n"
|
||||||
|
|
||||||
|
|
||||||
#: src/rougail/output_hcl/export.py:130
|
#: src/rougail/output_hcl/export.py:134
|
||||||
msgid "The family \"{0}\" has a hcl_type parameter but is not in a root config"
|
msgid "The family \"{0}\" has a hcl_type parameter but is not in a root config"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/rougail/output_hcl/export.py:142
|
#: src/rougail/output_hcl/export.py:146 src/rougail/output_hcl/export.py:158
|
||||||
msgid "The family \"{0}\" has a hcl_type parameter to label but is not in a block"
|
msgid "The family \"{0}\" has a hcl_type parameter to label but is not in a block"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/structural_hcl/annotator.py:55
|
||||||
|
#: src/rougail/structural_hcl/annotator.py:63
|
||||||
|
msgid "the family \"{0}\" is a label but there are others families which are not label in same parent family"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,15 @@ class RougailOutputHcl(RougailOutputJson):
|
||||||
child_obj["__is_block__"] = True
|
child_obj["__is_block__"] = True
|
||||||
quote_name = True
|
quote_name = True
|
||||||
elif hcl_type == "label_with_label":
|
elif hcl_type == "label_with_label":
|
||||||
|
if self.config == parent or not parent.information.get(
|
||||||
|
"hcl_type", None
|
||||||
|
):
|
||||||
|
msg = _(
|
||||||
|
'The family "{0}" has a hcl_type parameter to label but is not in a block'
|
||||||
|
).format(child.path())
|
||||||
|
raise DictConsistencyError(
|
||||||
|
msg, 502, child.information.get("ymlfiles", None)
|
||||||
|
)
|
||||||
quote_name = True
|
quote_name = True
|
||||||
return quote_name
|
return quote_name
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -19,6 +19,7 @@ along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from .i18n import _
|
||||||
from rougail.annotator.variable import Walk
|
from rougail.annotator.variable import Walk
|
||||||
from rougail.error import DictConsistencyError
|
from rougail.error import DictConsistencyError
|
||||||
|
|
||||||
|
|
@ -51,12 +52,18 @@ class Annotator(Walk):
|
||||||
information_value = None
|
information_value = None
|
||||||
if hasattr(child, "hcl_type") and child.hcl_type == "label":
|
if hasattr(child, "hcl_type") and child.hcl_type == "label":
|
||||||
if is_label == False:
|
if is_label == False:
|
||||||
raise Exception()
|
msg = _('the family "{0}" is a label but there are others families which are not label in same parent family').format(child.path)
|
||||||
|
raise DictConsistencyError(
|
||||||
|
msg, 504, child.xmlfiles
|
||||||
|
)
|
||||||
information_value = "label"
|
information_value = "label"
|
||||||
is_label = True
|
is_label = True
|
||||||
sub_is_block = True
|
sub_is_block = True
|
||||||
elif is_label:
|
elif is_label:
|
||||||
raise Exception()
|
msg = _('the family "{0}" is a label but there are others families which are not label in same parent family').format(child.path)
|
||||||
|
raise DictConsistencyError(
|
||||||
|
msg, 503, child.xmlfiles
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
is_label = False
|
is_label = False
|
||||||
if self.parse_family(child_path, sub_is_block):
|
if self.parse_family(child_path, sub_is_block):
|
||||||
|
|
|
||||||
12
tests/errors/10-label-inside-label.yaml
Normal file
12
tests/errors/10-label-inside-label.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
a_block:
|
||||||
|
hcl_type: label
|
||||||
|
|
||||||
|
a_label:
|
||||||
|
hcl_type: label
|
||||||
|
|
||||||
|
a_variable: a value
|
||||||
|
...
|
||||||
1
tests/errors/10-label-inside-label.yaml.errno
Normal file
1
tests/errors/10-label-inside-label.yaml.errno
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
502
|
||||||
17
tests/errors/10-mix-block-label.yaml
Normal file
17
tests/errors/10-mix-block-label.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
a_block:
|
||||||
|
hcl_type: block
|
||||||
|
|
||||||
|
a_block:
|
||||||
|
hcl_type: block
|
||||||
|
|
||||||
|
a_variable: a value
|
||||||
|
|
||||||
|
a_label:
|
||||||
|
hcl_type: label
|
||||||
|
|
||||||
|
a_variable: a value
|
||||||
|
...
|
||||||
1
tests/errors/10-mix-block-label.yaml.errno
Normal file
1
tests/errors/10-mix-block-label.yaml.errno
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
504
|
||||||
17
tests/errors/10-mix-label-block.yaml
Normal file
17
tests/errors/10-mix-label-block.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
a_block:
|
||||||
|
hcl_type: block
|
||||||
|
|
||||||
|
a_label:
|
||||||
|
hcl_type: label
|
||||||
|
|
||||||
|
a_variable: a value
|
||||||
|
|
||||||
|
a_block:
|
||||||
|
hcl_type: block
|
||||||
|
|
||||||
|
a_variable: a value
|
||||||
|
...
|
||||||
1
tests/errors/10-mix-label-block.yaml.errno
Normal file
1
tests/errors/10-mix-label-block.yaml.errno
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
503
|
||||||
|
|
@ -29,12 +29,12 @@ def _test_structural_files(test_file, ext):
|
||||||
rougailconfig["main_structural_directories"] = [str(test_file.absolute())]
|
rougailconfig["main_structural_directories"] = [str(test_file.absolute())]
|
||||||
##################################
|
##################################
|
||||||
rougail = Rougail(rougailconfig)
|
rougail = Rougail(rougailconfig)
|
||||||
config = rougail.run()
|
|
||||||
config.information.set("description_type", "path_and_description")
|
|
||||||
config.property.read_only()
|
|
||||||
with Path(str(test_file.absolute()) + ".errno").open() as fh:
|
with Path(str(test_file.absolute()) + ".errno").open() as fh:
|
||||||
error_no = int(fh.read().strip())
|
error_no = int(fh.read().strip())
|
||||||
with raises(DictConsistencyError) as err:
|
with raises(DictConsistencyError) as err:
|
||||||
|
config = rougail.run()
|
||||||
|
config.information.set("description_type", "path_and_description")
|
||||||
|
config.property.read_only()
|
||||||
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
||||||
assert err.value.errno == error_no, f'expected errno: {error_no}, errno: {err.value.errno}, msg: {err}'
|
assert err.value.errno == error_no, f'expected errno: {error_no}, errno: {err.value.errno}, msg: {err}'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue