Skip to content

Testing with pyvider-hcl

๐Ÿค– AI-Generated Content

This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.

Test Setup

import pytest
from pyvider.hcl import parse_hcl_to_cty
from pyvider.cty import CtyObject, CtyString

def test_parse_config():
    hcl = 'name = "test"'
    result = parse_hcl_to_cty(hcl)
    assert result.value['name'].value == "test"

Using Fixtures

@pytest.fixture
def sample_hcl():
    return 'name = "test"\nport = 8080'

def test_with_fixture(sample_hcl):
    result = parse_hcl_to_cty(sample_hcl)
    assert 'name' in result.value

Testing with Schemas

def test_schema_validation():
    schema = CtyObject({"port": CtyNumber()})
    hcl = 'port = 8080'
    result = parse_hcl_to_cty(hcl, schema=schema)
    assert result.value['port'].value == 8080

Testing Errors

from pyvider.hcl import HclParsingError

def test_invalid_hcl():
    with pytest.raises(HclParsingError):
        parse_hcl_to_cty('invalid = ')

Property-Based Testing

from hypothesis import given
from hypothesis import strategies as st

@given(st.text())
def test_parse_strings(value):
    hcl = f'key = "{value}"'
    result = parse_hcl_to_cty(hcl)
    assert result.value['key'].value == value

See Also