From f587bd97c2034c210469397a11d15761480ff6d0 Mon Sep 17 00:00:00 2001 From: Gabriel Igliozzi Date: Wed, 8 Oct 2025 19:52:05 -0400 Subject: [PATCH 1/3] consolidate register_table tests in test_catalog --- tests/integration/test_catalog.py | 45 ++++++++++++ tests/integration/test_register_table.py | 88 ------------------------ 2 files changed, 45 insertions(+), 88 deletions(-) delete mode 100644 tests/integration/test_register_table.py diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index b57ab983ba..34b0a830f3 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -355,3 +355,48 @@ def test_update_namespace_properties(test_catalog: Catalog, database_name: str) else: assert k in update_report.removed assert "updated test description" == test_catalog.load_namespace_properties(database_name)["comment"] + + +@pytest.mark.integration +@pytest.mark.parametrize("test_catalog", CATALOGS) +def test_register_table( + test_catalog: Catalog, + table_name: str, + database_name: str +) -> None: + identifier = (database_name, table_name) + + test_catalog.create_namespace_if_not_exists(database_name) + + table = test_catalog.create_table( + identifier=identifier, + schema=Schema(), + ) + + assert test_catalog.table_exists(identifier) + test_catalog.drop_table(identifier) + assert not test_catalog.table_exists(identifier) + test_catalog.register_table((database_name, "register_table"), metadata_location=table.metadata_location) + assert test_catalog.table_exists((database_name, "register_table")) + + +@pytest.mark.integration +@pytest.mark.parametrize("test_catalog", CATALOGS) +def test_register_table_existing( + test_catalog: Catalog, + table_name: str, + database_name: str +) -> None: + identifier = (database_name, table_name) + + test_catalog.create_namespace_if_not_exists(database_name) + + table = test_catalog.create_table( + identifier=identifier, + schema=Schema(), + ) + + assert test_catalog.table_exists(identifier) + # Assert that registering the table again raises TableAlreadyExistsError + with pytest.raises(TableAlreadyExistsError): + test_catalog.register_table(identifier, metadata_location=table.metadata_location) diff --git a/tests/integration/test_register_table.py b/tests/integration/test_register_table.py deleted file mode 100644 index c0db2014af..0000000000 --- a/tests/integration/test_register_table.py +++ /dev/null @@ -1,88 +0,0 @@ -# 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. -import pytest - -from pyiceberg.catalog import Catalog -from pyiceberg.exceptions import NoSuchTableError, TableAlreadyExistsError -from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec -from pyiceberg.schema import Schema -from pyiceberg.table import Table -from pyiceberg.types import ( - BooleanType, - DateType, - IntegerType, - NestedField, - StringType, -) - -TABLE_SCHEMA = Schema( - NestedField(field_id=1, name="foo", field_type=BooleanType(), required=False), - NestedField(field_id=2, name="bar", field_type=StringType(), required=False), - NestedField(field_id=4, name="baz", field_type=IntegerType(), required=False), - NestedField(field_id=10, name="qux", field_type=DateType(), required=False), -) - - -def _create_table( - session_catalog: Catalog, - identifier: str, - format_version: int, - location: str, - partition_spec: PartitionSpec = UNPARTITIONED_PARTITION_SPEC, - schema: Schema = TABLE_SCHEMA, -) -> Table: - try: - session_catalog.drop_table(identifier=identifier) - except NoSuchTableError: - pass - - return session_catalog.create_table( - identifier=identifier, - schema=schema, - location=location, - properties={"format-version": str(format_version)}, - partition_spec=partition_spec, - ) - - -@pytest.mark.integration -@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")]) -def test_register_table( - catalog: Catalog, -) -> None: - identifier = "default.register_table" - location = "s3a://warehouse/default/register_table" - tbl = _create_table(catalog, identifier, 2, location) - assert catalog.table_exists(identifier=identifier) - catalog.drop_table(identifier=identifier) - assert not catalog.table_exists(identifier=identifier) - catalog.register_table(("default", "register_table"), metadata_location=tbl.metadata_location) - assert catalog.table_exists(identifier=identifier) - - -@pytest.mark.integration -@pytest.mark.parametrize("catalog", [pytest.lazy_fixture("session_catalog_hive"), pytest.lazy_fixture("session_catalog")]) -def test_register_table_existing( - catalog: Catalog, -) -> None: - identifier = "default.register_table_existing" - location = "s3a://warehouse/default/register_table_existing" - tbl = _create_table(catalog, identifier, 2, location) - assert catalog.table_exists(identifier=identifier) - # Assert that registering the table again raises TableAlreadyExistsError - with pytest.raises(TableAlreadyExistsError): - catalog.register_table(("default", "register_table_existing"), metadata_location=tbl.metadata_location) From d519c40b6fb993f2735b0cd3fd46d5f2ac11cceb Mon Sep 17 00:00:00 2001 From: Gabriel Igliozzi Date: Thu, 9 Oct 2025 16:01:21 -0400 Subject: [PATCH 2/3] lint --- tests/integration/test_catalog.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index 34b0a830f3..eb8ecbd3b7 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -359,11 +359,7 @@ def test_update_namespace_properties(test_catalog: Catalog, database_name: str) @pytest.mark.integration @pytest.mark.parametrize("test_catalog", CATALOGS) -def test_register_table( - test_catalog: Catalog, - table_name: str, - database_name: str -) -> None: +def test_register_table(test_catalog: Catalog, table_name: str, database_name: str) -> None: identifier = (database_name, table_name) test_catalog.create_namespace_if_not_exists(database_name) @@ -382,11 +378,7 @@ def test_register_table( @pytest.mark.integration @pytest.mark.parametrize("test_catalog", CATALOGS) -def test_register_table_existing( - test_catalog: Catalog, - table_name: str, - database_name: str -) -> None: +def test_register_table_existing(test_catalog: Catalog, table_name: str, database_name: str) -> None: identifier = (database_name, table_name) test_catalog.create_namespace_if_not_exists(database_name) From 14d45c0c68221b8f6a1e3b9b1fa84ca72b5f2dd4 Mon Sep 17 00:00:00 2001 From: Gabriel Igliozzi Date: Thu, 9 Oct 2025 20:51:00 -0400 Subject: [PATCH 3/3] add schema to test --- tests/integration/test_catalog.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_catalog.py b/tests/integration/test_catalog.py index eb8ecbd3b7..db16c38b38 100644 --- a/tests/integration/test_catalog.py +++ b/tests/integration/test_catalog.py @@ -359,14 +359,14 @@ def test_update_namespace_properties(test_catalog: Catalog, database_name: str) @pytest.mark.integration @pytest.mark.parametrize("test_catalog", CATALOGS) -def test_register_table(test_catalog: Catalog, table_name: str, database_name: str) -> None: +def test_register_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None: identifier = (database_name, table_name) test_catalog.create_namespace_if_not_exists(database_name) table = test_catalog.create_table( identifier=identifier, - schema=Schema(), + schema=table_schema_nested, ) assert test_catalog.table_exists(identifier) @@ -378,14 +378,14 @@ def test_register_table(test_catalog: Catalog, table_name: str, database_name: s @pytest.mark.integration @pytest.mark.parametrize("test_catalog", CATALOGS) -def test_register_table_existing(test_catalog: Catalog, table_name: str, database_name: str) -> None: +def test_register_table_existing(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None: identifier = (database_name, table_name) test_catalog.create_namespace_if_not_exists(database_name) table = test_catalog.create_table( identifier=identifier, - schema=Schema(), + schema=table_schema_nested, ) assert test_catalog.table_exists(identifier)