From 1ebfd74c6890eb1f9dd7d8a346584d3ad206aec4 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 18 Sep 2023 18:43:49 +0100 Subject: [PATCH] reorganize dbt_show adapter test fixtures --- .../dbt/tests/adapter/dbt_show/fixtures.py | 34 ++++++++++++++++++ .../tests/adapter/dbt_show/test_dbt_show.py | 36 ++++++++++++++----- tests/functional/show/test_show.py | 2 -- 3 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py diff --git a/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py b/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py new file mode 100644 index 00000000000..6eda5a695f3 --- /dev/null +++ b/tests/adapter/dbt/tests/adapter/dbt_show/fixtures.py @@ -0,0 +1,34 @@ +models__sql_header = """ +{% call set_sql_header(config) %} +set session time zone '{{ var("timezone", "Europe/Paris") }}'; +{%- endcall %} +select current_setting('timezone') as timezone +""" + +models__ephemeral_model = """ +{{ config(materialized = 'ephemeral') }} +select + coalesce(sample_num, 0) + 10 as col_deci +from {{ ref('sample_model') }} +""" + +models__second_ephemeral_model = """ +{{ config(materialized = 'ephemeral') }} +select + col_deci + 100 as col_hundo +from {{ ref('ephemeral_model') }} +""" + +models__sample_model = """ +select * from {{ ref('sample_seed') }} +""" + +seeds__sample_seed = """sample_num,sample_bool +1,true +2,false +3,true +4,false +5,true +6,false +7,true +""" diff --git a/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py b/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py index 00551550eec..a93bb9dd2ab 100644 --- a/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py +++ b/tests/adapter/dbt/tests/adapter/dbt_show/test_dbt_show.py @@ -1,12 +1,28 @@ import pytest -from dbt.tests.util import run_dbt_and_capture, run_dbt +from dbt.tests.util import run_dbt -from tests.functional.show.test_show import ShowBase -from tests.functional.show.fixtures import models__second_ephemeral_model +from dbt.tests.adapter.dbt_show.fixtures import ( + models__sql_header, + models__ephemeral_model, + models__second_ephemeral_model, + models__sample_model, + seeds__sample_seed, +) # -- Below we define base classes for tests you import based on if your adapter supports dbt show or not -- -class BaseShowLimit(ShowBase): +class BaseShowLimit: + @pytest.fixture(scope="class") + def models(self): + return { + "sample_model.sql": models__sample_model, + "ephemeral_model.sql": models__ephemeral_model, + } + + @pytest.fixture(scope="class") + def seeds(self): + return {"sample_seed.csv": seeds__sample_seed} + @pytest.mark.parametrize( "args,expected", [ @@ -26,12 +42,16 @@ def test_limit(self, project, args, expected): assert f"limit {limit}" in results.results[0].node.compiled_code -class BaseShowSqlHeader(ShowBase): +class BaseShowSqlHeader: + @pytest.fixture(scope="class") + def models(self): + return { + "sql_header.sql": models__sql_header, + } + 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"] - ) + run_dbt(["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"]) class TestPostgresShowSqlHeader(BaseShowSqlHeader): diff --git a/tests/functional/show/test_show.py b/tests/functional/show/test_show.py index 8be3befa056..85f27261c11 100644 --- a/tests/functional/show/test_show.py +++ b/tests/functional/show/test_show.py @@ -11,7 +11,6 @@ models__second_model, models__ephemeral_model, schema_yml, - models__sql_header, private_model_yml, ) @@ -25,7 +24,6 @@ def models(self): "sample_number_model_with_nulls.sql": models__sample_number_model_with_nulls, "second_model.sql": models__second_model, "ephemeral_model.sql": models__ephemeral_model, - "sql_header.sql": models__sql_header, } @pytest.fixture(scope="class")