mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-07-05 16:19:35 +00:00

* Make pytest to user code from src rather than from install package * Fix test_amundsen: missing None * Update pytest configuration to use importlib mode * Fix custom_basemodel_validation to check model_fields on type(values) to prevent noisy warnings * Refactor referencedByQueries validation to use field_validator as per deprecation warning * Update ColumnJson to use model_rebuild rather as replacement for forward reference updates as per deprecation warning * Move superset test to integration test as they are using testcontainers * Update coverage source path * Fix wrong import. * Add install_dev_env target to Makefile for development dependencies * Add test-unit as extra in setup.py * Modify dependencies in dev environment. * Ignore all airflow tests * Remove coverage in unit_ingestion_dev_env. Revert coverage source to prevent broken CI. * Add nox for running unit test * FIx PowerBI integration test to use pathlib for resource paths and not os.getcwd to prevent failures when not executed from the right path * Move test_helpers.py to unit test, as it is not an integration test. * Remove utils empty folder in integration tests * Refactor testcontainers configuration to avoid pitfalls with max_tries setting * Add nox unit testing basic setup * Add format check session * Refactor nox-unit and add plugins tests * Add GHA for py-nox-ci * Add comment to GHA * Restore conftest.py file * Clarify comment * Simplify function * Fix matrix startegy and nox mismatch * Improve python version strategy with nox and GHA --------- Co-authored-by: Pere Menal <pere.menal@getcollate.io>
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# Copyright 2025 Collate
|
|
# Licensed under the Collate Community License, Version 1.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
|
|
# 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.
|
|
"""
|
|
Test helpers
|
|
"""
|
|
import uuid
|
|
from unittest import TestCase
|
|
|
|
from metadata.generated.schema.entity.data.table import Column, DataType, Table
|
|
from metadata.utils.helpers import (
|
|
find_column_in_table,
|
|
find_column_in_table_with_index,
|
|
find_in_iter,
|
|
)
|
|
|
|
|
|
class HelpersTest(TestCase):
|
|
def test_find_in_iter(self):
|
|
"""We can find elements within a list"""
|
|
iter_ = ("A", "B", "C")
|
|
|
|
found = find_in_iter(element="B", container=iter_)
|
|
self.assertEqual("B", found)
|
|
|
|
not_found = find_in_iter(element="random", container=iter_)
|
|
self.assertIsNone(not_found)
|
|
|
|
def test_find_column_in_table(self):
|
|
"""Check we can find a column inside a table"""
|
|
|
|
table = Table(
|
|
id=uuid.uuid4(),
|
|
name="test",
|
|
fullyQualifiedName="test-service-table.test-db.test-schema.test",
|
|
columns=[
|
|
Column(name="id", dataType=DataType.BIGINT),
|
|
Column(name="hello", dataType=DataType.BIGINT),
|
|
Column(name="foo", dataType=DataType.BIGINT),
|
|
Column(name="bar", dataType=DataType.BIGINT),
|
|
],
|
|
)
|
|
|
|
col = find_column_in_table(column_name="foo", table=table)
|
|
self.assertEqual(col, Column(name="foo", dataType=DataType.BIGINT))
|
|
|
|
not_found = find_column_in_table(column_name="random", table=table)
|
|
self.assertIsNone(not_found)
|
|
|
|
idx, col = find_column_in_table_with_index(column_name="foo", table=table)
|
|
self.assertEqual(col, Column(name="foo", dataType=DataType.BIGINT))
|
|
self.assertEqual(idx, 2)
|
|
|
|
not_found_col, not_found_idx = find_column_in_table_with_index(
|
|
column_name="random", table=table
|
|
)
|
|
self.assertIsNone(not_found)
|
|
self.assertIsNone(not_found_idx)
|
|
|
|
col = find_column_in_table(column_name="FOO", table=table, case_sensitive=False)
|
|
self.assertEqual(col, Column(name="foo", dataType=DataType.BIGINT))
|