diff --git a/src/rougail/output_hcl/export.py b/src/rougail/output_hcl/export.py index d4223e7..9017355 100644 --- a/src/rougail/output_hcl/export.py +++ b/src/rougail/output_hcl/export.py @@ -152,6 +152,15 @@ class RougailOutputHcl(RougailOutputJson): child_obj["__is_block__"] = True quote_name = True 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 return quote_name diff --git a/src/rougail/structural_hcl/annotator.py b/src/rougail/structural_hcl/annotator.py index ca0a345..e3251c9 100644 --- a/src/rougail/structural_hcl/annotator.py +++ b/src/rougail/structural_hcl/annotator.py @@ -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 """ +from .i18n import _ from rougail.annotator.variable import Walk from rougail.error import DictConsistencyError @@ -51,12 +52,18 @@ class Annotator(Walk): information_value = None if hasattr(child, "hcl_type") and child.hcl_type == "label": if is_label == False: - raise Exception() + msg = _('the family "{0}" is a label but there are others family which are not label in same parent family').format(child.path) + raise DictConsistencyError( + msg, 504, child.xmlfiles + ) information_value = "label" is_label = True sub_is_block = True elif is_label: - raise Exception() + msg = _('the family "{0}" is a label but there are others family which are not label in same parent family').format(child.path) + raise DictConsistencyError( + msg, 503, child.xmlfiles + ) else: is_label = False if self.parse_family(child_path, sub_is_block): diff --git a/tests/errors/10-label-inside-label.yaml b/tests/errors/10-label-inside-label.yaml new file mode 100644 index 0000000..fa6ea14 --- /dev/null +++ b/tests/errors/10-label-inside-label.yaml @@ -0,0 +1,12 @@ +%YAML 1.2 +--- +version: 1.1 + +a_block: + hcl_type: label + + a_label: + hcl_type: label + + a_variable: a value +... diff --git a/tests/errors/10-label-inside-label.yaml.errno b/tests/errors/10-label-inside-label.yaml.errno new file mode 100644 index 0000000..cc5027e --- /dev/null +++ b/tests/errors/10-label-inside-label.yaml.errno @@ -0,0 +1 @@ +502 diff --git a/tests/errors/10-mix-block-label.yaml b/tests/errors/10-mix-block-label.yaml new file mode 100644 index 0000000..889749f --- /dev/null +++ b/tests/errors/10-mix-block-label.yaml @@ -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 +... diff --git a/tests/errors/10-mix-block-label.yaml.errno b/tests/errors/10-mix-block-label.yaml.errno new file mode 100644 index 0000000..3091e8e --- /dev/null +++ b/tests/errors/10-mix-block-label.yaml.errno @@ -0,0 +1 @@ +504 diff --git a/tests/errors/10-mix-label-block.yaml b/tests/errors/10-mix-label-block.yaml new file mode 100644 index 0000000..74e55dc --- /dev/null +++ b/tests/errors/10-mix-label-block.yaml @@ -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 +... diff --git a/tests/errors/10-mix-label-block.yaml.errno b/tests/errors/10-mix-label-block.yaml.errno new file mode 100644 index 0000000..a712e76 --- /dev/null +++ b/tests/errors/10-mix-label-block.yaml.errno @@ -0,0 +1 @@ +503 diff --git a/tests/test_error.py b/tests/test_error.py index c645646..567fdc8 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -29,12 +29,12 @@ def _test_structural_files(test_file, ext): rougailconfig["main_structural_directories"] = [str(test_file.absolute())] ################################## 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: error_no = int(fh.read().strip()) 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] assert err.value.errno == error_no, f'expected errno: {error_no}, errno: {err.value.errno}, msg: {err}'