Skip to content

Commit

Permalink
add tests for compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyuLInx committed Jun 28, 2023
1 parent 8620b98 commit 89f17eb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion core/dbt/task/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,16 @@ def _runtime_initialize(self):
# keep track of the node added to the manifest
self._inline_node_id = sql_node.unique_id
except CompilationError as exc:
fire_event(ParseNodeError(exc=str(exc.msg), node_info=sql_node.node_info))
fire_event(
ParseNodeError(
exc=str(exc.msg),
node_info={
"node_path": "sql/inline_query",
"node_name": "inline_query",
"unique_id": "sqloperation.test.inline_query",
},
)
)
raise DbtException("Error parsing inline query")
super()._runtime_initialize()

Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ types-pytz
types-requests
types-setuptools
wheel
mocker
19 changes: 15 additions & 4 deletions tests/functional/compile/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,23 @@ def test_compile_inline_not_add_node(self, project):
manifest = parse_result.result
assert len(manifest.nodes) == 4
dbt = dbtRunner(manifest=manifest)
dbt.invoke(
["compile", "--inline", "select * from {{ ref('second_model') }}"],
populate_cache=False,
)
dbt = dbtRunner()
assert len(manifest.nodes) == 4

def test_compile_inline_syntax_error(self, project, mocker):
patched_fire_event = mocker.patch("dbt.task.compile.fire_event")
dbt = dbtRunner()
res = dbt.invoke(["compile", "--inline", "select * from {{ ref(1) }}"])
patched_fire_event.assert_called_once()
assert str(res.exception) == "Error parsing inline query"

def test_compile_inline_ref_node_not_exist(self, project, mocker):
patched_fire_event = mocker.patch("dbt.task.compile.fire_event")
dbt = dbtRunner()
res = dbt.invoke(["compile", "--inline", "select * from {{ ref('i') }}"])
patched_fire_event.assert_called_once()
assert str(res.exception) == "Error parsing inline query"

def test_graph_summary_output(self, project):
"""Ensure that the compile command generates a file named graph_summary.json
in the target directory, that the file contains valid json, and that the
Expand Down

0 comments on commit 89f17eb

Please sign in to comment.