Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamDee committed Nov 12, 2024
1 parent 9f2a8ed commit 6983d64
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
8 changes: 8 additions & 0 deletions core/dbt/artifacts/resources/v1/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class MetricTimeWindow(dbtClassMixin):
count: int
granularity: str

@property
def window_string(self) -> str: # noqa: D
return f"{self.count} {self.granularity}"

@property
def is_standard_granularity(self) -> bool: # noqa: D
return self.granularity.casefold() in {item.value.casefold() for item in TimeGranularity}


@dataclass
class MetricInput(dbtClassMixin):
Expand Down
11 changes: 11 additions & 0 deletions core/dbt/artifacts/resources/v1/semantic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
"""


@dataclass
class SemanticLayerElementConfig(dbtClassMixin):
meta: Dict[str, Any] = field(
default_factory=dict,
metadata=MergeBehavior.Update.meta(),
)


@dataclass
class Defaults(dbtClassMixin):
agg_time_dimension: Optional[str] = None
Expand Down Expand Up @@ -72,6 +80,7 @@ class Dimension(dbtClassMixin):
type_params: Optional[DimensionTypeParams] = None
expr: Optional[str] = None
metadata: Optional[SourceFileMetadata] = None
config: Optional[SemanticLayerElementConfig] = None

@property
def reference(self) -> DimensionReference:
Expand Down Expand Up @@ -106,6 +115,7 @@ class Entity(dbtClassMixin):
label: Optional[str] = None
role: Optional[str] = None
expr: Optional[str] = None
config: Optional[SemanticLayerElementConfig] = None

@property
def reference(self) -> EntityReference:
Expand Down Expand Up @@ -147,6 +157,7 @@ class Measure(dbtClassMixin):
agg_params: Optional[MeasureAggregationParameters] = None
non_additive_dimension: Optional[NonAdditiveDimension] = None
agg_time_dimension: Optional[str] = None
config: Optional[SemanticLayerElementConfig] = None

@property
def reference(self) -> MeasureReference:
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/metrics/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_simple_metric(
)
assert (
manifest.metrics["metric.test.number_of_people"].time_granularity
== TimeGranularity.MONTH
== TimeGranularity.MONTH.value
)
assert manifest.metrics["metric.test.collective_tenure"].time_granularity is None

Expand Down Expand Up @@ -436,25 +436,25 @@ def test_cumulative_metric(self, project):
metric_ids = set(manifest.metrics.keys())
expected_metric_ids_to_cumulative_type_params = {
"metric.test.weekly_visits": CumulativeTypeParams(
window=MetricTimeWindow(count=7, granularity=TimeGranularity.DAY),
window=MetricTimeWindow(count=7, granularity=TimeGranularity.DAY.value),
period_agg=PeriodAggregation.AVERAGE,
),
"metric.test.cumulative_orders": CumulativeTypeParams(
period_agg=PeriodAggregation.LAST
),
"metric.test.orders_ytd": CumulativeTypeParams(
grain_to_date=TimeGranularity.YEAR, period_agg=PeriodAggregation.FIRST
grain_to_date=TimeGranularity.YEAR.value, period_agg=PeriodAggregation.FIRST
),
"metric.test.monthly_orders": CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH),
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH.value),
period_agg=PeriodAggregation.AVERAGE,
),
"metric.test.yearly_orders": CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.YEAR),
window=MetricTimeWindow(count=1, granularity=TimeGranularity.YEAR.value),
period_agg=PeriodAggregation.FIRST,
),
"metric.test.visits_mtd": CumulativeTypeParams(
grain_to_date=TimeGranularity.MONTH, period_agg=PeriodAggregation.FIRST
grain_to_date=TimeGranularity.MONTH.value, period_agg=PeriodAggregation.FIRST
),
"metric.test.cumulative_visits": CumulativeTypeParams(
period_agg=PeriodAggregation.FIRST
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/contracts/graph/test_semantic_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
),
(
MetricTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH)
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH.value)
),
1,
False,
Expand All @@ -75,7 +75,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
grain_to_date=TimeGranularity.MONTH,
grain_to_date=TimeGranularity.MONTH.value,
)
),
0,
Expand All @@ -85,7 +85,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH),
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH.value),
)
),
0,
Expand All @@ -100,7 +100,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
),
(
MetricTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH)
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH.value)
),
0,
True,
Expand All @@ -109,7 +109,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
grain_to_date=TimeGranularity.MONTH,
grain_to_date=TimeGranularity.MONTH.value,
)
),
0,
Expand All @@ -119,7 +119,7 @@ def test_require_yaml_configuration_for_mf_time_spines(
(
MetricTypeParams(
cumulative_type_params=CumulativeTypeParams(
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH),
window=MetricTimeWindow(count=1, granularity=TimeGranularity.MONTH.value),
)
),
0,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_semantic_layer_nodes_satisfy_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def where_filter() -> WhereFilter:

@pytest.fixture(scope="session")
def metric_time_window() -> MetricTimeWindow:
return MetricTimeWindow(count=1, granularity=TimeGranularity.DAY)
return MetricTimeWindow(count=1, granularity=TimeGranularity.DAY.value)


@pytest.fixture(scope="session")
Expand All @@ -211,7 +211,7 @@ def complex_metric_input(metric_time_window, where_filter) -> MetricInput:
filter=where_filter,
alias="aliased_metric_input",
offset_window=metric_time_window,
offset_to_grain=TimeGranularity.DAY,
offset_to_grain=TimeGranularity.DAY.value,
)


Expand Down

0 comments on commit 6983d64

Please sign in to comment.