|
| 1 | +import json |
| 2 | +import pathlib |
1 | 3 | import pytest |
2 | 4 |
|
3 | 5 | from dbt.cli.main import dbtRunner |
4 | | -from dbt.exceptions import DbtRuntimeError, TargetNotFoundError |
| 6 | +from dbt.exceptions import DbtRuntimeError, Exception as DbtException |
5 | 7 | from dbt.tests.util import run_dbt, run_dbt_and_capture |
6 | 8 | from tests.functional.compile.fixtures import ( |
7 | 9 | first_model_sql, |
@@ -137,9 +139,7 @@ def test_select_pass_empty(self, project): |
137 | 139 | assert "Compiled node 'second_model' is:" in log_output |
138 | 140 |
|
139 | 141 | def test_inline_fail(self, project): |
140 | | - with pytest.raises( |
141 | | - TargetNotFoundError, match="depends on a node named 'third_model' which was not found" |
142 | | - ): |
| 142 | + with pytest.raises(DbtException, match="Error parsing inline query"): |
143 | 143 | run_dbt(["compile", "--inline", "select * from {{ ref('third_model') }}"]) |
144 | 144 |
|
145 | 145 | def test_multiline_jinja(self, project): |
@@ -174,3 +174,28 @@ def test_compile_inline_not_add_node(self, project): |
174 | 174 | populate_cache=False, |
175 | 175 | ) |
176 | 176 | assert len(manifest.nodes) == 4 |
| 177 | + |
| 178 | + def test_compile_inline_syntax_error(self, project, mocker): |
| 179 | + patched_fire_event = mocker.patch("dbt.task.compile.fire_event") |
| 180 | + with pytest.raises(DbtException, match="Error parsing inline query"): |
| 181 | + run_dbt(["compile", "--inline", "select * from {{ ref(1) }}"]) |
| 182 | + # Event for parsing error fired |
| 183 | + patched_fire_event.assert_called_once() |
| 184 | + |
| 185 | + def test_compile_inline_ref_node_not_exist(self, project, mocker): |
| 186 | + patched_fire_event = mocker.patch("dbt.task.compile.fire_event") |
| 187 | + with pytest.raises(DbtException, match="Error parsing inline query"): |
| 188 | + run_dbt(["compile", "--inline", "select * from {{ ref('third_model') }}"]) |
| 189 | + # Event for parsing error fired |
| 190 | + patched_fire_event.assert_called_once() |
| 191 | + |
| 192 | + def test_graph_summary_output(self, project): |
| 193 | + """Ensure that the compile command generates a file named graph_summary.json |
| 194 | + in the target directory, that the file contains valid json, and that the |
| 195 | + json has the high level structure it should.""" |
| 196 | + dbtRunner().invoke(["compile"]) |
| 197 | + summary_path = pathlib.Path(project.project_root, "target/graph_summary.json") |
| 198 | + with open(summary_path, "r") as summary_file: |
| 199 | + summary = json.load(summary_file) |
| 200 | + assert "_invocation_id" in summary |
| 201 | + assert "linked" in summary |
0 commit comments