-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add adapter tests for
date_spine
macro
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
tests/adapter/dbt/tests/adapter/utils/fixture_date_spine.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# If date_spine works properly, there should be no `null` values in the resulting model | ||
|
||
models__test_date_spine_sql = """ | ||
with generated_dates as ( | ||
{{ date_spine("day", "'2023-09-01'::date", "'2023-09-10'::date") }} | ||
), expected_dates as ( | ||
select '2023-09-01'::date as expected | ||
union all | ||
select '2023-09-02'::date as expected | ||
union all | ||
select '2023-09-03'::date as expected | ||
union all | ||
select '2023-09-04'::date as expected | ||
union all | ||
select '2023-09-05'::date as expected | ||
union all | ||
select '2023-09-06'::date as expected | ||
union all | ||
select '2023-09-07'::date as expected | ||
union all | ||
select '2023-09-08'::date as expected | ||
union all | ||
select '2023-09-09'::date as expected | ||
), joined as ( | ||
select | ||
generated_dates.date_day, | ||
expected_dates.expected | ||
from generated_dates | ||
left join expected_dates on generated_dates.date_day = expected_dates.expected | ||
) | ||
SELECT * from joined | ||
""" | ||
|
||
models__test_date_spine_yml = """ | ||
version: 2 | ||
models: | ||
- name: test_date_spine | ||
tests: | ||
- assert_equal: | ||
actual: date_day | ||
expected: expected | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from dbt.tests.adapter.utils.base_utils import BaseUtils | ||
from dbt.tests.adapter.utils.fixture_date_spine import ( | ||
models__test_date_spine_sql, | ||
models__test_date_spine_yml, | ||
) | ||
|
||
|
||
class BaseDateSpine(BaseUtils): | ||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"test_date_spine.yml": models__test_date_spine_yml, | ||
"test_date_spine.sql": self.interpolate_macro_namespace( | ||
models__test_date_spine_sql, "date_spine" | ||
), | ||
} | ||
|
||
|
||
class TestDateSpine(BaseDateSpine): | ||
pass |