Skip to content

Commit 68c1316

Browse files
committed
temp
1 parent a049f89 commit 68c1316

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ def _check_required_catalog_properties(name: str, catalog_type: CatalogType, con
226226
)
227227

228228

229-
def load_catalog(name: str | None = None, config: Config | None = None, **properties: str | None) -> Catalog:
229+
def load_catalog(
230+
name: str | None = None, config: Config | dict[str, str | None] | None = None, **properties: str | None
231+
) -> Catalog:
230232
"""Load the catalog based on the properties.
231233
232234
Will look up the properties from the config, based on the name.
@@ -242,6 +244,10 @@ def load_catalog(name: str | None = None, config: Config | None = None, **proper
242244
ValueError: Raises a ValueError in case properties are missing or malformed,
243245
or if it could not determine the catalog based on the properties.
244246
"""
247+
if isinstance(config, dict):
248+
properties = {**config, **properties}
249+
config = None
250+
245251
config = config or get_env_config()
246252
if name is None:
247253
name = config.get_default_catalog_name()

tests/catalog/test_rest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,16 +2036,18 @@ def test_catalog_from_environment_variables(catalog_config_mock: mock.Mock, rest
20362036

20372037

20382038
@mock.patch.dict(os.environ, EXAMPLE_ENV)
2039-
@mock.patch("pyiceberg.catalog._ENV_CONFIG.get_catalog_config")
2040-
def test_catalog_from_environment_variables_override(catalog_config_mock: mock.Mock, rest_mock: Mocker) -> None:
2039+
@mock.patch("pyiceberg.catalog.get_env_config")
2040+
def test_catalog_from_environment_variables_override(get_env_config_mock: mock.Mock, rest_mock: Mocker) -> None:
20412041
rest_mock.get(
20422042
"https://other-service.io/api/v1/config",
20432043
json={"defaults": {}, "overrides": {}},
20442044
status_code=200,
20452045
)
20462046
env_config: RecursiveDict = Config._from_environment_variables({})
20472047

2048-
catalog_config_mock.return_value = cast(RecursiveDict, env_config.get("catalog")).get("production")
2048+
mock_env_config = mock.Mock()
2049+
mock_env_config.get_catalog_config.return_value = cast(RecursiveDict, env_config.get("catalog")).get("production")
2050+
get_env_config_mock.return_value = mock_env_config
20492051
catalog = cast(RestCatalog, load_catalog("production", uri="https://other-service.io/api"))
20502052
assert catalog.uri == "https://other-service.io/api"
20512053

tests/cli/test_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_missing_uri(mocker: MockFixture, empty_home_dir_path: str) -> None:
5050
def test_hive_catalog_missing_uri_shows_helpful_error(mocker: MockFixture) -> None:
5151
mock_env_config = mocker.MagicMock()
5252
mock_env_config.get_catalog_config.return_value = {"type": "hive"}
53-
mocker.patch("pyiceberg.catalog._ENV_CONFIG", mock_env_config)
53+
mocker.patch("pyiceberg.catalog.get_env_config", return_value=mock_env_config)
5454

5555
runner = CliRunner()
5656
result = runner.invoke(run, ["--catalog", "my_hive_catalog", "list"])

tests/conftest.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
TYPE_CHECKING,
4141
Any,
4242
)
43-
from unittest import mock
4443

4544
import boto3
4645
import pytest
@@ -111,20 +110,6 @@ def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
111110
item.add_marker("unmarked")
112111

113112

114-
@pytest.fixture(autouse=True, scope="session")
115-
def _isolate_pyiceberg_config() -> None:
116-
"""Make test runs ignore your local PyIceberg config.
117-
118-
Without this, tests will attempt to resolve a local ~/.pyiceberg.yaml while running pytest.
119-
This replaces the global catalog config once at session start with an env-only config.
120-
"""
121-
import pyiceberg.catalog as _catalog_module
122-
from pyiceberg.utils.config import Config
123-
124-
with mock.patch.object(Config, "_from_configuration_files", return_value=None):
125-
_catalog_module._ENV_CONFIG = Config()
126-
127-
128113
def pytest_addoption(parser: pytest.Parser) -> None:
129114
# S3 options
130115
parser.addoption(

tests/utils/test_config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def test_from_configuration_files(tmp_path_factory: pytest.TempPathFactory) -> N
7171
file.write(yaml_str)
7272

7373
os.environ["PYICEBERG_HOME"] = config_path
74-
assert Config().get_catalog_config("production") == {"uri": "https://service.io/api"}
74+
config = Config()
75+
assert config.get_catalog_config("production") == {"uri": "https://service.io/api"}
7576

7677

7778
def test_lowercase_dictionary_keys() -> None:

0 commit comments

Comments
 (0)