Skip to content

Commit d8a8bd6

Browse files
committed
add tests
1 parent d319746 commit d8a8bd6

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

pyiceberg/catalog/rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ def _create_session(self) -> Session:
231231

232232
# Sets the client side and server side SSL cert verification, if provided as properties.
233233
if ssl_config := self.properties.get(SSL):
234-
if ssl_ca_bundle := ssl_config.get(CA_BUNDLE): # type: ignore
234+
if ssl_ca_bundle := ssl_config.get(CA_BUNDLE):
235235
session.verify = ssl_ca_bundle
236-
if ssl_client := ssl_config.get(CLIENT): # type: ignore
236+
if ssl_client := ssl_config.get(CLIENT):
237237
if all(k in ssl_client for k in (CERT, KEY)):
238238
session.cert = (ssl_client[CERT], ssl_client[KEY])
239239
elif ssl_client_cert := ssl_client.get(CERT):

pyiceberg/typedef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __missing__(self, key: K) -> V:
7373

7474

7575
Identifier = Tuple[str, ...]
76-
Properties = Dict[str, str]
76+
Properties = Dict[str, Any]
7777
RecursiveDict = Dict[str, Union[str, "RecursiveDict"]]
7878

7979
# Represents the literal value

tests/catalog/test_base.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import pyarrow as pa
2828
import pytest
29+
from pydantic_core import ValidationError
2930
from pytest_lazyfixture import lazy_fixture
3031

3132
from pyiceberg.catalog import (
@@ -277,13 +278,16 @@ def catalog() -> InMemoryCatalog:
277278
NAMESPACE_NOT_EMPTY_ERROR = "Namespace is not empty: \\('com', 'organization', 'department'\\)"
278279

279280

280-
def given_catalog_has_a_table(catalog: InMemoryCatalog) -> Table:
281+
def given_catalog_has_a_table(
282+
catalog: InMemoryCatalog,
283+
properties: Properties = EMPTY_DICT,
284+
) -> Table:
281285
return catalog.create_table(
282286
identifier=TEST_TABLE_IDENTIFIER,
283287
schema=TEST_TABLE_SCHEMA,
284288
location=TEST_TABLE_LOCATION,
285289
partition_spec=TEST_TABLE_PARTITION_SPEC,
286-
properties=TEST_TABLE_PROPERTIES,
290+
properties=properties or TEST_TABLE_PROPERTIES,
287291
)
288292

289293

@@ -682,3 +686,17 @@ def test_add_column_with_statement(catalog: InMemoryCatalog) -> None:
682686
def test_catalog_repr(catalog: InMemoryCatalog) -> None:
683687
s = repr(catalog)
684688
assert s == "test.in.memory.catalog (<class 'test_base.InMemoryCatalog'>)"
689+
690+
691+
def test_table_properties_int_value(catalog: InMemoryCatalog) -> None:
692+
# table properties can be set to int, but still serialized to string
693+
property_with_int = {"property_name": 42}
694+
given_table = given_catalog_has_a_table(catalog, properties=property_with_int)
695+
assert isinstance(given_table.properties["property_name"], str)
696+
697+
698+
def test_table_properties_raise_for_none_value(catalog: InMemoryCatalog) -> None:
699+
property_with_none = {"property_name": None}
700+
with pytest.raises(ValidationError) as exc_info:
701+
_ = given_catalog_has_a_table(catalog, properties=property_with_none)
702+
assert "None type is not a supported value in properties" in str(exc_info.value)

tests/catalog/test_sql.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import pyarrow as pa
2323
import pytest
24+
from pydantic_core import ValidationError
2425
from pytest_lazyfixture import lazy_fixture
2526
from sqlalchemy.exc import ArgumentError, IntegrityError
2627

@@ -639,7 +640,7 @@ def test_create_namespace_with_null_properties(catalog: SqlCatalog, database_nam
639640
catalog.create_namespace(namespace=database_name, properties={None: "value"}) # type: ignore
640641

641642
with pytest.raises(IntegrityError):
642-
catalog.create_namespace(namespace=database_name, properties={"key": None}) # type: ignore
643+
catalog.create_namespace(namespace=database_name, properties={"key": None})
643644

644645

645646
@pytest.mark.parametrize(
@@ -851,3 +852,39 @@ def test_concurrent_commit_table(catalog: SqlCatalog, table_schema_simple: Schem
851852
# This one should fail since it already has been updated
852853
with table_b.update_schema() as update:
853854
update.add_column(path="c", field_type=IntegerType())
855+
856+
857+
@pytest.mark.parametrize(
858+
'catalog',
859+
[
860+
lazy_fixture('catalog_memory'),
861+
lazy_fixture('catalog_sqlite'),
862+
lazy_fixture('catalog_sqlite_without_rowcount'),
863+
],
864+
)
865+
def test_table_properties_int_value(catalog: SqlCatalog, table_schema_simple: Schema, random_identifier: Identifier) -> None:
866+
# table properties can be set to int, but still serialized to string
867+
database_name, _table_name = random_identifier
868+
catalog.create_namespace(database_name)
869+
property_with_int = {"property_name": 42}
870+
table = catalog.create_table(random_identifier, table_schema_simple, properties=property_with_int)
871+
assert isinstance(table.properties["property_name"], str)
872+
873+
874+
@pytest.mark.parametrize(
875+
'catalog',
876+
[
877+
lazy_fixture('catalog_memory'),
878+
lazy_fixture('catalog_sqlite'),
879+
lazy_fixture('catalog_sqlite_without_rowcount'),
880+
],
881+
)
882+
def test_table_properties_raise_for_none_value(
883+
catalog: SqlCatalog, table_schema_simple: Schema, random_identifier: Identifier
884+
) -> None:
885+
database_name, _table_name = random_identifier
886+
catalog.create_namespace(database_name)
887+
property_with_none = {"property_name": None}
888+
with pytest.raises(ValidationError) as exc_info:
889+
_ = catalog.create_table(random_identifier, table_schema_simple, properties=property_with_none)
890+
assert "None type is not a supported value in properties" in str(exc_info.value)

0 commit comments

Comments
 (0)