Skip to content

Commit

Permalink
Refactored the test blocks into macros blocks.
Browse files Browse the repository at this point in the history
Replaced the original code inside the test blocks with the new macros.
  • Loading branch information
Leopold Gabelmann committed Jun 5, 2023
1 parent 4a3ef16 commit efe93d6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions macros/dmt_unit_test.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{%- test unit_test(model, input_mapping, expected_output, name, description, compare_columns, depends_on) -%}
{%- macro unit_test(model, input_mapping, expected_output, name, description, compare_columns, depends_on) -%}
{%- set test_sql = dbt_datamocktool.get_unit_test_sql(model, input_mapping, depends_on)|trim -%}
{%- set test_report = dbt_datamocktool.test_equality(expected_output, name, compare_model=test_sql, compare_columns=compare_columns) -%}
{{ test_report }}
{%- endmacro -%}
{%- test unit_test(model, input_mapping, expected_output, name, description, compare_columns, depends_on) -%}
{{ dbt_datamocktool.unit_test(model, input_mapping, expected_output, name, description, compare_columns, depends_on) }}
{%- endtest -%}

{% test unit_test_incremental(model, input_mapping, expected_output, name, description, compare_columns, depends_on) %}
{%- macro unit_test_incremental(model, input_mapping, expected_output, name, description, compare_columns, depends_on) -%}
{%- set test_sql = dbt_datamocktool.get_unit_test_incremental_sql(model, input_mapping, depends_on)|trim -%}
{%- set test_report = dbt_datamocktool.test_equality(expected_output, name, compare_model=test_sql, compare_columns=compare_columns) -%}
{{ test_report }}
{%- endmacro -%}
{% test unit_test_incremental(model, input_mapping, expected_output, name, description, compare_columns, depends_on) %}
{{ dbt_datamocktool.unit_test_incremental(model, input_mapping, expected_output, name, description, compare_columns, depends_on) }}
{% endtest %}

{%- macro test_equality(model, name, compare_model, compare_columns=None) -%}

{#-- Prevent querying of db in parsing mode. This works because this macro does not create any new refs. #}
{%- if not execute -%}
{{ return('') }}
Expand Down Expand Up @@ -49,9 +54,9 @@
{#- Run the comparison query -#}
{%- set test_report = run_query(tables_compared) -%}
{%- if test_report.columns[0].values()|length -%}
{%- set test_status = 1 -%}
{%- set test_status = 1 -%}
{%- else -%}
{%- set test_status = 0 -%}
{%- set test_status = 0 -%}
{%- endif-%}

{#- Print output if there are any rows within the table. -#}
Expand Down

0 comments on commit efe93d6

Please sign in to comment.