From 5b82a2c5a71d9bb8290a712d5a25ededc83f63e3 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 18 Oct 2022 15:45:23 -0400 Subject: [PATCH] convert 027 cycle test --- .../complex_cycle_models/model_a.sql | 2 - .../complex_cycle_models/model_b.sql | 4 -- .../complex_cycle_models/model_c.sql | 2 - .../complex_cycle_models/model_d.sql | 2 - .../complex_cycle_models/model_e.sql | 2 - .../complex_cycle_models/readme | 7 -- .../simple_cycle_models/model_a.sql | 2 - .../simple_cycle_models/model_b.sql | 2 - .../027_cycle_tests/test_cycles.py | 37 ---------- tests/functional/cycles/test_cycles.py | 71 +++++++++++++++++++ 10 files changed, 71 insertions(+), 60 deletions(-) delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/model_a.sql delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/model_b.sql delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/model_c.sql delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/model_d.sql delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/model_e.sql delete mode 100644 test/integration/027_cycle_tests/complex_cycle_models/readme delete mode 100644 test/integration/027_cycle_tests/simple_cycle_models/model_a.sql delete mode 100644 test/integration/027_cycle_tests/simple_cycle_models/model_b.sql delete mode 100644 test/integration/027_cycle_tests/test_cycles.py create mode 100644 tests/functional/cycles/test_cycles.py diff --git a/test/integration/027_cycle_tests/complex_cycle_models/model_a.sql b/test/integration/027_cycle_tests/complex_cycle_models/model_a.sql deleted file mode 100644 index 2cd691ea7b4..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/model_a.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select 1 as id diff --git a/test/integration/027_cycle_tests/complex_cycle_models/model_b.sql b/test/integration/027_cycle_tests/complex_cycle_models/model_b.sql deleted file mode 100644 index da16daedfdb..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/model_b.sql +++ /dev/null @@ -1,4 +0,0 @@ - -select * from {{ ref('model_a') }} -union all -select * from {{ ref('model_e') }} diff --git a/test/integration/027_cycle_tests/complex_cycle_models/model_c.sql b/test/integration/027_cycle_tests/complex_cycle_models/model_c.sql deleted file mode 100644 index 741b6cce028..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/model_c.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select * from {{ ref('model_b') }} diff --git a/test/integration/027_cycle_tests/complex_cycle_models/model_d.sql b/test/integration/027_cycle_tests/complex_cycle_models/model_d.sql deleted file mode 100644 index 954ca668936..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/model_d.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select * from {{ ref('model_c') }} diff --git a/test/integration/027_cycle_tests/complex_cycle_models/model_e.sql b/test/integration/027_cycle_tests/complex_cycle_models/model_e.sql deleted file mode 100644 index 9f689ae55df..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/model_e.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select * from {{ ref('model_e') }} diff --git a/test/integration/027_cycle_tests/complex_cycle_models/readme b/test/integration/027_cycle_tests/complex_cycle_models/readme deleted file mode 100644 index 5f95aba0473..00000000000 --- a/test/integration/027_cycle_tests/complex_cycle_models/readme +++ /dev/null @@ -1,7 +0,0 @@ - -The cycle in this graph looks like: - -A -> B -> C -> D - ^ | - | | - +--- E <--+ diff --git a/test/integration/027_cycle_tests/simple_cycle_models/model_a.sql b/test/integration/027_cycle_tests/simple_cycle_models/model_a.sql deleted file mode 100644 index 741b6cce028..00000000000 --- a/test/integration/027_cycle_tests/simple_cycle_models/model_a.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select * from {{ ref('model_b') }} diff --git a/test/integration/027_cycle_tests/simple_cycle_models/model_b.sql b/test/integration/027_cycle_tests/simple_cycle_models/model_b.sql deleted file mode 100644 index 67176d4b2b4..00000000000 --- a/test/integration/027_cycle_tests/simple_cycle_models/model_b.sql +++ /dev/null @@ -1,2 +0,0 @@ - -select * from {{ ref('model_a') }} diff --git a/test/integration/027_cycle_tests/test_cycles.py b/test/integration/027_cycle_tests/test_cycles.py deleted file mode 100644 index 9312a76ac84..00000000000 --- a/test/integration/027_cycle_tests/test_cycles.py +++ /dev/null @@ -1,37 +0,0 @@ -from freezegun import freeze_time -from test.integration.base import DBTIntegrationTest, use_profile - - -class TestSimpleCycle(DBTIntegrationTest): - - @property - def schema(self): - return "cycles_simple_027" - - @property - def models(self): - return "simple_cycle_models" - - @property - @use_profile('postgres') - def test_postgres_simple_cycle(self): - message = "Found a cycle.*" - with self.assertRaisesRegex(Exception, message): - self.run_dbt(["run"]) - -class TestComplexCycle(DBTIntegrationTest): - - @property - def schema(self): - return "cycles_complex_027" - - @property - def models(self): - return "complex_cycle_models" - - @property - @use_profile('postgres') - def test_postgres_simple_cycle(self): - message = "Found a cycle.*" - with self.assertRaisesRegex(Exception, message): - self.run_dbt(["run"]) diff --git a/tests/functional/cycles/test_cycles.py b/tests/functional/cycles/test_cycles.py new file mode 100644 index 00000000000..5ad2e37062e --- /dev/null +++ b/tests/functional/cycles/test_cycles.py @@ -0,0 +1,71 @@ +import pytest + +from dbt.tests.util import run_dbt + +model_a_sql = """ +select * from {{ ref('model_b') }} +""" + +model_b_sql = """ +select * from {{ ref('model_a') }} +""" + +complex_cycle__model_a_sql = """ +select 1 as id +""" + +complex_cycle__model_b_sql = """ +select * from {{ ref('model_a') }}s +union all +select * from {{ ref('model_e') }} +""" + +complex_cycle__model_c_sql = """ +select * from {{ ref('model_b') }} +""" + +complex_cycle__model_d_sql = """ +select * from {{ ref('model_c') }} +""" + +complex_cycle__model_e_sql = """ +select * from {{ ref('model_e') }} +""" + + +class TestSimpleCycle: + @pytest.fixture(scope="class") + def models(self): + return { + "model_a.sql": model_a_sql, + "model_b.sql": model_b_sql + } + + def test_postgres_simple_cycle(self, project): + with pytest.raises(RuntimeError) as exc: + run_dbt(["run"], expect_pass=False) + expected_msg = "Found a cycle" + assert expected_msg in str(exc.value) + + +class TestComplexCycle: + @pytest.fixture(scope="class") + def models(self): + # The cycle in this graph looks like: + # A -> B -> C -> D + # ^ | + # | | + # +--- E <--+ + return { + "model_a.sql": complex_cycle__model_a_sql, + "model_b.sql": complex_cycle__model_b_sql, + "model_c.sql": complex_cycle__model_c_sql, + "model_d.sql": complex_cycle__model_d_sql, + "model_e.sql": complex_cycle__model_e_sql, + } + + def test_postgres_complex_cycle(self, project): + with pytest.raises(RuntimeError) as exc: + run_dbt(["run"], expect_pass=False) + expected_msg = "Found a cycle" + assert expected_msg in str(exc.value)