Skip to content

Commit c4af086

Browse files
committed
change up to integration tests
1 parent 72c2870 commit c4af086

3 files changed

Lines changed: 122 additions & 97 deletions

File tree

pyiceberg/catalog/hive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
LOCATION,
6464
METADATA_LOCATION,
6565
TABLE_TYPE,
66+
URI,
6667
MetastoreCatalog,
6768
PropertiesUpdateSummary,
6869
)
@@ -300,7 +301,7 @@ def __init__(self, name: str, **properties: str):
300301
@staticmethod
301302
def _create_hive_client(properties: Dict[str, str]) -> _HiveClient:
302303
last_exception = None
303-
for uri in properties["uri"].split(","):
304+
for uri in properties[URI].split(","):
304305
try:
305306
return _HiveClient(
306307
uri,
@@ -312,7 +313,7 @@ def _create_hive_client(properties: Dict[str, str]) -> _HiveClient:
312313
if last_exception is not None:
313314
raise last_exception
314315
else:
315-
raise ValueError(f"Unable to connect to hive using uri: {properties['uri']}")
316+
raise ValueError(f"Unable to connect to hive using uri: {properties[URI]}")
316317

317318
def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
318319
properties: Dict[str, str] = table.parameters

tests/catalog/test_common.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

tests/integration/test_catalog.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
from pathlib import Path, PosixPath
19+
from typing import Generator
20+
21+
import pytest
22+
23+
from pyiceberg.catalog import Catalog
24+
from pyiceberg.catalog.dynamodb import DynamoDbCatalog
25+
from pyiceberg.catalog.glue import GLUE_CATALOG_ENDPOINT, GlueCatalog
26+
from pyiceberg.catalog.hive import HiveCatalog
27+
from pyiceberg.catalog.memory import InMemoryCatalog
28+
from pyiceberg.catalog.rest import RestCatalog
29+
from pyiceberg.catalog.sql import SqlCatalog
30+
from pyiceberg.io import WAREHOUSE
31+
from tests.conftest import clean_up, get_bucket_name, get_glue_endpoint, get_s3_path
32+
33+
# The number of tables/databases used in list_table/namespace test
34+
LIST_TEST_NUMBER = 2
35+
36+
37+
@pytest.fixture(scope="function")
38+
def dynamodb() -> Generator[Catalog, None, None]:
39+
test_catalog = DynamoDbCatalog("test_dynamodb_catalog", warehouse=get_s3_path(get_bucket_name()))
40+
yield test_catalog
41+
clean_up(test_catalog)
42+
43+
44+
@pytest.fixture(scope="function")
45+
def glue() -> Generator[Catalog, None, None]:
46+
test_catalog = GlueCatalog(
47+
"test_glue_catalog", **{"warehouse": get_s3_path(get_bucket_name()), GLUE_CATALOG_ENDPOINT: get_glue_endpoint()}
48+
)
49+
yield test_catalog
50+
clean_up(test_catalog)
51+
52+
53+
@pytest.fixture(scope="function")
54+
def memory_catalog(tmp_path: PosixPath) -> Generator[Catalog, None, None]:
55+
test_catalog = InMemoryCatalog(
56+
"test.in_memory.catalog", **{WAREHOUSE: tmp_path.absolute().as_posix(), "test.key": "test.value"}
57+
)
58+
yield test_catalog
59+
60+
clean_up(test_catalog)
61+
62+
63+
@pytest.fixture(scope="function")
64+
def sqlite_catalog_memory(warehouse: Path) -> Generator[Catalog, None, None]:
65+
test_catalog = SqlCatalog("sqlitememory", uri="sqlite:///:memory:", warehouse=f"file://{warehouse}")
66+
67+
yield test_catalog
68+
69+
clean_up(test_catalog)
70+
71+
72+
@pytest.fixture(scope="function")
73+
def sqlite_catalog_file(warehouse: Path) -> Generator[Catalog, None, None]:
74+
test_catalog = SqlCatalog("sqlitefile", uri=f"sqlite:////{warehouse}/sql-catalog.db", warehouse=f"file://{warehouse}")
75+
76+
yield test_catalog
77+
78+
clean_up(test_catalog)
79+
80+
81+
@pytest.fixture(scope="function")
82+
def rest_catalog() -> Generator[Catalog, None, None]:
83+
test_catalog = RestCatalog("rest", uri="http://localhost:8181")
84+
85+
yield test_catalog
86+
87+
clean_up(test_catalog)
88+
89+
90+
@pytest.fixture(scope="function")
91+
def hive_catalog() -> Generator[Catalog, None, None]:
92+
test_catalog = HiveCatalog(
93+
"test_hive_catalog",
94+
uri="thrift://localhost:9083",
95+
)
96+
yield test_catalog
97+
clean_up(test_catalog)
98+
99+
100+
@pytest.mark.integration
101+
@pytest.mark.parametrize(
102+
"test_catalog",
103+
[
104+
pytest.lazy_fixture("glue"),
105+
pytest.lazy_fixture("dynamodb"),
106+
pytest.lazy_fixture("memory_catalog"),
107+
pytest.lazy_fixture("sqlite_catalog_memory"),
108+
pytest.lazy_fixture("sqlite_catalog_file"),
109+
pytest.lazy_fixture("rest_catalog"),
110+
pytest.lazy_fixture("hive_catalog"),
111+
],
112+
)
113+
def test_create_namespace(
114+
test_catalog: Catalog,
115+
database_name: str,
116+
) -> None:
117+
test_catalog.create_namespace(database_name)
118+
# note the use of `in` because some catalogs have a "default" namespace
119+
assert (database_name,) in test_catalog.list_namespaces()

0 commit comments

Comments
 (0)