Compare commits
No commits in common. "151a92c60be0c0afb1156bf9ef576479ac2d1e18" and "83cd7740795ca42cf3e539e51110f2b7ac4b07b2" have entirely different histories.
151a92c60b
...
83cd774079
20 changed files with 7 additions and 233 deletions
|
|
@ -115,12 +115,8 @@ class RougailOutputHcl(RougailOutputJson):
|
||||||
parent_obj[name] = []
|
parent_obj[name] = []
|
||||||
block_to_insert = parent_obj[name]
|
block_to_insert = parent_obj[name]
|
||||||
block_to_insert.extend(child_obj)
|
block_to_insert.extend(child_obj)
|
||||||
elif parent_is_block and child_obj.get("__is_block__", False):
|
|
||||||
parent_obj.append({name: child_obj})
|
|
||||||
elif parent_is_block:
|
elif parent_is_block:
|
||||||
if not parent_obj:
|
parent_obj.append({name: child_obj})
|
||||||
parent_obj.append({})
|
|
||||||
parent_obj[-1][name] = child_obj
|
|
||||||
else:
|
else:
|
||||||
parent_obj[name] = child_obj
|
parent_obj[name] = child_obj
|
||||||
|
|
||||||
|
|
@ -152,15 +148,6 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ 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
|
||||||
|
|
||||||
|
|
@ -52,18 +51,12 @@ 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:
|
||||||
msg = _('the family "{0}" is a label but there are others family which are not label in same parent family').format(child.path)
|
raise Exception()
|
||||||
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:
|
||||||
msg = _('the family "{0}" is a label but there are others family which are not label in same parent family').format(child.path)
|
raise Exception()
|
||||||
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):
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_block:
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
a_variable: a value
|
|
||||||
...
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
502
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
%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 +0,0 @@
|
||||||
504
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
%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 +0,0 @@
|
||||||
503
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
stack {
|
|
||||||
a_family_1 = {
|
|
||||||
a_variable = "a value"
|
|
||||||
}
|
|
||||||
a_family_2 = {
|
|
||||||
a_variable = "a value"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
stack:
|
|
||||||
hcl_type: block
|
|
||||||
|
|
||||||
a_family_1: # a family 1
|
|
||||||
|
|
||||||
a_variable: a value
|
|
||||||
|
|
||||||
a_family_2: # a family 2
|
|
||||||
|
|
||||||
a_variable: a value
|
|
||||||
...
|
|
||||||
|
|
@ -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)
|
||||||
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 = rougail.run()
|
||||||
config.information.set("description_type", "path_and_description")
|
config.information.set("description_type", "path_and_description")
|
||||||
config.property.read_only()
|
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:
|
||||||
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}'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from rougail.output_hcl import RougailOutputHcl as RougailOutput
|
||||||
from rougail.error import DictConsistencyError
|
from rougail.error import DictConsistencyError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _test_subconfig(error):
|
def _test_subconfig(error):
|
||||||
rougailconfig = RougailConfig.copy()
|
rougailconfig = RougailConfig.copy()
|
||||||
##################################
|
##################################
|
||||||
|
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
from pytest import raises
|
|
||||||
from pathlib import Path
|
|
||||||
from rougail import Rougail, RougailConfig
|
|
||||||
from rougail.output_hcl import RougailOutputHcl as RougailOutput
|
|
||||||
from rougail.error import DictConsistencyError
|
|
||||||
|
|
||||||
|
|
||||||
def _test_types(name):
|
|
||||||
rougailconfig = RougailConfig.copy()
|
|
||||||
##################################
|
|
||||||
rougailconfig['step.output'] = 'hcl'
|
|
||||||
rougailconfig["main_namespace"] = None
|
|
||||||
rougailconfig["types"] = [str((Path(__file__).parent / 'types' / name / 'types').absolute())]
|
|
||||||
rougailconfig["main_structural_directories"] = [str((Path(__file__).parent / 'types' / name / 'structures').absolute())]
|
|
||||||
##################################
|
|
||||||
rougail = Rougail(rougailconfig)
|
|
||||||
config = rougail.run()
|
|
||||||
config.information.set("description_type", "path_and_description")
|
|
||||||
config.property.read_only()
|
|
||||||
generated_output = RougailOutput(config, rougailconfig=rougailconfig).run()[1]
|
|
||||||
output_file = Path(__file__).parent / 'types' / name / 'rougail.hcl'
|
|
||||||
if not output_file.is_file():
|
|
||||||
if not output_file.parent.is_dir():
|
|
||||||
output_file.parent.mkdir()
|
|
||||||
with output_file.open('w') as outfh:
|
|
||||||
outfh.write(generated_output)
|
|
||||||
with output_file.open() as outfh:
|
|
||||||
attented_output = outfh.read()
|
|
||||||
assert generated_output == attented_output, f'filename {output_file}'
|
|
||||||
|
|
||||||
|
|
||||||
def test_types_01():
|
|
||||||
_test_types('01-types')
|
|
||||||
|
|
||||||
|
|
||||||
def test_types_02():
|
|
||||||
_test_types('02-double')
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
a_new_block_1 "a_label" {
|
|
||||||
an_attribute = "a value"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
a_new_block_2 "a_label" {
|
|
||||||
an_attribute = "a value"
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_new_block_1:
|
|
||||||
type: a_block
|
|
||||||
|
|
||||||
a_new_block_2:
|
|
||||||
hcl_type: block
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
type: a_label
|
|
||||||
...
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_block:
|
|
||||||
description: A block is a family with hcl_type attribute
|
|
||||||
hcl_type: block
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
description: A label is also a family with hcl_type attribute
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
an_attribute: a value # An attribute in a block
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
description: A label is also a family with hcl_type attribute
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
an_attribute: a value # An attribute in a block
|
|
||||||
...
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
a_new_block_1 "a_label" {
|
|
||||||
an_attribute = "a value new"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
a_new_block_2 "a_label" {
|
|
||||||
an_attribute = "a value new"
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_new_block_1:
|
|
||||||
type: a_block
|
|
||||||
|
|
||||||
a_new_block_2:
|
|
||||||
hcl_type: block
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
type: a_label
|
|
||||||
...
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_block_ori:
|
|
||||||
description: A block is a family with hcl_type attribute
|
|
||||||
hcl_type: block
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
description: A label is also a family with hcl_type attribute
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
an_attribute: a value # An attribute in a block
|
|
||||||
|
|
||||||
a_label_ori:
|
|
||||||
description: A label is also a family with hcl_type attribute
|
|
||||||
hcl_type: label
|
|
||||||
|
|
||||||
an_attribute: a value # An attribute in a block
|
|
||||||
...
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
%YAML 1.2
|
|
||||||
---
|
|
||||||
version: 1.1
|
|
||||||
|
|
||||||
a_block:
|
|
||||||
type: a_block_ori
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
|
|
||||||
an_attribute: a value new
|
|
||||||
|
|
||||||
a_label:
|
|
||||||
type: a_label_ori
|
|
||||||
|
|
||||||
an_attribute: a value new
|
|
||||||
...
|
|
||||||
Loading…
Reference in a new issue