From 84b37450f0a88db13269cda605bb40371397d95a Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 9 Sep 2024 10:37:58 -0400 Subject: [PATCH] remove tests covered by dbt-core: deprecations --- tests/functional/deprecations/fixtures.py | 101 ------------ .../deprecations/model_deprecations.py | 106 ------------- .../deprecations/test_config_deprecations.py | 148 ------------------ .../deprecations/test_deprecations.py | 148 ------------------ 4 files changed, 503 deletions(-) delete mode 100644 tests/functional/deprecations/fixtures.py delete mode 100644 tests/functional/deprecations/model_deprecations.py delete mode 100644 tests/functional/deprecations/test_config_deprecations.py delete mode 100644 tests/functional/deprecations/test_deprecations.py diff --git a/tests/functional/deprecations/fixtures.py b/tests/functional/deprecations/fixtures.py deleted file mode 100644 index 0028f206..00000000 --- a/tests/functional/deprecations/fixtures.py +++ /dev/null @@ -1,101 +0,0 @@ -models__already_exists_sql = """ -select 1 as id - -{% if adapter.already_exists(this.schema, this.identifier) and not should_full_refresh() %} - where id > (select max(id) from {{this}}) -{% endif %} -""" - -models_trivial__model_sql = """ -select 1 as id -""" - - -bad_name_yaml = """ -version: 2 - -exposures: - - name: simple exposure spaced!! - type: dashboard - depends_on: - - ref('model') - owner: - email: something@example.com -""" - -# deprecated test config fixtures -data_tests_yaml = """ -models: - - name: model - columns: - - name: id - data_tests: - - not_null -""" - -test_type_mixed_yaml = """ -models: - - name: model - columns: - - name: id - data_tests: - - not_null - tests: - - unique -""" - -old_tests_yaml = """ -models: - - name: model - columns: - - name: id - tests: - - not_null -""" - -sources_old_tests_yaml = """ -sources: - - name: seed_source - schema: "{{ var('schema_override', target.schema) }}" - tables: - - name: "seed" - columns: - - name: id - tests: - - unique -""" - -seed_csv = """id,name -1,Mary -2,Sam -3,John -""" - - -local_dependency__dbt_project_yml = """ - -name: 'local_dep' -version: '1.0' - -seeds: - quote_columns: False - -""" - -local_dependency__schema_yml = """ -sources: - - name: seed_source - schema: "{{ var('schema_override', target.schema) }}" - tables: - - name: "seed" - columns: - - name: id - tests: - - unique -""" - -local_dependency__seed_csv = """id,name -1,Mary -2,Sam -3,John -""" diff --git a/tests/functional/deprecations/model_deprecations.py b/tests/functional/deprecations/model_deprecations.py deleted file mode 100644 index c762e7a6..00000000 --- a/tests/functional/deprecations/model_deprecations.py +++ /dev/null @@ -1,106 +0,0 @@ -from dbt.cli.main import dbtRunner -from dbt.tests.util import run_dbt -from dbt_common.exceptions import EventCompilationError -import pytest - - -deprecated_model__yml = """ -version: 2 - -models: - - name: my_model - description: deprecated - deprecation_date: 1999-01-01 -""" - -deprecating_model__yml = """ -version: 2 - -models: - - name: my_model - description: deprecating in the future - deprecation_date: 2999-01-01 -""" - -model__sql = """ -select 1 as Id -""" - -dependant_model__sql = """ -select * from {{ ref("my_model") }} -""" - - -class TestModelDeprecationWarning: - @pytest.fixture(scope="class") - def models(self): - return {"my_model.sql": model__sql, "my_schema.yml": deprecated_model__yml} - - def test_deprecation_warning(self, project): - events = [] - dbtRunner(callbacks=[events.append]).invoke(["parse"]) - matches = list([e for e in events if e.info.name == "DeprecatedModel"]) - assert len(matches) == 1 - assert matches[0].read_data.model_name == "my_model" - - def test_deprecation_warning_error(self, project): - with pytest.raises(EventCompilationError): - run_dbt(["--warn-error", "parse"]) - - def test_deprecation_warning_error_options(self, project): - with pytest.raises(EventCompilationError): - run_dbt(["--warn-error-options", '{"include": ["DeprecatedModel"]}', "parse"]) - - -class TestUpcomingReferenceDeprecatingWarning: - @pytest.fixture(scope="class") - def models(self): - return { - "my_model.sql": model__sql, - "my_dependant_model.sql": dependant_model__sql, - "my_schema.yml": deprecating_model__yml, - } - - def test_deprecation_warning(self, project): - events = [] - dbtRunner(callbacks=[events.append]).invoke(["parse"]) - matches = list([e for e in events if e.info.name == "UpcomingReferenceDeprecation"]) - assert len(matches) == 1 - assert matches[0].read_data.model_name == "my_dependant_model" - assert matches[0].read_data.ref_model_name == "my_model" - - def test_deprecation_warning_error(self, project): - with pytest.raises(EventCompilationError): - run_dbt(["--warn-error", "parse"]) - - def test_deprecation_warning_error_options(self, project): - with pytest.raises(EventCompilationError): - run_dbt( - ["--warn-error-options", '{"include": ["UpcomingReferenceDeprecation"]}', "parse"] - ) - - -class TestDeprecatedReferenceWarning: - @pytest.fixture(scope="class") - def models(self): - return { - "my_model.sql": model__sql, - "my_dependant_model.sql": dependant_model__sql, - "my_schema.yml": deprecated_model__yml, - } - - def test_deprecation_warning(self, project): - events = [] - dbtRunner(callbacks=[events.append]).invoke(["parse"]) - matches = list([e for e in events if e.info.name == "DeprecatedReference"]) - assert len(matches) == 1 - assert matches[0].read_data.model_name == "my_dependant_model" - assert matches[0].read_data.ref_model_name == "my_model" - - def test_deprecation_warning_error(self, project): - with pytest.raises(EventCompilationError): - run_dbt(["--warn-error", "parse"]) - - def test_deprecation_warning_error_options(self, project): - with pytest.raises(EventCompilationError): - run_dbt(["--warn-error-options", '{"include": ["DeprecatedReference"]}', "parse"]) diff --git a/tests/functional/deprecations/test_config_deprecations.py b/tests/functional/deprecations/test_config_deprecations.py deleted file mode 100644 index f8623c1a..00000000 --- a/tests/functional/deprecations/test_config_deprecations.py +++ /dev/null @@ -1,148 +0,0 @@ -from dbt.deprecations import active_deprecations, reset_deprecations -from dbt.exceptions import ProjectContractError, YamlParseDictError -from dbt.tests.fixtures.project import write_project_files -from dbt.tests.util import run_dbt, update_config_file -from dbt_common.exceptions import CompilationError -import pytest - -from tests.functional.deprecations import fixtures - - -# test deprecation messages -class TestTestsConfigDeprecation: - @pytest.fixture(scope="class") - def models(self): - return {"model.sql": fixtures.models_trivial__model_sql} - - @pytest.fixture(scope="class") - def project_config_update(self, unique_schema): - return {"tests": {"enabled": "true"}} - - def test_tests_config(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["parse"]) - expected = {"project-test-config"} - assert expected == active_deprecations - - def test_tests_config_fail(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "--no-partial-parse", "parse"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "The `tests` config has been renamed to `data_tests`" - assert expected_msg in exc_str - - -class TestSchemaTestDeprecation: - @pytest.fixture(scope="class") - def models(self): - return { - "model.sql": fixtures.models_trivial__model_sql, - "schema.yml": fixtures.old_tests_yaml, - } - - def test_tests_config(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["parse"]) - expected = {"project-test-config"} - assert expected == active_deprecations - - def test_schema_tests_fail(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "--no-partial-parse", "parse"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "The `tests` config has been renamed to `data_tests`" - assert expected_msg in exc_str - - -class TestSourceSchemaTestDeprecation: - @pytest.fixture(scope="class") - def models(self): - return {"schema.yml": fixtures.sources_old_tests_yaml} - - @pytest.fixture(scope="class") - def seeds(self): - return {"seed.csv": fixtures.seed_csv} - - def test_source_tests_config(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["seed"]) - run_dbt(["parse"]) - expected = {"project-test-config"} - assert expected == active_deprecations - - def test_schema_tests(self, project): - run_dbt(["seed"]) - results = run_dbt(["test"]) - assert len(results) == 1 - - -# test for failure with test and data_tests in the same file -class TestBothSchemaTestDeprecation: - @pytest.fixture(scope="class") - def models(self): - return { - "model.sql": fixtures.models_trivial__model_sql, - "schema.yml": fixtures.test_type_mixed_yaml, - } - - def test_schema(self, project): - expected_msg = "Invalid test config: cannot have both 'tests' and 'data_tests' defined" - with pytest.raises(YamlParseDictError) as excinfo: - run_dbt(["parse"]) - assert expected_msg in str(excinfo.value) - - -# test for failure with test and data_tests in the same dbt_project.yml -class TestBothProjectTestDeprecation: - @pytest.fixture(scope="class") - def models(self): - return {"model.sql": fixtures.models_trivial__model_sql} - - def test_tests_config(self, project): - config_patch = {"tests": {"+enabled": "true"}, "data_tests": {"+tags": "super"}} - update_config_file(config_patch, project.project_root, "dbt_project.yml") - - expected_msg = "Invalid project config: cannot have both 'tests' and 'data_tests' defined" - with pytest.raises(ProjectContractError) as excinfo: - run_dbt(["parse"]) - assert expected_msg in str(excinfo.value) - - -# test a local dependency can have tests while the rest of the project uses data_tests -class TestTestConfigInDependency: - @pytest.fixture(scope="class", autouse=True) - def setUp(self, project_root): - local_dependency_files = { - "dbt_project.yml": fixtures.local_dependency__dbt_project_yml, - "models": { - "schema.yml": fixtures.local_dependency__schema_yml, - }, - "seeds": {"seed.csv": fixtures.local_dependency__seed_csv}, - } - write_project_files(project_root, "local_dependency", local_dependency_files) - - @pytest.fixture(scope="class") - def packages(self): - return {"packages": [{"local": "local_dependency"}]} - - @pytest.fixture(scope="class") - def models(self): - return { - "model.sql": fixtures.models_trivial__model_sql, - "schema.yml": fixtures.data_tests_yaml, - } - - def test_test_dep(self, project): - run_dbt(["deps"]) - run_dbt(["seed"]) - run_dbt(["run"]) - results = run_dbt(["test"]) - # 1 data_test in the dep and 1 in the project - assert len(results) == 2 diff --git a/tests/functional/deprecations/test_deprecations.py b/tests/functional/deprecations/test_deprecations.py deleted file mode 100644 index 1f4a31c2..00000000 --- a/tests/functional/deprecations/test_deprecations.py +++ /dev/null @@ -1,148 +0,0 @@ -from dbt.deprecations import active_deprecations, reset_deprecations -from dbt.tests.util import run_dbt, write_file -from dbt_common.exceptions import CompilationError -import pytest -import yaml - -from tests.functional.deprecations import fixtures - - -class TestConfigPathDeprecation: - @pytest.fixture(scope="class") - def models(self): - return {"already_exists.sql": fixtures.models_trivial__model_sql} - - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "config-version": 2, - "data-paths": ["data"], - "log-path": "customlogs", - "target-path": "customtarget", - } - - def test_data_path(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["debug"]) - expected = { - "project-config-data-paths", - "project-config-log-path", - "project-config-target-path", - } - assert expected == active_deprecations - - def test_data_path_fail(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "debug"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "The `data-paths` config has been renamed" - assert expected_msg in exc_str - - -class TestPackageInstallPathDeprecation: - @pytest.fixture(scope="class") - def models_trivial(self): - return {"model.sql": fixtures.models_trivial__model_sql} - - @pytest.fixture(scope="class") - def project_config_update(self): - return {"config-version": 2, "clean-targets": ["dbt_modules"]} - - def test_package_path(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["clean"]) - expected = {"install-packages-path"} - assert expected == active_deprecations - - def test_package_path_not_set(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "clean"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "path has changed from `dbt_modules` to `dbt_packages`." - assert expected_msg in exc_str - - -class TestPackageRedirectDeprecation: - @pytest.fixture(scope="class") - def models(self): - return {"already_exists.sql": fixtures.models_trivial__model_sql} - - @pytest.fixture(scope="class") - def packages(self): - return {"packages": [{"package": "fishtown-analytics/dbt_utils", "version": "0.7.0"}]} - - def test_package_redirect(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["deps"]) - expected = {"package-redirect"} - assert expected == active_deprecations - - # if this test comes before test_package_redirect it will raise an exception as expected - def test_package_redirect_fail(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "deps"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "The `fishtown-analytics/dbt_utils` package is deprecated in favor of `dbt-labs/dbt_utils`" - assert expected_msg in exc_str - - -class TestExposureNameDeprecation: - @pytest.fixture(scope="class") - def models(self): - return { - "model.sql": fixtures.models_trivial__model_sql, - "bad_name.yml": fixtures.bad_name_yaml, - } - - def test_exposure_name(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["parse"]) - expected = {"exposure-name"} - assert expected == active_deprecations - - def test_exposure_name_fail(self, project): - reset_deprecations() - assert active_deprecations == set() - with pytest.raises(CompilationError) as exc: - run_dbt(["--warn-error", "--no-partial-parse", "parse"]) - exc_str = " ".join(str(exc.value).split()) # flatten all whitespace - expected_msg = "Starting in v1.3, the 'name' of an exposure should contain only letters, numbers, and underscores." - assert expected_msg in exc_str - - -class TestPrjectFlagsMovedDeprecation: - @pytest.fixture(scope="class") - def profiles_config_update(self): - return { - "config": {"send_anonymous_usage_stats": False}, - } - - @pytest.fixture(scope="class") - def dbt_project_yml(self, project_root, project_config_update): - project_config = { - "name": "test", - "profile": "test", - } - write_file(yaml.safe_dump(project_config), project_root, "dbt_project.yml") - return project_config - - @pytest.fixture(scope="class") - def models(self): - return {"my_model.sql": "select 1 as fun"} - - def test_profile_config_deprecation(self, project): - reset_deprecations() - assert active_deprecations == set() - run_dbt(["parse"]) - expected = {"project-flags-moved"} - assert expected == active_deprecations