Skip to content

Commit

Permalink
Add tests for MetricLookup linkable element extractors
Browse files Browse the repository at this point in the history
These methods in the MetricLookup class have behavior that
is somewhat difficult to reason about, and having a test that
both illustrates the output expectations for a given call and
provides some assurance that these accessors retain consistent
behavior is worthwhile.

This commit adds the missing test with a small filter. If this
becomes noisy we should move the semantic model container tests
off of the simple model and onto something less subject to change
(and also something with fewer join links).

The test for getting linkable elements for measure is also moved
under the metric accessor test suite, because the current API
sequencing suggests that the MetricLookup class is what we wish
to rely on, while the ValidLinkableSpecResolver implementation is
more fungible. This way, we ensure that the method we actually
use is covered without duplicating the pass through test in two
locations.
  • Loading branch information
tlento committed Apr 11, 2024
1 parent eff82e8 commit 3356dae
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 18 deletions.
18 changes: 0 additions & 18 deletions tests/model/semantics/test_linkable_spec_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,6 @@ def test_create_linkable_element_set_from_join_path_multi_hop( # noqa: D103
)


def test_get_linkable_element_set_for_measure(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
simple_model_spec_resolver: ValidLinkableSpecResolver,
) -> None:
"""Tests extracting linkable elements for a given measure input."""
assert_linkable_element_set_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
set_id="result0",
linkable_element_set=simple_model_spec_resolver.get_linkable_element_set_for_measure(
measure_reference=MeasureReference(element_name="listings"),
with_any_of=LinkableElementProperties.all_properties(),
without_any_of=frozenset({}),
),
)


def test_linkable_element_set_as_spec_set(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
Expand Down
36 changes: 36 additions & 0 deletions tests/model/test_semantic_model_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,42 @@ def test_linkable_elements_for_metrics( # noqa: D103
)


def test_linkable_elements_for_measure(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
metric_lookup: MetricLookup,
) -> None:
"""Tests extracting linkable elements for a given measure input."""
assert_linkable_element_set_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
set_id="result0",
linkable_element_set=metric_lookup.linkable_elements_for_measure(
measure_reference=MeasureReference(element_name="listings"),
),
)


def test_linkable_elements_for_no_metrics_query(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
metric_lookup: MetricLookup,
) -> None:
"""Tests extracting linkable elements for a dimension values query with no metrics."""
linkable_elements = metric_lookup.linkable_elements_for_no_metrics_query(
without_any_of={
LinkableElementProperties.DERIVED_TIME_GRANULARITY,
}
)
sorted_specs = sorted(linkable_elements.as_spec_set.as_tuple, key=lambda x: x.qualified_name)
assert_object_snapshot_equal(
request=request,
mf_test_configuration=mf_test_configuration,
obj_id="result0",
obj=tuple(spec.qualified_name for spec in sorted_specs),
)


def test_linkable_set_for_common_dimensions_in_different_models(
request: FixtureRequest, mf_test_configuration: MetricFlowTestConfiguration, metric_lookup: MetricLookup
) -> None:
Expand Down
Loading

0 comments on commit 3356dae

Please sign in to comment.