Skip to content

Commit

Permalink
Support dict-style generic test spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jtcohen6 committed Mar 18, 2022
1 parent 5da3760 commit f092d01
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/dbt/parser/generic_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,23 @@ def extract_test_args(test, name=None) -> Tuple[str, Dict[str, Any]]:
"test must be dict or str, got {} (value {})".format(type(test), test)
)

test = list(test.items())
if len(test) != 1:
raise_parsing_error(
"test definition dictionary must have exactly one key, got"
" {} instead ({} keys)".format(test, len(test))
)
test_name, test_args = test[0]
# If the test is a dictionary with top-level keys, the test name is "test_name"
# and the rest are arguments
# {'name': 'my_favorite_test', 'test_name': 'unique', 'config': {'where': '1=1'}}
if "test_name" in test.keys():
test_name = test.pop("test_name")
test_args = test
# If the test is a nested dictionary with one top-level key, the test name
# is the dict name, and nested keys are arguments
# {'unique': {'name': 'my_favorite_test', 'config': {'where': '1=1'}}}
else:
test = list(test.items())
if len(test) != 1:
raise_parsing_error(
"test definition dictionary must have exactly one key, got"
" {} instead ({} keys)".format(test, len(test))
)
test_name, test_args = test[0]

if not isinstance(test_args, dict):
raise_parsing_error(
Expand Down

0 comments on commit f092d01

Please sign in to comment.