Skip to content

Commit

Permalink
add adapter-zone tests for dbt show
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 18, 2023
1 parent a8d01ee commit a2ace01
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 28 deletions.
4 changes: 3 additions & 1 deletion core/dbt/task/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def execute(self, compiled_node, manifest):
context_override=model_context,
kwargs={"limit": limit},
)
adapter_response, execute_result = self.adapter.execute(compiled_node.compiled_code, fetch=True)
adapter_response, execute_result = self.adapter.execute(
compiled_node.compiled_code, fetch=True
)

end_time = time.time()

Expand Down
44 changes: 44 additions & 0 deletions tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from dbt.tests.util import run_dbt_and_capture, run_dbt

from tests.functional.show.test_show import ShowBase
from tests.functional.show.fixtures import (
models__second_ephemeral_model
)


# -- Below we define base classes for tests you import the one based on if your adapter uses dbt clone or not --
class BaseShowLimit(ShowBase):
@pytest.mark.parametrize(
"args,expected",
[
([], 5), # default limit
(["--limit", 3], 3), # fetch 3 rows
(["--limit", -1], 7), # fetch all rows
],
)
def test_limit(self, project, args, expected):
run_dbt(["build"])
dbt_args = ["show", "--inline", models__second_ephemeral_model, *args]
results = run_dbt(dbt_args)
assert len(results.results[0].agate_table) == expected
# ensure limit was injected in compiled_code when limit specified in command args
limit = results.args.get("limit")
if limit > 0:
assert f"limit {limit}" in results.results[0].node.compiled_code


class BaseShowSqlHeader(ShowBase):
def test_sql_header(self, project):
run_dbt(["build", "--vars", "timezone: Asia/Kolkata"])
(_, log_output) = run_dbt_and_capture(
["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"]
)


class TestPostgresShowSqlHeader(BaseShowSqlHeader):
pass


class TestPostgresShowLimit(BaseShowLimit):
pass
27 changes: 0 additions & 27 deletions tests/functional/show/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,39 +143,12 @@ def test_second_ephemeral_model(self, project):
assert "col_hundo" in log_output


class TestShowLimit(ShowBase):
@pytest.mark.parametrize(
"args,expected",
[
([], 5), # default limit
(["--limit", 3], 3), # fetch 3 rows
(["--limit", -1], 7), # fetch all rows
],
)
def test_limit(self, project, args, expected):
run_dbt(["build"])
dbt_args = ["show", "--inline", models__second_ephemeral_model, *args]
results = run_dbt(dbt_args)
assert len(results.results[0].agate_table) == expected
# ensure limit was injected in compiled_code when limit specified in command args
if results.args.get("limit") > 0:
assert "limit" in results.results[0].node.compiled_code


class TestShowSeed(ShowBase):
def test_seed(self, project):
(_, log_output) = run_dbt_and_capture(["show", "--select", "sample_seed"])
assert "Previewing node 'sample_seed'" in log_output


class TestShowSqlHeader(ShowBase):
def test_sql_header(self, project):
run_dbt(["build", "--vars", "timezone: Asia/Kolkata"])
(_, log_output) = run_dbt_and_capture(
["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"]
)


class TestShowModelVersions:
@pytest.fixture(scope="class")
def models(self):
Expand Down

0 comments on commit a2ace01

Please sign in to comment.