-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adap 821/unit tests infer wrong datatype for None values in fixtures (#…
…885) * Add test to confirm upstream handling * Add changelog. * Add another test. * standardize names to reflect python objects. * revert dev requirements. * Add the macro for the row checking. * Test for user facing exception thrown in base adapter with new redshift macor. * revert the dev requirements --------- Co-authored-by: Mila Page <[email protected]> Co-authored-by: Mike Alfare <[email protected]>
- Loading branch information
1 parent
f261d17
commit a1f33db
Showing
4 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Fixes | ||
body: 'Handle unit test fixtures where typing goes wrong from first value in column | ||
being Null. ' | ||
time: 2024-06-25T17:03:24.73937-07:00 | ||
custom: | ||
Author: versusfacit | ||
Issue: "821" |
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,11 @@ | ||
{%- macro redshift__validate_fixture_rows(rows, row_number) -%} | ||
{%- if rows is not none and rows|length > 0 -%} | ||
{%- set row = rows[0] -%} | ||
{%- for key, value in row.items() -%} | ||
{%- if value is none -%} | ||
{%- set fixture_name = "expected output" if model.resource_type == 'unit_test' else ("'" ~ model.name ~ "'") -%} | ||
{{ exceptions.raise_compiler_error("Unit test fixture " ~ fixture_name ~ " in " ~ model.name ~ " does not have any row free of null values, which may cause type mismatch errors during unit test execution.") }} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
{%- endmacro -%} |
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,73 @@ | ||
model_none_value_base = """ | ||
{{ config(materialized="table") }} | ||
select 1 as id, 'a' as col1 | ||
""" | ||
|
||
model_none_value_model = """ | ||
{{config(materialized="table")}} | ||
select * from {{ ref('none_value_base') }} | ||
""" | ||
|
||
|
||
test_none_column_value_doesnt_throw_error_csv = """ | ||
unit_tests: | ||
- name: test_simple | ||
model: none_value_model | ||
given: | ||
- input: ref('none_value_base') | ||
format: csv | ||
rows: | | ||
id,col1 | ||
,d | ||
,e | ||
6,f | ||
expect: | ||
format: csv | ||
rows: | | ||
id,col1 | ||
,d | ||
,e | ||
6,f | ||
""" | ||
|
||
test_none_column_value_doesnt_throw_error_dct = """ | ||
unit_tests: | ||
- name: test_simple | ||
model: none_value_model | ||
given: | ||
- input: ref('none_value_base') | ||
rows: | ||
- { "id": , "col1": "d"} | ||
- { "id": , "col1": "e"} | ||
- { "id": 6, "col1": "f"} | ||
expect: | ||
rows: | ||
- {id: , "col1": "d"} | ||
- {id: , "col1": "e"} | ||
- {id: 6, "col1": "f"} | ||
""" | ||
|
||
test_none_column_value_will_throw_error = """ | ||
unit_tests: | ||
- name: test_simple | ||
model: none_value_model | ||
given: | ||
- input: ref('none_value_base') | ||
rows: | ||
- { "id": , "col1": "d"} | ||
- { "id": , "col1": "e"} | ||
- { "id": 6, "col1": } | ||
expect: | ||
rows: | ||
- {id: , "col1": "d"} | ||
- {id: , "col1": "e"} | ||
- {id: 6, "col1": } | ||
""" |
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