Skip to content

Commit ba1a6f4

Browse files
committed
typing
1 parent b6e261e commit ba1a6f4

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

tests/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.

tests/catalog/test_rest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
# pylint: disable=redefined-outer-name,unused-argument
1818
import os
19+
from typing import cast
1920
from unittest import mock
2021
from uuid import UUID
2122

@@ -25,7 +26,6 @@
2526
import pyiceberg
2627
from pyiceberg.catalog import PropertiesUpdateSummary, Table, load_catalog
2728
from pyiceberg.catalog.rest import RestCatalog
28-
from pyiceberg.utils.config import Config
2929
from pyiceberg.exceptions import (
3030
NamespaceAlreadyExistsError,
3131
NoSuchNamespaceError,
@@ -41,12 +41,14 @@
4141
from pyiceberg.table.snapshots import Operation, Snapshot, Summary
4242
from pyiceberg.table.sorting import SortField, SortOrder
4343
from pyiceberg.transforms import IdentityTransform, TruncateTransform
44+
from pyiceberg.typedef import RecursiveDict
4445
from pyiceberg.types import (
4546
BooleanType,
4647
IntegerType,
4748
NestedField,
4849
StringType,
4950
)
51+
from pyiceberg.utils.config import Config
5052

5153
TEST_URI = "https://iceberg-test-catalog/"
5254
TEST_CREDENTIALS = "client:secret"
@@ -953,32 +955,34 @@ def test_request_session_with_ssl_client_cert() -> None:
953955

954956
@mock.patch.dict(os.environ, EXAMPLE_ENV)
955957
@mock.patch("pyiceberg.catalog.Config.get_catalog_config")
956-
def test_catalog_from_environment_variables(catalog_config_mock, rest_mock) -> None:
957-
catalog_config_mock.return_value = Config._from_environment_variables({}).get("catalog").get("production")
958-
catalog = load_catalog("production")
958+
def test_catalog_from_environment_variables(catalog_config_mock: mock.Mock) -> None:
959+
env_config: RecursiveDict = Config._from_environment_variables({})
960+
catalog_config_mock.return_value = cast(RecursiveDict, env_config.get("catalog")).get("production")
961+
catalog = cast(RestCatalog, load_catalog("production"))
959962
assert catalog.uri == TEST_URI
960963

961964

962965
@mock.patch.dict(os.environ, EXAMPLE_ENV)
963966
@mock.patch("pyiceberg.catalog._ENV_CONFIG.get_catalog_config")
964-
def test_catalog_from_environment_variables_override(catalog_config_mock, rest_mock) -> None:
967+
def test_catalog_from_environment_variables_override(catalog_config_mock: mock.Mock, rest_mock: Mocker) -> None:
965968
rest_mock.get(
966969
"https://other-service.io/api/v1/config",
967970
json={"defaults": {}, "overrides": {}},
968971
status_code=200,
969972
)
973+
env_config: RecursiveDict = Config._from_environment_variables({})
970974

971-
catalog_config_mock.return_value = Config._from_environment_variables({}).get("catalog").get("production")
972-
catalog = load_catalog("production", uri="https://other-service.io/api")
975+
catalog_config_mock.return_value = cast(RecursiveDict, env_config.get("catalog")).get("production")
976+
catalog = cast(RestCatalog, load_catalog("production", uri="https://other-service.io/api"))
973977
assert catalog.uri == "https://other-service.io/api"
974978

975979

976-
def test_catalog_from_parameters_empty_env(rest_mock) -> None:
980+
def test_catalog_from_parameters_empty_env(rest_mock: Mocker) -> None:
977981
rest_mock.get(
978-
f"https://other-service.io/api/v1/config",
982+
"https://other-service.io/api/v1/config",
979983
json={"defaults": {}, "overrides": {}},
980984
status_code=200,
981985
)
982986

983-
catalog = load_catalog("production", uri="https://other-service.io/api")
987+
catalog = cast(RestCatalog, load_catalog("production", uri="https://other-service.io/api"))
984988
assert catalog.uri == "https://other-service.io/api"

tests/utils/test_config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import pytest
2121
from strictyaml import as_document
2222

23+
from pyiceberg.typedef import RecursiveDict
2324
from pyiceberg.utils.config import Config, _lowercase_dictionary_keys, merge_config
2425

2526
EXAMPLE_ENV = {"PYICEBERG_CATALOG__PRODUCTION__URI": "https://service.io/api"}
@@ -55,9 +56,9 @@ def test_lowercase_dictionary_keys() -> None:
5556
expected = {"upper": {"nested_upper": {"YES"}}}
5657
assert _lowercase_dictionary_keys(uppercase_keys) == expected # type: ignore
5758

59+
5860
def test_merge_config() -> None:
59-
lhs = {"common_key": "abc123"}
60-
rhs = {"common_key": "xyz789"}
61+
lhs: RecursiveDict = {"common_key": "abc123"}
62+
rhs: RecursiveDict = {"common_key": "xyz789"}
6163
result = merge_config(lhs, rhs)
6264
assert result["common_key"] == rhs["common_key"]
63-

0 commit comments

Comments
 (0)