This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 63b4a7104e Refactor: use tmp_path in databricks test (#33541)
63b4a7104e is described below
commit 63b4a7104eed453c03528a36f8d2c6ec10206e4d
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Sun Aug 20 21:55:15 2023 +0000
Refactor: use tmp_path in databricks test (#33541)
---
.../databricks/operators/test_databricks_sql.py | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/tests/providers/databricks/operators/test_databricks_sql.py
b/tests/providers/databricks/operators/test_databricks_sql.py
index 5c5d4c92af..539727e787 100644
--- a/tests/providers/databricks/operators/test_databricks_sql.py
+++ b/tests/providers/databricks/operators/test_databricks_sql.py
@@ -18,7 +18,6 @@
from __future__ import annotations
import os
-import tempfile
from unittest.mock import patch
import pytest
@@ -268,16 +267,18 @@ def test_return_value_serialization():
),
],
)
-def test_exec_write_file(return_last, split_statements, sql, descriptions,
hook_results, do_xcom_push):
+def test_exec_write_file(
+ return_last, split_statements, sql, descriptions, hook_results,
do_xcom_push, tmp_path
+):
"""
Test the execute function in case where SQL query was successful and data
is written as CSV
"""
with
patch("airflow.providers.databricks.operators.databricks_sql.DatabricksSqlHook")
as db_mock_class:
- tempfile_path = tempfile.mkstemp()[1]
+ path = tmp_path / "testfile"
op = DatabricksSqlOperator(
task_id=TASK_ID,
sql=sql,
- output_path=tempfile_path,
+ output_path=os.fspath(path),
return_last=return_last,
do_xcom_push=do_xcom_push,
split_statements=split_statements,
@@ -287,11 +288,8 @@ def test_exec_write_file(return_last, split_statements,
sql, descriptions, hook_
db_mock.run.return_value = mock_results
db_mock.descriptions = descriptions
- try:
- op.execute(None)
- results = [line.strip() for line in open(tempfile_path)]
- finally:
- os.remove(tempfile_path)
+ op.execute(None)
+ results = path.read_text().splitlines()
# In all cases only result of last query i output as file
assert results == ["id,value", "1,value1", "2,value2"]
db_mock_class.assert_called_once_with(