Skip to content

Commit

Permalink
format test case
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jul 17, 2024
1 parent 2880158 commit cff48c1
Showing 1 changed file with 29 additions and 68 deletions.
97 changes: 29 additions & 68 deletions tests/unit/contracts/files/test_schema_source_file.py
Original file line number Diff line number Diff line change
@@ -1,152 +1,113 @@
from dbt.contracts.files import SchemaSourceFile


def test_fix_metrics_from_measure():
# This is a test for converting "generated_metrics" to "metrics_from_measures"
schema_source_file = {
"path": {
"searched_path": "models",
"relative_path": "schema.yml",
"modification_time": 1721228094.7544806,
"project_root": "/Users/a_user/sample_project"
"project_root": "/Users/a_user/sample_project",
},
"checksum": {
"name": "sha256",
"checksum": "63130d480a44a481aa0adc0a8469dccbb72ea36cc09f06683a584a31339f362e"
"checksum": "63130d480a44a481aa0adc0a8469dccbb72ea36cc09f06683a584a31339f362e",
},
"project_name": "test",
"parse_file_type": "schema",
"dfy": {
"models": [
{
"name": "fct_revenue",
"description": "This is the model fct_revenue."
}
],
"models": [{"name": "fct_revenue", "description": "This is the model fct_revenue."}],
"semantic_models": [
{
"name": "revenue",
"description": "This is the FIRST semantic model.",
"model": "ref('fct_revenue')",
"defaults": {
"agg_time_dimension": "ds"
},
"defaults": {"agg_time_dimension": "ds"},
"measures": [
{
"name": "txn_revenue",
"expr": "revenue",
"agg": "sum",
"agg_time_dimension": "ds",
"create_metric": True
"create_metric": True,
},
{
"name": "sum_of_things",
"expr": 2,
"agg": "sum",
"agg_time_dimension": "ds"
}
"agg_time_dimension": "ds",
},
],
"dimensions": [
{
"name": "ds",
"type": "time",
"expr": "created_at",
"type_params": {
"time_granularity": "day"
}
"type_params": {"time_granularity": "day"},
}
],
"entities": [
{
"name": "user",
"type": "foreign",
"expr": "user_id"
},
{
"name": "id",
"type": "primary"
}
]
{"name": "user", "type": "foreign", "expr": "user_id"},
{"name": "id", "type": "primary"},
],
},
{
"name": "alt_revenue",
"description": "This is the second revenue semantic model.",
"model": "ref('fct_revenue')",
"defaults": {
"agg_time_dimension": "ads"
},
"defaults": {"agg_time_dimension": "ads"},
"measures": [
{
"name": "alt_txn_revenue",
"expr": "revenue",
"agg": "sum",
"agg_time_dimension": "ads",
"create_metric": True
"create_metric": True,
},
{
"name": "alt_sum_of_things",
"expr": 2,
"agg": "sum",
"agg_time_dimension": "ads"
}
"agg_time_dimension": "ads",
},
],
"dimensions": [
{
"name": "ads",
"type": "time",
"expr": "created_at",
"type_params": {
"time_granularity": "day"
}
"type_params": {"time_granularity": "day"},
}
],
"entities": [
{
"name": "user",
"type": "foreign",
"expr": "user_id"
},
{
"name": "id",
"type": "primary"
}
]
}
{"name": "user", "type": "foreign", "expr": "user_id"},
{"name": "id", "type": "primary"},
],
},
],
"metrics": [
{
"name": "simple_metric",
"label": "Simple Metric",
"type": "simple",
"type_params": {
"measure": "sum_of_things"
}
"type_params": {"measure": "sum_of_things"},
}
]
],
},
"data_tests": {},
"metrics": [
"metric.test.simple_metric"
],
"metrics": ["metric.test.simple_metric"],
"generated_metrics": ["metric.test.txn_revenue", "metric.test.alt_txn_revenue"],
"metrics_from_measures": {},
"ndp": [
"model.test.fct_revenue"
],
"semantic_models": [
"semantic_model.test.revenue",
"semantic_model.test.alt_revenue"
],
"ndp": ["model.test.fct_revenue"],
"semantic_models": ["semantic_model.test.revenue", "semantic_model.test.alt_revenue"],
"mcp": {},
"env_vars": {}
"env_vars": {},
}

expected_metrics_from_measures = {
"revenue": [
"metric.test.txn_revenue"
],
"alt_revenue": [
"metric.test.alt_txn_revenue"
]
"revenue": ["metric.test.txn_revenue"],
"alt_revenue": ["metric.test.alt_txn_revenue"],
}
ssf = SchemaSourceFile.from_dict(schema_source_file)
assert ssf
Expand Down

0 comments on commit cff48c1

Please sign in to comment.