Skip to content

Commit

Permalink
Changes to support unit test sql format (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank authored Apr 11, 2024
1 parent 7392deb commit 3f2386d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240409-084844.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Support for sql fixtures in unit testing
time: 2024-04-09T08:48:44.441106-04:00
custom:
Author: gshank
Issue: "148"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% set relations = [] %}

{% set expected_rows = config.get('expected_rows') %}
{% set expected_sql = config.get('expected_sql') %}
{% set tested_expected_column_names = expected_rows[0].keys() if (expected_rows | length ) > 0 else get_columns_in_query(sql) %} %}

{%- set target_relation = this.incorporate(type='table') -%}
Expand All @@ -11,10 +12,13 @@
{%- set columns_in_relation = adapter.get_columns_in_relation(temp_relation) -%}
{%- set column_name_to_data_types = {} -%}
{%- for column in columns_in_relation -%}
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%}
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%}
{%- endfor -%}

{% set unit_test_sql = get_unit_test_sql(sql, get_expected_sql(expected_rows, column_name_to_data_types), tested_expected_column_names) %}
{% if not expected_sql %}
{% set expected_sql = get_expected_sql(expected_rows, column_name_to_data_types) %}
{% endif %}
{% set unit_test_sql = get_unit_test_sql(sql, expected_sql, tested_expected_column_names) %}

{% call statement('main', fetch_result=True) -%}

Expand Down

0 comments on commit 3f2386d

Please sign in to comment.