From a3e052ddda8dfe30b9e16dd550b80f00f4da3381 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Sat, 14 Jan 2023 14:12:08 +0100 Subject: [PATCH] Rm defer_state_test --- .../macros/infinite_macros.sql | 13 -- .../defer_state_test/macros/macros.sql | 3 - .../models/ephemeral_model.sql | 2 - .../defer_state_test/models/exposures.yml | 8 - .../defer_state_test/models/schema.yml | 9 -- .../defer_state_test/models/table_model.sql | 5 - .../defer_state_test/models/view_model.sql | 4 - .../defer_state_test/seeds/seed.csv | 3 - .../defer_state_test/test_defer_state.py | 152 ------------------ 9 files changed, 199 deletions(-) delete mode 100644 tests/integration/defer_state_test/macros/infinite_macros.sql delete mode 100644 tests/integration/defer_state_test/macros/macros.sql delete mode 100644 tests/integration/defer_state_test/models/ephemeral_model.sql delete mode 100644 tests/integration/defer_state_test/models/exposures.yml delete mode 100644 tests/integration/defer_state_test/models/schema.yml delete mode 100644 tests/integration/defer_state_test/models/table_model.sql delete mode 100644 tests/integration/defer_state_test/models/view_model.sql delete mode 100644 tests/integration/defer_state_test/seeds/seed.csv delete mode 100644 tests/integration/defer_state_test/test_defer_state.py diff --git a/tests/integration/defer_state_test/macros/infinite_macros.sql b/tests/integration/defer_state_test/macros/infinite_macros.sql deleted file mode 100644 index 81d2083d3..000000000 --- a/tests/integration/defer_state_test/macros/infinite_macros.sql +++ /dev/null @@ -1,13 +0,0 @@ -{# trigger infinite recursion if not handled #} - -{% macro my_infinitely_recursive_macro() %} - {{ return(adapter.dispatch('my_infinitely_recursive_macro')()) }} -{% endmacro %} - -{% macro default__my_infinitely_recursive_macro() %} - {% if unmet_condition %} - {{ my_infinitely_recursive_macro() }} - {% else %} - {{ return('') }} - {% endif %} -{% endmacro %} diff --git a/tests/integration/defer_state_test/macros/macros.sql b/tests/integration/defer_state_test/macros/macros.sql deleted file mode 100644 index 79519c1b6..000000000 --- a/tests/integration/defer_state_test/macros/macros.sql +++ /dev/null @@ -1,3 +0,0 @@ -{% macro my_macro() %} - {% do log('in a macro' ) %} -{% endmacro %} diff --git a/tests/integration/defer_state_test/models/ephemeral_model.sql b/tests/integration/defer_state_test/models/ephemeral_model.sql deleted file mode 100644 index 2f976e3a9..000000000 --- a/tests/integration/defer_state_test/models/ephemeral_model.sql +++ /dev/null @@ -1,2 +0,0 @@ -{{ config(materialized='ephemeral') }} -select * from {{ ref('view_model') }} diff --git a/tests/integration/defer_state_test/models/exposures.yml b/tests/integration/defer_state_test/models/exposures.yml deleted file mode 100644 index 489dec3c3..000000000 --- a/tests/integration/defer_state_test/models/exposures.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: 2 -exposures: - - name: my_exposure - type: application - depends_on: - - ref('view_model') - owner: - email: test@example.com diff --git a/tests/integration/defer_state_test/models/schema.yml b/tests/integration/defer_state_test/models/schema.yml deleted file mode 100644 index 1ec506d3d..000000000 --- a/tests/integration/defer_state_test/models/schema.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: 2 -models: - - name: view_model - columns: - - name: id - tests: - - unique - - not_null - - name: name diff --git a/tests/integration/defer_state_test/models/table_model.sql b/tests/integration/defer_state_test/models/table_model.sql deleted file mode 100644 index 65909318b..000000000 --- a/tests/integration/defer_state_test/models/table_model.sql +++ /dev/null @@ -1,5 +0,0 @@ -{{ config(materialized='table') }} -select * from {{ ref('ephemeral_model') }} - --- establish a macro dependency to trigger state:modified.macros --- depends on: {{ my_macro() }} \ No newline at end of file diff --git a/tests/integration/defer_state_test/models/view_model.sql b/tests/integration/defer_state_test/models/view_model.sql deleted file mode 100644 index 72cb07a5e..000000000 --- a/tests/integration/defer_state_test/models/view_model.sql +++ /dev/null @@ -1,4 +0,0 @@ -select * from {{ ref('seed') }} - --- establish a macro dependency that trips infinite recursion if not handled --- depends on: {{ my_infinitely_recursive_macro() }} \ No newline at end of file diff --git a/tests/integration/defer_state_test/seeds/seed.csv b/tests/integration/defer_state_test/seeds/seed.csv deleted file mode 100644 index 1a728c8ab..000000000 --- a/tests/integration/defer_state_test/seeds/seed.csv +++ /dev/null @@ -1,3 +0,0 @@ -id,name -1,Alice -2,Bob diff --git a/tests/integration/defer_state_test/test_defer_state.py b/tests/integration/defer_state_test/test_defer_state.py deleted file mode 100644 index 2d14c6103..000000000 --- a/tests/integration/defer_state_test/test_defer_state.py +++ /dev/null @@ -1,152 +0,0 @@ -from tests.integration.base import DBTIntegrationTest, use_profile -import copy -import json -import os -import shutil - - -class TestDeferState(DBTIntegrationTest): - @property - def schema(self): - return "defer_state" - - @property - def models(self): - return "models" - - def setUp(self): - self.other_schema = None - super().setUp() - self._created_schemas.add(self.other_schema) - - @property - def project_config(self): - return { - 'config-version': 2, - 'seeds': { - 'test': { - 'quote_columns': False, - } - } - } - - def get_profile(self, adapter_type): - if self.other_schema is None: - self.other_schema = self.unique_schema() + '_other' - self.other_schema = self.other_schema.upper() - profile = super().get_profile(adapter_type) - default_name = profile['test']['target'] - profile['test']['outputs']['otherschema'] = copy.deepcopy(profile['test']['outputs'][default_name]) - profile['test']['outputs']['otherschema']['schema'] = self.other_schema - return profile - - def copy_state(self): - assert not os.path.exists('state') - os.makedirs('state') - shutil.copyfile('target/manifest.json', 'state/manifest.json') - - def run_and_defer(self): - results = self.run_dbt(['seed']) - assert len(results) == 1 - assert not any(r.node.deferred for r in results) - results = self.run_dbt(['run']) - assert len(results) == 2 - assert not any(r.node.deferred for r in results) - results = self.run_dbt(['test']) - assert len(results) == 2 - - # copy files over from the happy times when we had a good target - self.copy_state() - - # test tests first, because run will change things - # no state, wrong schema, failure. - self.run_dbt(['test', '--target', 'otherschema'], expect_pass=False) - - # no state, run also fails - self.run_dbt(['run', '--target', 'otherschema'], expect_pass=False) - - # defer test, it succeeds - results = self.run_dbt(['test', '-m', 'view_model+', '--state', 'state', '--defer', '--target', 'otherschema']) - - # with state it should work though - results = self.run_dbt(['run', '-m', 'view_model', '--state', 'state', '--defer', '--target', 'otherschema']) - assert self.other_schema not in results[0].node.compiled_code - assert self.unique_schema() in results[0].node.compiled_code - - with open('target/manifest.json') as fp: - data = json.load(fp) - assert data['nodes']['seed.test.seed']['deferred'] - - assert len(results) == 1 - - def run_switchdirs_defer(self): - results = self.run_dbt(['seed']) - assert len(results) == 1 - results = self.run_dbt(['run']) - assert len(results) == 2 - - # copy files over from the happy times when we had a good target - self.copy_state() - - self.use_default_project({'model-paths': ['changed_models']}) - # the sql here is just wrong, so it should fail - self.run_dbt( - ['run', '-m', 'view_model', '--state', 'state', '--defer', '--target', 'otherschema'], - expect_pass=False, - ) - # but this should work since we just use the old happy model - self.run_dbt( - ['run', '-m', 'table_model', '--state', 'state', '--defer', '--target', 'otherschema'], - expect_pass=True, - ) - - self.use_default_project({'model-paths': ['changed_models_bad']}) - # this should fail because the table model refs a broken ephemeral - # model, which it should see - self.run_dbt( - ['run', '-m', 'table_model', '--state', 'state', '--defer', '--target', 'otherschema'], - expect_pass=False, - ) - - def run_defer_iff_not_exists(self): - results = self.run_dbt(['seed', '--target', 'otherschema']) - assert len(results) == 1 - results = self.run_dbt(['run', '--target', 'otherschema']) - assert len(results) == 2 - - # copy files over from the happy times when we had a good target - self.copy_state() - results = self.run_dbt(['seed']) - assert len(results) == 1 - results = self.run_dbt(['run', '--state', 'state', '--defer']) - assert len(results) == 2 - - # because the seed now exists in our schema, we shouldn't defer it - assert self.other_schema not in results[0].node.compiled_code - assert self.unique_schema() in results[0].node.compiled_code - - def run_defer_deleted_upstream(self): - results = self.run_dbt(['seed']) - assert len(results) == 1 - results = self.run_dbt(['run']) - assert len(results) == 2 - - # copy files over from the happy times when we had a good target - self.copy_state() - - self.use_default_project({'model-paths': ['changed_models_missing']}) - # ephemeral_model is now gone. previously this caused a - # keyerror (dbt#2875), now it should pass - self.run_dbt( - ['run', '-m', 'view_model', '--state', 'state', '--defer', '--target', 'otherschema'], - expect_pass=True, - ) - - # despite deferral, test should use models just created in our schema - results = self.run_dbt(['test', '--state', 'state', '--defer']) - assert self.other_schema not in results[0].node.compiled_code - assert self.unique_schema() in results[0].node.compiled_code - - @use_profile('snowflake') - def test_snowflake_state_changetarget(self): - self.run_and_defer()