Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ def load_catalog(name: str | None = None, **properties: str | None) -> Catalog:
catalog_type: CatalogType | None
provided_catalog_type = conf.get(TYPE)

if catalog_impl := properties.get(PY_CATALOG_IMPL):
if catalog_impl := conf.get(PY_CATALOG_IMPL):
if provided_catalog_type:
raise ValueError(
"Must not set both catalog type and py-catalog-impl configurations, "
f"but found type {provided_catalog_type} and py-catalog-impl {catalog_impl}"
)

if catalog := _import_catalog(name, catalog_impl, properties):
if catalog := _import_catalog(name, cast(str, catalog_impl), cast(dict[str, str], conf)):
logger.info("Loaded Catalog: %s", catalog_impl)
return catalog
else:
Expand Down
13 changes: 13 additions & 0 deletions tests/catalog/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pathlib import PosixPath

import pytest
from pytest_mock import MockerFixture

from pyiceberg.catalog import Catalog, load_catalog
from pyiceberg.catalog.memory import InMemoryCatalog
Expand Down Expand Up @@ -54,6 +55,18 @@ def test_load_catalog_impl_does_not_exist() -> None:
assert "Could not initialize Catalog: pyiceberg.does.not.exist.Catalog" in str(exc_info.value)


def test_load_catalog_impl_from_config(mocker: MockerFixture) -> None:
mocker.patch(
"pyiceberg.catalog._ENV_CONFIG.get_catalog_config",
return_value={"py-catalog-impl": "pyiceberg.catalog.memory.InMemoryCatalog", "test.key": "test.value"},
)

catalog = load_catalog("catalog")

assert isinstance(catalog, InMemoryCatalog)
assert catalog.properties["test.key"] == "test.value"


def test_load_catalog_has_type_and_impl() -> None:
with pytest.raises(ValueError) as exc_info:
load_catalog("catalog", **{"py-catalog-impl": "pyiceberg.does.not.exist.Catalog", "type": "sql"})
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
def test_missing_uri(mocker: MockFixture, empty_home_dir_path: str) -> None:
# mock to prevent parsing ~/.pyiceberg.yaml or {PYICEBERG_HOME}/.pyiceberg.yaml
mocker.patch.dict(os.environ, values={"HOME": empty_home_dir_path, "PYICEBERG_HOME": empty_home_dir_path})
mocker.patch("pyiceberg.catalog._ENV_CONFIG", return_value=Config())
mocker.patch("pyiceberg.catalog._ENV_CONFIG", Config())

runner = CliRunner()
result = runner.invoke(run, ["list"])

assert result.exit_code == 1
assert result.output == "Could not initialize catalog with the following properties: {}\n"
assert "URI missing, please provide using --uri" in result.output


def test_hive_catalog_missing_uri_shows_helpful_error(mocker: MockFixture) -> None:
Expand Down
Loading