From 8ae3ec89f7bc829cfa9351100905e13bc42542ac Mon Sep 17 00:00:00 2001 From: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Date: Wed, 3 Jul 2024 17:53:32 -0400 Subject: [PATCH] use shared empty flag tests (#1104) --- tests/functional/adapter/empty/_models.py | 72 -------------------- tests/functional/adapter/empty/test_empty.py | 48 ++----------- 2 files changed, 7 insertions(+), 113 deletions(-) delete mode 100644 tests/functional/adapter/empty/_models.py diff --git a/tests/functional/adapter/empty/_models.py b/tests/functional/adapter/empty/_models.py deleted file mode 100644 index 698e4f1db..000000000 --- a/tests/functional/adapter/empty/_models.py +++ /dev/null @@ -1,72 +0,0 @@ -SEED = """ -my_id,my_value -1,a -2,b -3,c -""".strip() - - -SCHEMA = """ -version: 2 - -seeds: - - name: my_seed - description: "This is my_seed" - columns: - - name: id - description: "This is my_seed.my_id" -""" - -CONTROL = """ -select * from {{ ref("my_seed") }} -""" - - -GET_COLUMNS_IN_RELATION = """ -{{ config(materialized="table") }} -{% set columns = adapter.get_columns_in_relation(ref("my_seed")) %} -select * from {{ ref("my_seed") }} -""" - - -ALTER_COLUMN_TYPE = """ -{{ config(materialized="table") }} -{{ alter_column_type(ref("my_seed"), "MY_VALUE", "varchar") }} -select * from {{ ref("my_seed") }} -""" - - -ALTER_RELATION_COMMENT = """ -{{ config( - materialized="table", - persist_docs={"relations": True}, -) }} -select * from {{ ref("my_seed") }} -""" - - -ALTER_COLUMN_COMMENT = """ -{{ config( - materialized="table", - persist_docs={"columns": True}, -) }} -select * from {{ ref("my_seed") }} -""" - - -ALTER_RELATION_ADD_REMOVE_COLUMNS = """ -{{ config(materialized="table") }} -{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %} -{% set my_column = api.Column("my_column", "varchar") %} -{% do alter_relation_add_remove_columns(my_seed, [my_column], none) %} -{% do alter_relation_add_remove_columns(my_seed, none, [my_column]) %} -select * from {{ ref("my_seed") }} -""" - - -TRUNCATE_RELATION = """ -{{ config(materialized="table") }} -{% set my_seed = adapter.Relation.create(this.database, this.schema, "my_seed", "table") %} -{{ truncate_relation(my_seed) }} -select * from {{ ref("my_seed") }} -""" diff --git a/tests/functional/adapter/empty/test_empty.py b/tests/functional/adapter/empty/test_empty.py index fe07fc081..0bf9d1a41 100644 --- a/tests/functional/adapter/empty/test_empty.py +++ b/tests/functional/adapter/empty/test_empty.py @@ -1,8 +1,8 @@ -from dbt.tests.adapter.empty.test_empty import BaseTestEmpty, BaseTestEmptyInlineSourceRef -from dbt.tests.util import run_dbt -import pytest - -from tests.functional.adapter.empty import _models +from dbt.tests.adapter.empty.test_empty import ( + BaseTestEmpty, + BaseTestEmptyInlineSourceRef, + MetadataWithEmptyFlag, +) class TestSnowflakeEmpty(BaseTestEmpty): @@ -13,39 +13,5 @@ class TestSnowflakeEmptyInlineSourceRef(BaseTestEmptyInlineSourceRef): pass -class TestMetadataWithEmptyFlag: - @pytest.fixture(scope="class") - def seeds(self): - return {"my_seed.csv": _models.SEED} - - @pytest.fixture(scope="class") - def models(self): - return { - "schema.yml": _models.SCHEMA, - "control.sql": _models.CONTROL, - "get_columns_in_relation.sql": _models.GET_COLUMNS_IN_RELATION, - "alter_column_type.sql": _models.ALTER_COLUMN_TYPE, - "alter_relation_comment.sql": _models.ALTER_RELATION_COMMENT, - "alter_column_comment.sql": _models.ALTER_COLUMN_COMMENT, - "alter_relation_add_remove_columns.sql": _models.ALTER_RELATION_ADD_REMOVE_COLUMNS, - "truncate_relation.sql": _models.TRUNCATE_RELATION, - } - - @pytest.fixture(scope="class", autouse=True) - def setup(self, project): - run_dbt(["seed"]) - - @pytest.mark.parametrize( - "model", - [ - "control", - "get_columns_in_relation", - "alter_column_type", - "alter_relation_comment", - "alter_column_comment", - "alter_relation_add_remove_columns", - "truncate_relation", - ], - ) - def test_run(self, project, model): - run_dbt(["run", "--empty", "--select", model]) +class TestMetadataWithEmptyFlag(MetadataWithEmptyFlag): + pass