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 d1ad3470cb tests: Add missing tests for OpenLineage (#39111)
d1ad3470cb is described below
commit d1ad3470cb549e23e4f11f82b1ead47eb1fac5d9
Author: Kacper Muda <[email protected]>
AuthorDate: Thu Apr 18 14:08:17 2024 +0200
tests: Add missing tests for OpenLineage (#39111)
Signed-off-by: Kacper Muda <[email protected]>
---
tests/always/test_project_structure.py | 3 --
...test_openlineage_adapter.py => test_adapter.py} | 0
tests/providers/openlineage/plugins/test_facets.py | 37 +++++++++++++++
.../openlineage/{utils => }/test_sqlparser.py | 53 +++++++++++++++++++++-
4 files changed, 89 insertions(+), 4 deletions(-)
diff --git a/tests/always/test_project_structure.py
b/tests/always/test_project_structure.py
index d14885aca9..4341dd1aec 100644
--- a/tests/always/test_project_structure.py
+++ b/tests/always/test_project_structure.py
@@ -158,9 +158,6 @@ class TestProjectStructure:
"tests/providers/microsoft/azure/operators/test_adls.py",
"tests/providers/microsoft/azure/transfers/test_azure_blob_to_gcs.py",
"tests/providers/mongo/sensors/test_mongo.py",
- "tests/providers/openlineage/plugins/test_adapter.py",
- "tests/providers/openlineage/plugins/test_facets.py",
- "tests/providers/openlineage/test_sqlparser.py",
"tests/providers/redis/operators/test_redis_publish.py",
"tests/providers/redis/sensors/test_redis_key.py",
"tests/providers/slack/notifications/test_slack_notifier.py",
diff --git a/tests/providers/openlineage/plugins/test_openlineage_adapter.py
b/tests/providers/openlineage/plugins/test_adapter.py
similarity index 100%
rename from tests/providers/openlineage/plugins/test_openlineage_adapter.py
rename to tests/providers/openlineage/plugins/test_adapter.py
diff --git a/tests/providers/openlineage/plugins/test_facets.py
b/tests/providers/openlineage/plugins/test_facets.py
new file mode 100644
index 0000000000..dd4e5851f2
--- /dev/null
+++ b/tests/providers/openlineage/plugins/test_facets.py
@@ -0,0 +1,37 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from airflow.providers.openlineage.plugins.facets import AirflowRunFacet
+
+
+def test_airflow_run_facet():
+ dag = {"dag_id": "123"}
+ dag_run = {"dag_run_id": "456"}
+ task = {"task_id": "789"}
+ task_instance = {"task_instance_id": "000"}
+ task_uuid = "XXX"
+
+ airflow_run_facet = AirflowRunFacet(
+ dag=dag, dagRun=dag_run, task=task, taskInstance=task_instance,
taskUuid=task_uuid
+ )
+
+ assert airflow_run_facet.dag == dag
+ assert airflow_run_facet.dagRun == dag_run
+ assert airflow_run_facet.task == task
+ assert airflow_run_facet.taskInstance == task_instance
+ assert airflow_run_facet.taskUuid == task_uuid
diff --git a/tests/providers/openlineage/utils/test_sqlparser.py
b/tests/providers/openlineage/test_sqlparser.py
similarity index 87%
rename from tests/providers/openlineage/utils/test_sqlparser.py
rename to tests/providers/openlineage/test_sqlparser.py
index 24967f56b6..22bd067422 100644
--- a/tests/providers/openlineage/utils/test_sqlparser.py
+++ b/tests/providers/openlineage/test_sqlparser.py
@@ -32,7 +32,7 @@ from openlineage.client.run import Dataset
from openlineage.common.sql import DbTableMeta
from airflow.providers.openlineage.extractors import OperatorLineage
-from airflow.providers.openlineage.sqlparser import DatabaseInfo, SQLParser
+from airflow.providers.openlineage.sqlparser import DatabaseInfo,
GetTableSchemasParams, SQLParser
DB_NAME = "FOOD_DELIVERY"
DB_SCHEMA_NAME = "PUBLIC"
@@ -41,6 +41,57 @@ DB_TABLE_NAME = DbTableMeta("DISCOUNTS")
NAMESPACE = "test_namespace"
+def test_get_table_schemas_params():
+ def _inner(x: str) -> str:
+ return x
+
+ result = GetTableSchemasParams(
+ normalize_name=_inner,
+ is_cross_db=False,
+ information_schema_columns=["col1", "col2"],
+ information_schema_table="table",
+ use_flat_cross_db_query=True,
+ is_uppercase_names=False,
+ database="db",
+ )
+
+ assert result["normalize_name"] == _inner
+ assert result["is_cross_db"] is False
+ assert result["information_schema_columns"] == ["col1", "col2"]
+ assert result["information_schema_table"] == "table"
+ assert result["use_flat_cross_db_query"] is True
+ assert result["is_uppercase_names"] is False
+ assert result["database"] == "db"
+
+
+def test_database_info():
+ def _inner(x: str) -> str:
+ return x
+
+ result = DatabaseInfo(
+ scheme="scheme",
+ authority="authority",
+ database="database",
+ information_schema_columns=["col1", "col2"],
+ information_schema_table_name="table",
+ use_flat_cross_db_query=True,
+ is_information_schema_cross_db=True,
+ is_uppercase_names=False,
+ normalize_name_method=_inner,
+ )
+
+ assert result.scheme == "scheme"
+ assert result.authority == "authority"
+ assert result.database == "database"
+ assert result.information_schema_columns == ["col1", "col2"]
+ assert result.information_schema_table_name == "table"
+ assert result.use_flat_cross_db_query is True
+ assert result.is_information_schema_cross_db is True
+ assert result.is_uppercase_names is False
+ assert result.is_uppercase_names is False
+ assert result.normalize_name_method == _inner
+
+
def normalize_name_lower(name: str) -> str:
return name.lower()