-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
392 additions
and
111 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
integration_tests/macros/tests/comparisons/test_dict_equals.sql
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,86 @@ | ||
{% macro test_dict_equals() %} | ||
{# Test successful dictionary equality #} | ||
{% set dict1 = {'a': 1, 'b': 2, 'c': 3} %} | ||
{% set dict2 = {'a': 1, 'b': 2, 'c': 3} %} | ||
{% set result1 = dbt_unittest.dict_equals(dict1, dict2) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: Identical dictionaries should be equal") }} | ||
{% endif %} | ||
|
||
{# Test failed dictionary equality - different values #} | ||
{% set dict3 = {'a': 1, 'b': 2, 'c': 4} %} | ||
{% set result2 = dbt_unittest.dict_equals(dict1, dict3) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: Dictionaries with different values should not be equal") }} | ||
{% endif %} | ||
|
||
{# Test failed dictionary equality - different keys #} | ||
{% set dict4 = {'a': 1, 'b': 2, 'd': 3} %} | ||
{% set result3 = dbt_unittest.dict_equals(dict1, dict4) %} | ||
{% if result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: Dictionaries with different keys should not be equal") }} | ||
{% endif %} | ||
|
||
{# Test failed dictionary equality - different lengths #} | ||
{% set dict5 = {'a': 1, 'b': 2} %} | ||
{% set result4 = dbt_unittest.dict_equals(dict1, dict5) %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: Dictionaries with different lengths should not be equal") }} | ||
{% endif %} | ||
|
||
{# Test failed dictionary equality - non-mapping types #} | ||
{% set result5 = dbt_unittest.dict_equals(dict1, [1, 2, 3]) %} | ||
{% if result5 %} | ||
{{ exceptions.raise_compiler_error("Failed: Comparing dictionary with non-mapping type should fail") }} | ||
{% endif %} | ||
|
||
{# Test failed dictionary equality - None values #} | ||
{% set result6 = dbt_unittest.dict_equals(dict1, none) %} | ||
{% if result6 %} | ||
{{ exceptions.raise_compiler_error("Failed: Comparing dictionary with None should fail") }} | ||
{% endif %} | ||
|
||
{# Test None equality #} | ||
{% set result7 = dbt_unittest.dict_equals(none, none) %} | ||
{% if not result7 %} | ||
{{ exceptions.raise_compiler_error("Failed: None should be equal to None") }} | ||
{% endif %} | ||
|
||
{# Test nested dictionary equality #} | ||
{% set nested_dict1 = {'a': 1, 'b': {'c': 2, 'd': 3}} %} | ||
{% set nested_dict2 = {'a': 1, 'b': {'c': 2, 'd': 3}} %} | ||
{% set result8 = dbt_unittest.dict_equals(nested_dict1, nested_dict2) %} | ||
{% if not result8 %} | ||
{{ exceptions.raise_compiler_error("Failed: Identical nested dictionaries should be equal") }} | ||
{% endif %} | ||
|
||
{# Test nested dictionary inequality #} | ||
{% set nested_dict3 = {'a': 1, 'b': {'c': 2, 'd': 4}} %} | ||
{% set result9 = dbt_unittest.dict_equals(nested_dict1, nested_dict3) %} | ||
{% if result9 %} | ||
{{ exceptions.raise_compiler_error("Failed: Nested dictionaries with different values should not be equal") }} | ||
{% endif %} | ||
|
||
{# Test empty dictionary equality #} | ||
{% set empty_dict1 = {} %} | ||
{% set empty_dict2 = {} %} | ||
{% set result10 = dbt_unittest.dict_equals(empty_dict1, empty_dict2) %} | ||
{% if not result10 %} | ||
{{ exceptions.raise_compiler_error("Failed: Empty dictionaries should be equal") }} | ||
{% endif %} | ||
|
||
{# Test dictionary with different value types #} | ||
{% set dict_mixed1 = {'a': 1, 'b': 'string', 'c': true} %} | ||
{% set dict_mixed2 = {'a': 1, 'b': 'string', 'c': true} %} | ||
{% set result11 = dbt_unittest.dict_equals(dict_mixed1, dict_mixed2) %} | ||
{% if not result11 %} | ||
{{ exceptions.raise_compiler_error("Failed: Dictionaries with mixed value types should be equal") }} | ||
{% endif %} | ||
|
||
{# Test dictionary with different value types - inequality #} | ||
{% set dict_mixed3 = {'a': 1, 'b': 'string', 'c': false} %} | ||
{% set result12 = dbt_unittest.dict_equals(dict_mixed1, dict_mixed3) %} | ||
{% if result12 %} | ||
{{ exceptions.raise_compiler_error("Failed: Dictionaries with different boolean values should not be equal") }} | ||
{% endif %} | ||
{% endmacro %} |
25 changes: 25 additions & 0 deletions
25
integration_tests/macros/tests/comparisons/test_equals.sql
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,25 @@ | ||
{% macro test_equals() %} | ||
{# Test successful equality #} | ||
{% set result1 = dbt_unittest.equals(5, 5) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should equal 5") }} | ||
{% endif %} | ||
|
||
{# Test failed equality #} | ||
{% set result2 = dbt_unittest.equals(5, 6) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should not equal 6") }} | ||
{% endif %} | ||
|
||
{# Test string equality #} | ||
{% set result3 = dbt_unittest.equals('hello', 'hello') %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'hello' should equal 'hello'") }} | ||
{% endif %} | ||
|
||
{# Test string inequality #} | ||
{% set result4 = dbt_unittest.equals('hello', 'world') %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'hello' should not equal 'world'") }} | ||
{% 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,25 @@ | ||
{% macro test_in() %} | ||
{# Test successful in condition with list #} | ||
{% set result1 = dbt_unittest.in(5, [1, 2, 3, 4, 5]) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should be in [1, 2, 3, 4, 5]") }} | ||
{% endif %} | ||
|
||
{# Test failed in condition with list #} | ||
{% set result2 = dbt_unittest.in(6, [1, 2, 3, 4, 5]) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: 6 should not be in [1, 2, 3, 4, 5]") }} | ||
{% endif %} | ||
|
||
{# Test successful in condition with string #} | ||
{% set result3 = dbt_unittest.in('a', 'abcde') %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'a' should be in 'abcde'") }} | ||
{% endif %} | ||
|
||
{# Test failed in condition with string #} | ||
{% set result4 = dbt_unittest.in('f', 'abcde') %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'f' should not be in 'abcde'") }} | ||
{% endif %} | ||
{% endmacro %} |
26 changes: 26 additions & 0 deletions
26
integration_tests/macros/tests/comparisons/test_is_false.sql
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,26 @@ | ||
{% macro test_is_false() %} | ||
{# Test successful false condition #} | ||
{% set result1 = dbt_unittest.is_false(false) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: false should be false") }} | ||
{% endif %} | ||
|
||
{# Test failed false condition #} | ||
{% set result2 = dbt_unittest.is_false(true) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: true should not be false") }} | ||
{% endif %} | ||
|
||
{# Test false with boolean expression #} | ||
{% set x = 5 %} | ||
{% set result3 = dbt_unittest.is_false(x != 5) %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 != 5 should be false") }} | ||
{% endif %} | ||
|
||
{# Test true with boolean expression #} | ||
{% set result4 = dbt_unittest.is_false(x == 5) %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 == 5 should not be false") }} | ||
{% endif %} | ||
{% endmacro %} |
28 changes: 28 additions & 0 deletions
28
integration_tests/macros/tests/comparisons/test_is_none.sql
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,28 @@ | ||
{% macro test_is_none() %} | ||
{# Test successful is_none condition #} | ||
{% set result1 = dbt_unittest.is_none(none) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: None should be None") }} | ||
{% endif %} | ||
|
||
{# Test failed is_none conditions #} | ||
{% set result2 = dbt_unittest.is_none(true) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: true should not be None") }} | ||
{% endif %} | ||
|
||
{% set result3 = dbt_unittest.is_none(1) %} | ||
{% if result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 1 should not be None") }} | ||
{% endif %} | ||
|
||
{% set result4 = dbt_unittest.is_none([1, 2, 3]) %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: list should not be None") }} | ||
{% endif %} | ||
|
||
{% set result5 = dbt_unittest.is_none({"1": "2"}) %} | ||
{% if result5 %} | ||
{{ exceptions.raise_compiler_error("Failed: dictionary should not be None") }} | ||
{% endif %} | ||
{% endmacro %} |
26 changes: 26 additions & 0 deletions
26
integration_tests/macros/tests/comparisons/test_is_true.sql
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,26 @@ | ||
{% macro test_is_true() %} | ||
{# Test successful true condition #} | ||
{% set result1 = dbt_unittest.is_true(true) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: true should be true") }} | ||
{% endif %} | ||
|
||
{# Test failed true condition #} | ||
{% set result2 = dbt_unittest.is_true(false) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: false should not be true") }} | ||
{% endif %} | ||
|
||
{# Test true with boolean expression #} | ||
{% set x = 5 %} | ||
{% set result3 = dbt_unittest.is_true(x == 5) %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 == 5 should be true") }} | ||
{% endif %} | ||
|
||
{# Test false with boolean expression #} | ||
{% set result4 = dbt_unittest.is_true(x != 5) %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 != 5 should not be true") }} | ||
{% endif %} | ||
{% endmacro %} |
25 changes: 25 additions & 0 deletions
25
integration_tests/macros/tests/comparisons/test_not_equals.sql
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,25 @@ | ||
{% macro test_not_equals() %} | ||
{# Test successful not equals #} | ||
{% set result1 = dbt_unittest.not_equals(5, 6) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should not equal 6") }} | ||
{% endif %} | ||
|
||
{# Test failed not equals #} | ||
{% set result2 = dbt_unittest.not_equals(5, 5) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should equal 5") }} | ||
{% endif %} | ||
|
||
{# Test string not equals #} | ||
{% set result3 = dbt_unittest.not_equals('hello', 'world') %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'hello' should not equal 'world'") }} | ||
{% endif %} | ||
|
||
{# Test string equals #} | ||
{% set result4 = dbt_unittest.not_equals('hello', 'hello') %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'hello' should equal 'hello'") }} | ||
{% endif %} | ||
{% endmacro %} |
25 changes: 25 additions & 0 deletions
25
integration_tests/macros/tests/comparisons/test_not_in.sql
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,25 @@ | ||
{% macro test_not_in() %} | ||
{# Test successful not in condition with list #} | ||
{% set result1 = dbt_unittest.not_in(6, [1, 2, 3, 4, 5]) %} | ||
{% if not result1 %} | ||
{{ exceptions.raise_compiler_error("Failed: 6 should not be in [1, 2, 3, 4, 5]") }} | ||
{% endif %} | ||
|
||
{# Test failed not in condition with list #} | ||
{% set result2 = dbt_unittest.not_in(5, [1, 2, 3, 4, 5]) %} | ||
{% if result2 %} | ||
{{ exceptions.raise_compiler_error("Failed: 5 should be in [1, 2, 3, 4, 5]") }} | ||
{% endif %} | ||
|
||
{# Test successful not in condition with string #} | ||
{% set result3 = dbt_unittest.not_in('f', 'abcde') %} | ||
{% if not result3 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'f' should not be in 'abcde'") }} | ||
{% endif %} | ||
|
||
{# Test failed not in condition with string #} | ||
{% set result4 = dbt_unittest.not_in('a', 'abcde') %} | ||
{% if result4 %} | ||
{{ exceptions.raise_compiler_error("Failed: 'a' should be in 'abcde'") }} | ||
{% 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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
{% macro test_macros() %} | ||
{% do test_assert_dict_equals() %} | ||
|
||
{% do test_assert_equals() %} | ||
|
||
{% do test_assert_false() %} | ||
|
||
{% do test_assert_in() %} | ||
|
||
{% do test_assert_not_in() %} | ||
|
||
{% do test_assert_is_none() %} | ||
|
||
{% do test_assert_is_not_none() %} | ||
|
||
{% do test_assert_list_equals() %} | ||
|
||
{% do test_assert_not_equals() %} | ||
|
||
{% do test_assert_true() %} | ||
|
||
{# New comparison macro unit tests #} | ||
{% do test_equals() %} | ||
{% do test_not_equals() %} | ||
{% do test_is_true() %} | ||
{% do test_is_false() %} | ||
{% do test_in() %} | ||
{% do test_not_in() %} | ||
{% do test_dict_equals() %} | ||
{% 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 |
---|---|---|
@@ -1,38 +1,5 @@ | ||
{% macro assert_dict_equals(value, expected) %} | ||
{% if value is not mapping %} | ||
{% do exceptions.raise_compiler_error("FAILED: 1st argument " ~ value ~ " is not a mapping.") %} | ||
{% macro assert_dict_equals(actual, expected) %} | ||
{% if not dbt_unittest.dict_equals(actual, expected) %} | ||
{% do exceptions.raise_compiler_error("FAILED: Dictionaries are not equal.") %} | ||
{% endif %} | ||
{% if expected is not mapping %} | ||
{% do exceptions.raise_compiler_error("FAILED: 2nd argument " ~ expected ~ " is not a mapping.") %} | ||
{% endif %} | ||
|
||
{% for k, v in value.items() %} | ||
{% if k not in expected %} | ||
{% do exceptions.raise_compiler_error("FAILED: key " ~ k ~ " of 1st argument is not in " ~ expected ~ ".") %} | ||
{% endif %} | ||
|
||
{% if v is none and expected[k] is not none %} | ||
{% do exceptions.raise_compiler_error("FAILED: values on the key " ~ k ~ " are not same.") %} | ||
{% endif %} | ||
|
||
{% if v != expected[k] %} | ||
{% do exceptions.raise_compiler_error("FAILED: values on the key " ~ k ~ " are not same.") %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% for k, v in expected.items() %} | ||
{% if k not in value %} | ||
{% do exceptions.raise_compiler_error("FAILED: key " ~ k ~ " of 2nd argument is not in " ~ value ~ ".") %} | ||
{% endif %} | ||
|
||
{% if v is none and value[k] is not none %} | ||
{% do exceptions.raise_compiler_error("FAILED: values on the key " ~ k ~ " are not same.") %} | ||
{% endif %} | ||
|
||
{% if v != value[k] %} | ||
{% do exceptions.raise_compiler_error("FAILED: values on the key " ~ k ~ " are not same.") %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{% do log("SUCCESS") %} | ||
{% 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{% macro assert_equals(value, expected) %} | ||
{% if value == expected %} | ||
{% do log("SUCCESS") %} | ||
{% else %} | ||
{% do exceptions.raise_compiler_error("FAILED: " ~ value ~ " is not equal to " ~ expected ~ ".") %} | ||
{% macro assert_equals(actual, expected) %} | ||
{% if not dbt_unittest.equals(actual, expected) %} | ||
{% do exceptions.raise_compiler_error("FAILED: " ~ actual ~ " does not equal " ~ expected ~ ".") %} | ||
{% 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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
{% macro assert_false(value) %} | ||
{% if value is not boolean %} | ||
{% do exceptions.raise_compiler_error("FAILED: " ~ value ~ " is not boolean.") %} | ||
{% endif %} | ||
|
||
{% if value is false %} | ||
{% do log("SUCCESS") %} | ||
{% else %} | ||
{% do exceptions.raise_compiler_error("FAILED: value " ~ value ~ " is not false.") %} | ||
{% macro assert_false(condition) %} | ||
{% if not dbt_unittest.is_false(condition) %} | ||
{% do exceptions.raise_compiler_error("FAILED: Condition is not false.") %} | ||
{% 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{% macro assert_in(value, expected) %} | ||
{% if value in expected %} | ||
{% do log("SUCCESS") %} | ||
{% else %} | ||
{% do exceptions.raise_compiler_error("FAILED: value " ~ value ~ " is not in " ~ expected ~ ".") %} | ||
{% if not dbt_unittest.in(value, expected) %} | ||
{% do exceptions.raise_compiler_error("FAILED: " ~ value ~ " is not in " ~ expected ~ ".") %} | ||
{% 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{% macro assert_is_none(value) %} | ||
{% if value is none %} | ||
{% do log("SUCCESS") %} | ||
{% else %} | ||
{% do exceptions.raise_compiler_error("FAILED: value " ~ value ~ " is not none.") %} | ||
{% if not dbt_unittest.is_none(value) %} | ||
{% do exceptions.raise_compiler_error("FAILED: Value is not None.") %} | ||
{% endif %} | ||
{% endmacro %} |
Oops, something went wrong.