1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#
# These tests are taken from hcl/parse_test.go
#
from __future__ import print_function
from os.path import join, dirname
import hcl
import json
import pytest
PARSE_FIXTURE_DIR = join(dirname(__file__), 'lex-fixtures')
PARSE_FIXTURES = [
(
"assign_colon.hcl",
False,
),
(
"comment.hcl",
False,
),
(
"list_comma.hcl",
False,
),
(
"list_of_maps.hcl",
False,
),
(
"multiple.hcl",
False,
),
(
"structure.hcl",
False,
),
(
"structure_basic.hcl",
False,
),
(
"structure_empty.hcl",
False,
),
(
"complex.hcl",
False,
),
(
"assign_deep.hcl",
False,
),
(
"types.hcl",
False,
),
(
"structure_comma.hcl",
False,
),
(
"terraform0.12syntax.hcl",
False,
),
(
"conditional_operator.hcl",
False,
),
]
@pytest.mark.parametrize("export_comments", [None, 'LINE', 'MULTILINE', 'ALL'])
@pytest.mark.parametrize("hcl_fname,invalid", PARSE_FIXTURES)
def test_parser_bytes(hcl_fname, invalid, export_comments):
with open(join(PARSE_FIXTURE_DIR, hcl_fname), 'rb') as fp:
input = fp.read()
print(input)
if not invalid:
hcl.loads(input, export_comments)
else:
with pytest.raises(ValueError):
hcl.loads(input, export_comments)
@pytest.mark.parametrize("export_comments", [None, 'LINE', 'MULTILINE', 'ALL'])
@pytest.mark.parametrize("hcl_fname,invalid", PARSE_FIXTURES)
def test_parser_str(hcl_fname, invalid, export_comments):
with open(join(PARSE_FIXTURE_DIR, hcl_fname), 'r') as fp:
input = fp.read()
print(input)
if not invalid:
hcl.loads(input, export_comments)
else:
with pytest.raises(ValueError):
hcl.loads(input, export_comments)
|