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 multiple args for ref and source #5635

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20220816-153401.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: multiple args for ref and source
time: 2022-08-16T15:34:01.348339-07:00
custom:
Author: ChenyuLInx
Issue: "5634"
PR: "5635"
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class this:

class dbtObj:
def __init__(self, load_df_function) -> None:
self.source = lambda x: source(x, dbt_load_df_function=load_df_function)
self.ref = lambda x: ref(x, dbt_load_df_function=load_df_function)
self.source = lambda *args: source(*args, dbt_load_df_function=load_df_function)
self.ref = lambda *args: ref(*args, dbt_load_df_function=load_df_function)
self.config = config
self.this = this()
self.is_incremental = {{ is_incremental() }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import os
import yaml
from dbt.tests.util import run_dbt

basic_sql = """
Expand All @@ -16,27 +17,64 @@ def model(dbt, _):
materialized='table',
)
df = dbt.ref("my_sql_model")
df2 = dbt.source('test_source', 'test_table')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test will automatically run across places, tested locally in dbt-snowflake

df = df.limit(2)
return df
"""

second_sql = """
select * from {{ref('my_python_model')}}
"""
schema_yml = """version: 2
sources:
- name: test_source
loader: custom
schema: "{{ var(env_var('DBT_TEST_SCHEMA_NAME_VARIABLE')) }}"
quoting:
identifier: True
tags:
- my_test_source_tag
tables:
- name: test_table
identifier: source
"""

seeds__source_csv = """favorite_color,id,first_name,email,ip_address,updated_at
blue,1,Larry,[email protected],'69.135.206.194',2008-09-12 19:08:31
blue,2,Larry,[email protected],'64.210.133.162',1978-05-09 04:15:14
"""


class BasePythonModelTests:
@pytest.fixture(scope="class", autouse=True)
def setEnvVars(self):
os.environ["DBT_TEST_SCHEMA_NAME_VARIABLE"] = "test_run_schema"

yield

del os.environ["DBT_TEST_SCHEMA_NAME_VARIABLE"]

@pytest.fixture(scope="class")
def seeds(self):
return {"source.csv": seeds__source_csv}

@pytest.fixture(scope="class")
def models(self):
return {
"schema.yml": schema_yml,
"my_sql_model.sql": basic_sql,
"my_python_model.py": basic_python,
"second_sql_model.sql": second_sql,
}

def test_singular_tests(self, project):
# test command
results = run_dbt(["run"])
vars_dict = {
"test_run_schema": project.test_schema,
}

run_dbt(["seed", "--vars", yaml.safe_dump(vars_dict)])
results = run_dbt(["run", "--vars", yaml.safe_dump(vars_dict)])
assert len(results) == 3


Expand Down