VZLA
Databricks Employee
Databricks Employee

Thank you for your follow-up question.

Yes, if it helps, this would be a good starting point/demo:

import yaml
import pytest

# Load the data contract
with open('data_contract.yml', 'r') as file:
    data_contract = yaml.safe_load(file)

# Example data product schema
data_product_schema = {
    'name': 'string',
    'age': 'integer',
    'email': 'string'
}

# Test to check alignment between data product and data contract
def test_data_product_alignment():
    for field, field_type in data_contract['schema'].items():
        assert field in data_product_schema, f"Field '{field}' is missing in the data product schema."
        assert data_product_schema[field] == field_type, (
            f"Field '{field}' type mismatch: expected '{field_type}', got '{data_product_schema[field]}'."
        )

# Additional example: check for unexpected fields in the data product
def test_no_unexpected_fields():
    for field in data_product_schema:
        assert field in data_contract['schema'], f"Unexpected field '{field}' found in the data product schema."

if __name__ == '__main__':
    pytest.main()