From 5a096676f5edcbf011e58319541d3761a59eb5ce Mon Sep 17 00:00:00 2001 From: Drew Banin Date: Fri, 9 Dec 2016 18:56:02 -0500 Subject: [PATCH] negative testing --- .../016_macro_tests/bad-macros/bad_macros.sql | 7 +++ .../016_macro_tests/bad-models/dep_macro.sql | 5 ++ .../016_macro_tests/test_macros.py | 61 ++++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/integration/016_macro_tests/bad-macros/bad_macros.sql create mode 100644 test/integration/016_macro_tests/bad-models/dep_macro.sql diff --git a/test/integration/016_macro_tests/bad-macros/bad_macros.sql b/test/integration/016_macro_tests/bad-macros/bad_macros.sql new file mode 100644 index 00000000000..36840cb9a78 --- /dev/null +++ b/test/integration/016_macro_tests/bad-macros/bad_macros.sql @@ -0,0 +1,7 @@ + +{% macro invalid_macro() %} + + select + '{{ foo2 }}' as foo2, + '{{ bar2 }}' as bar2 + diff --git a/test/integration/016_macro_tests/bad-models/dep_macro.sql b/test/integration/016_macro_tests/bad-models/dep_macro.sql new file mode 100644 index 00000000000..eb14d73ad5d --- /dev/null +++ b/test/integration/016_macro_tests/bad-models/dep_macro.sql @@ -0,0 +1,5 @@ + +-- try to globally reference a dependency macro +{{ + do_something("arg1", "arg2") +}} diff --git a/test/integration/016_macro_tests/test_macros.py b/test/integration/016_macro_tests/test_macros.py index 6bad66e77b3..770ff625006 100644 --- a/test/integration/016_macro_tests/test_macros.py +++ b/test/integration/016_macro_tests/test_macros.py @@ -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