Skip to content

Commit 72c2870

Browse files
committed
maint: catalog implementation roundtripping tests
1 parent 131dd15 commit 72c2870

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

tests/catalog/test_common.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
19+
from pathlib import Path, PosixPath
20+
21+
import pytest
22+
from moto import mock_aws
23+
24+
from pyiceberg.catalog import Catalog
25+
from pyiceberg.io import WAREHOUSE
26+
from tests.conftest import BUCKET_NAME
27+
28+
29+
@pytest.fixture(scope="function")
30+
@mock_aws
31+
def glue(_bucket_initialize: None, moto_endpoint_url: str) -> Catalog:
32+
from pyiceberg.catalog.glue import GlueCatalog
33+
34+
catalog = GlueCatalog(name="glue", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"})
35+
36+
return catalog
37+
38+
39+
@pytest.fixture(scope="function")
40+
@mock_aws
41+
def dynamodb(_bucket_initialize: None, moto_endpoint_url: str) -> Catalog:
42+
from pyiceberg.catalog.dynamodb import DynamoDbCatalog
43+
44+
catalog = DynamoDbCatalog(name="dynamodb", **{"s3.endpoint": moto_endpoint_url, "warehouse": f"s3://{BUCKET_NAME}/"})
45+
46+
return catalog
47+
48+
49+
@pytest.fixture(scope="function")
50+
def memory_catalog(tmp_path: PosixPath) -> Catalog:
51+
from pyiceberg.catalog.memory import InMemoryCatalog
52+
53+
return InMemoryCatalog("test.in_memory.catalog", **{WAREHOUSE: tmp_path.absolute().as_posix(), "test.key": "test.value"})
54+
55+
56+
@pytest.fixture(scope="function")
57+
def sqllite_catalog_memory(warehouse: Path) -> Catalog:
58+
from pyiceberg.catalog.sql import SqlCatalog
59+
60+
catalog = SqlCatalog("sqlitememory", uri="sqlite:///:memory:", warehouse=f"file://{warehouse}")
61+
62+
return catalog
63+
64+
65+
@pytest.fixture(scope="function")
66+
def sqllite_catalog_file(warehouse: Path) -> Catalog:
67+
from pyiceberg.catalog.sql import SqlCatalog
68+
69+
catalog = SqlCatalog("sqlitefile", uri=f"sqlite:////{warehouse}/sql-catalog.db", warehouse=f"file://{warehouse}")
70+
71+
return catalog
72+
73+
74+
@pytest.mark.parametrize(
75+
"catalog",
76+
[
77+
pytest.lazy_fixture("glue"),
78+
pytest.lazy_fixture("dynamodb"),
79+
pytest.lazy_fixture("memory_catalog"),
80+
pytest.lazy_fixture("sqllite_catalog_memory"),
81+
pytest.lazy_fixture("sqllite_catalog_file"),
82+
],
83+
)
84+
def test_create_namespace_no_properties(
85+
catalog: Catalog,
86+
database_name: str,
87+
) -> None:
88+
catalog.create_namespace(namespace=database_name)
89+
loaded_database_list = catalog.list_namespaces()
90+
assert len(loaded_database_list) == 1
91+
assert (database_name,) in loaded_database_list
92+
properties = catalog.load_namespace_properties(database_name)
93+
assert properties == {}
94+
catalog.drop_namespace(database_name)
95+
assert len(catalog.list_namespaces()) == 0

0 commit comments

Comments
 (0)