Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix package-defined schema test macros #562

Merged
merged 3 commits into from
Oct 20, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dbt/context/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import dbt.context.common

from dbt.adapters.factory import get_adapter


execute = False

Expand All @@ -16,6 +18,9 @@ def ref(*args):
else:
dbt.exceptions.ref_invalid_args(model, args)

adapter = get_adapter(profile)
return dbt.utils.Relation(adapter, model)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 we should have added this a long time ago :)


return ref


Expand Down
9 changes: 8 additions & 1 deletion dbt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,16 @@ def parse_schema_test(test_base, model_name, test_config, test_type,
# sort the dict so the keys are rendered deterministically (for tests)
kwargs = [as_kwarg(key, test_args[key]) for key in sorted(test_args)]

macro_name = "test_{}".format(test_type)

if package_project_config.get('name') != \
root_project_config.get('name'):
macro_name = "{}.{}".format(package_project_config.get('name'),
macro_name)

raw_sql = "{{{{ {macro}(model=ref('{model}'), {kwargs}) }}}}".format(**{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have a think about how to do this better in the future -- it's kind of jank!

'model': model_name,
'macro': "test_{}".format(test_type),
'macro': macro_name,
'kwargs': ", ".join(kwargs)
})

Expand Down