-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add adapter-zone test, expand data type coverage
- Loading branch information
1 parent
827e35e
commit 8197fa7
Showing
2 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
tests/adapter/dbt/tests/adapter/unit_testing/test_unit_testing_types.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,84 @@ | ||
import pytest | ||
|
||
from dbt.tests.util import write_file, run_dbt | ||
|
||
|
||
my_model_sql = """ | ||
select | ||
tested_column from {{ ref('my_upstream_model')}} | ||
""" | ||
|
||
my_upstream_model_sql = """ | ||
select | ||
{sql_value} as tested_column | ||
""" | ||
|
||
test_my_model_yml = """ | ||
unit_tests: | ||
- name: test_my_model | ||
model: my_model | ||
given: | ||
- input: ref('my_upstream_model') | ||
rows: | ||
- {{ tested_column: {yaml_value} }} | ||
expect: | ||
rows: | ||
- {{ tested_column: {yaml_value} }} | ||
""" | ||
|
||
|
||
class BaseUnitTestingTypes: | ||
@pytest.fixture | ||
def data_types(self): | ||
# sql_value, yaml_value | ||
return [ | ||
["1", "1"], | ||
["'1'", "1"], | ||
["true", "true"], | ||
["DATE '2020-01-02'", "2020-01-02"], | ||
["TIMESTAMP '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], | ||
["TIMESTAMPTZ '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"], | ||
["ARRAY['a','b','c']", """'{"a", "b", "c"}'"""], | ||
["ARRAY[1,2,3]", """'{1, 2, 3}'"""], | ||
["'1'::numeric", "1"], | ||
[ | ||
"""'{"bar": "baz", "balance": 7.77, "active": false}'::json""", | ||
"""'{"bar": "baz", "balance": 7.77, "active": false}'""", | ||
], | ||
] | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
return { | ||
"my_model.sql": my_model_sql, | ||
"my_upstream_model.sql": my_upstream_model_sql, | ||
"schema.yml": test_my_model_yml, | ||
} | ||
|
||
def test_unit_test_data_type(self, project, data_types): | ||
for (sql_value, yaml_value) in data_types: | ||
# Write parametrized type value to sql files | ||
write_file( | ||
my_upstream_model_sql.format(sql_value=sql_value), | ||
"models", | ||
"my_upstream_model.sql", | ||
) | ||
|
||
# Write parametrized type value to unit test yaml definition | ||
write_file( | ||
test_my_model_yml.format(yaml_value=yaml_value), | ||
"models", | ||
"schema.yml", | ||
) | ||
|
||
results = run_dbt(["run", "--select", "my_upstream_model"]) | ||
assert len(results) == 1 | ||
|
||
try: | ||
run_dbt(["unit-test", "--select", "my_model"]) | ||
except Exception: | ||
raise AssertionError(f"unit test failed when testing model with {sql_value}") | ||
|
||
|
||
class TestUnitTestingTypes(BaseUnitTestingTypes): | ||
pass |