Skip to content

Commit

Permalink
Add tests for cross-database cast macro (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Alfare <[email protected]>
  • Loading branch information
dbeatty10 and mikealfare authored Apr 19, 2024
1 parent a9f1e14 commit 9cfb21e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240412-192040.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Cross-database `cast` macro
time: 2024-04-12T19:20:40.904842-06:00
custom:
Author: MichelleArk dbeatty10
Issue: "84"
33 changes: 33 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# cast

seeds__data_cast_csv = """field,output
abc,abc
123,123
,
"""


models__test_cast_sql = """
with data as (
select * from {{ ref('data_cast') }}
)
select
{{ cast('field', api.Column.translate_type('string')) }} as actual,
output as expected
from data
"""


models__test_cast_yml = """
version: 2
models:
- name: test_cast
data_tests:
- assert_equal:
actual: actual
expected: expected
"""
23 changes: 23 additions & 0 deletions dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

from dbt.tests.adapter.utils import base_utils, fixture_cast


class BaseCast(base_utils.BaseUtils):
@pytest.fixture(scope="class")
def seeds(self):
return {"data_cast.csv": fixture_cast.seeds__data_cast_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"test_cast.yml": fixture_cast.models__test_cast_yml,
"test_cast.sql": self.interpolate_macro_namespace(
self.interpolate_macro_namespace(fixture_cast.models__test_cast_sql, "cast"),
"type_string",
),
}


class TestCast(BaseCast):
pass

0 comments on commit 9cfb21e

Please sign in to comment.