Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add semantic model test to test_contracts_graph_parsed.py #8654

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ docutils
flake8
flaky
freezegun==0.3.12
hypothesis
ipdb
mypy==1.4.1
pip-tools
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pickle
import pytest

from hypothesis import given
from hypothesis.strategies import builds, lists

from dbt.node_types import NodeType, AccessType
from dbt.contracts.files import FileHash
from dbt.contracts.graph.model_config import (
Expand Down Expand Up @@ -34,7 +37,10 @@
HookNode,
Owner,
TestMetadata,
SemanticModel,
RefArgs,
)
from dbt.contracts.graph.semantic_models import Dimension, Entity, Measure
from dbt.contracts.graph.unparsed import (
ExposureType,
FreshnessThreshold,
Expand Down Expand Up @@ -2354,3 +2360,18 @@ def basic_parsed_metric_object():
meta={},
tags=[],
)


@given(
builds(
SemanticModel,
depends_on=builds(DependsOn),
dimensions=lists(builds(Dimension)),
entities=lists(builds(Entity)),
measures=lists(builds(Measure)),
refs=lists(builds(RefArgs)),
)
)
def test_semantic_model_symmetry(semantic_model: SemanticModel):
assert semantic_model == SemanticModel.from_dict(semantic_model.to_dict())
assert semantic_model == pickle.loads(pickle.dumps(semantic_model))