Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2045 from fishtown-analytics/feature/detect-dupli…
…cate-macros Detect duplicate macros (#1891)
- Loading branch information
Showing
8 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
test/integration/006_simple_dependency_test/local_dependency/macros/dep_macro.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% macro some_overridden_macro() -%} | ||
100 | ||
{%- endmacro %} |
4 changes: 4 additions & 0 deletions
4
test/integration/006_simple_dependency_test/macros/main_macro.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{# This macro also exists in the dependency -dbt should be fine with that #} | ||
{% macro some_overridden_macro() -%} | ||
999 | ||
{%- endmacro %} |
5 changes: 5 additions & 0 deletions
5
test/integration/025_duplicate_model_test/macros-bad-same/macros.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% macro some_macro() %} | ||
{% endmacro %} | ||
|
||
{% macro some_macro() %} | ||
{% endmacro %} |
2 changes: 2 additions & 0 deletions
2
test/integration/025_duplicate_model_test/macros-bad-separate/one.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% macro some_macro() %} | ||
{% endmacro %} |
2 changes: 2 additions & 0 deletions
2
test/integration/025_duplicate_model_test/macros-bad-separate/two.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{% macro some_macro() %} | ||
{% endmacro %} |
52 changes: 52 additions & 0 deletions
52
test/integration/025_duplicate_model_test/test_duplicate_macro.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
from dbt.exceptions import CompilationException | ||
from test.integration.base import DBTIntegrationTest, use_profile | ||
|
||
|
||
class TestDuplicateMacroEnabledSameFile(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_macro_025" | ||
|
||
@property | ||
def models(self): | ||
return "models-3" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'macro-paths': ['macros-bad-same'] | ||
} | ||
|
||
@use_profile('postgres') | ||
def test_postgres_duplicate_macros(self): | ||
with self.assertRaises(CompilationException) as exc: | ||
self.run_dbt(['compile']) | ||
self.assertIn('some_macro', str(exc.exception)) | ||
self.assertIn(os.path.join('macros-bad-same', 'macros.sql'), str(exc.exception)) | ||
|
||
|
||
class TestDuplicateMacroEnabledDifferentFiles(DBTIntegrationTest): | ||
|
||
@property | ||
def schema(self): | ||
return "duplicate_macro_025" | ||
|
||
@property | ||
def models(self): | ||
return "models-3" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
'macro-paths': ['macros-bad-separate'] | ||
} | ||
|
||
@use_profile('postgres') | ||
def test_postgres_duplicate_macros(self): | ||
with self.assertRaises(CompilationException) as exc: | ||
self.run_dbt(['compile']) | ||
self.assertIn('some_macro', str(exc.exception)) | ||
self.assertIn(os.path.join('macros-bad-separate', 'one.sql'), str(exc.exception)) | ||
self.assertIn(os.path.join('macros-bad-separate', 'two.sql'), str(exc.exception)) |