Repository: apache/airflow
File: task-sdk/tests/task_sdk/test_lineage.py (Python)

Code before:
#
# 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 unittest.mock import MagicMock, patch

import pytest

from airflow.sdk import BaseHook, plugins_manager
from airflow.sdk.definitions.asset import Asset
from airflow.sdk.lineage import (
    AssetLineageInfo,
    HookLineage,
    HookLineageCollector,
    HookLineageReader,
    NoOpCollector,
    get_hook_lineage_collector,
)

from tests_common.test_utils.mock_plugins import mock_plugin_manager


class TestHookLineageCollector:
    @pytest.fixture  # default scope is function
    def collector(self):
        return HookLineageCollector()

    def test_generate_hash_handles_non_serializable(self, collector):
        class Obj:
            def __str__(self):
                return "<obj>"

        h1 = collector._generate_hash({"a": Obj()})
        h2 = collector._generate_hash({"a": "<obj>"})
        assert isinstance(h1, str)

Review comment (suggestion):
```suggestion
from airflow.sdk import Asset, BaseHook, plugins_manager
```

Code after:
#
# 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 unittest.mock import MagicMock, patch

import pytest

from airflow.sdk import Asset, BaseHook, plugins_manager
from airflow.sdk.lineage import (
    AssetLineageInfo,
    HookLineage,
    HookLineageCollector,
    HookLineageReader,
    NoOpCollector,
    get_hook_lineage_collector,
)

from tests_common.test_utils.mock_plugins import mock_plugin_manager


class TestHookLineageCollector:
    @pytest.fixture  # default scope is function
    def collector(self):
        return HookLineageCollector()

    def test_generate_hash_handles_non_serializable(self, collector):
        class Obj:
            def __str__(self):
                return "<obj>"

        h1 = collector._generate_hash({"a": Obj()})
        h2 = collector._generate_hash({"a": "<obj>"})
        assert isinstance(h1, str)
        assert h1 == h2