Skip to content

Commit

Permalink
negative testing
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbanin committed Dec 9, 2016
1 parent 6707c98 commit 5a09667
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions test/integration/016_macro_tests/bad-macros/bad_macros.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{% macro invalid_macro() %}

select
'{{ foo2 }}' as foo2,
'{{ bar2 }}' as bar2

5 changes: 5 additions & 0 deletions test/integration/016_macro_tests/bad-models/dep_macro.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

-- try to globally reference a dependency macro
{{
do_something("arg1", "arg2")
}}
61 changes: 60 additions & 1 deletion test/integration/016_macro_tests/test_macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,68 @@ def project_config(self):
]
}

def test_simple_dependency(self):
def test_working_macros(self):
self.run_dbt(["deps"])
self.run_dbt(["run"])

self.assertTablesEqual("expected_dep_macro","dep_macro")
self.assertTablesEqual("expected_local_macro","local_macro")


class TestInvalidMacros(DBTIntegrationTest):

def setUp(self):
DBTIntegrationTest.setUp(self)

@property
def schema(self):
return "test_macros_016"

@property
def models(self):
return "test/integration/016_macro_tests/models"

@property
def project_config(self):
return {
"macro-paths": ["test/integration/016_macro_tests/bad-macros"]
}

def test_invalid_macro(self):

try:
self.run_dbt(["compile"])
self.assertTrue(False, 'compiling bad macro should raise a runtime error')
except RuntimeError as e:
pass

class TestMisusedMacros(DBTIntegrationTest):

def setUp(self):
DBTIntegrationTest.setUp(self)

@property
def schema(self):
return "test_macros_016"

@property
def models(self):
return "test/integration/016_macro_tests/bad-models"

@property
def project_config(self):
return {
"macro-paths": ["test/integration/016_macro_tests/macros"],
"repositories": [
'https://github.com/fishtown-analytics/dbt-integration-project'
]
}

def test_working_macros(self):
self.run_dbt(["deps"])

try:
self.run_dbt(["run"])
self.assertTrue(False, 'invoked a package macro from global scope')
except RuntimeError as e:
pass

0 comments on commit 5a09667

Please sign in to comment.