fix: add double types tests
This commit is contained in:
parent
83cd774079
commit
b3acb51625
9 changed files with 135 additions and 1 deletions
|
|
@ -5,7 +5,6 @@ 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()
|
||||||
##################################
|
##################################
|
||||||
|
|
|
||||||
37
tests/test_types.py
Normal file
37
tests/test_types.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
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')
|
||||||
8
tests/types/01-types/rougail.hcl
Normal file
8
tests/types/01-types/rougail.hcl
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
a_new_block_1 "a_label" {
|
||||||
|
an_attribute = "a value"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
a_new_block_2 "a_label" {
|
||||||
|
an_attribute = "a value"
|
||||||
|
}
|
||||||
13
tests/types/01-types/structures/00-main.yml
Normal file
13
tests/types/01-types/structures/00-main.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
%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
|
||||||
|
...
|
||||||
20
tests/types/01-types/types/00-main.yml
Normal file
20
tests/types/01-types/types/00-main.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
%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
|
||||||
|
...
|
||||||
8
tests/types/02-double/rougail.hcl
Normal file
8
tests/types/02-double/rougail.hcl
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
a_new_block_1 "a_label" {
|
||||||
|
an_attribute = "a value new"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
a_new_block_2 "a_label" {
|
||||||
|
an_attribute = "a value new"
|
||||||
|
}
|
||||||
13
tests/types/02-double/structures/00-main.yml
Normal file
13
tests/types/02-double/structures/00-main.yml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
%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
|
||||||
|
...
|
||||||
20
tests/types/02-double/types/00-main.yml
Normal file
20
tests/types/02-double/types/00-main.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
%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
|
||||||
|
...
|
||||||
16
tests/types/02-double/types/10-main.yml
Normal file
16
tests/types/02-double/types/10-main.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
%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