|
28 | 28 | from pyiceberg.catalog import (
|
29 | 29 | Catalog,
|
30 | 30 | )
|
31 |
| -from pyiceberg.catalog.sql import SqlCatalog |
| 31 | +from pyiceberg.catalog.sql import DEFAULT_ECHO_VALUE, DEFAULT_POOL_PRE_PING_VALUE, SqlCatalog |
32 | 32 | from pyiceberg.exceptions import (
|
33 | 33 | CommitFailedException,
|
34 | 34 | NamespaceAlreadyExistsError,
|
|
52 | 52 | )
|
53 | 53 | from pyiceberg.transforms import IdentityTransform
|
54 | 54 | from pyiceberg.typedef import Identifier
|
55 |
| -from pyiceberg.types import IntegerType |
| 55 | +from pyiceberg.types import IntegerType, strtobool |
56 | 56 |
|
57 | 57 |
|
58 | 58 | @pytest.fixture(scope="module")
|
@@ -168,6 +168,49 @@ def test_creation_with_unsupported_uri(catalog_name: str) -> None:
|
168 | 168 | SqlCatalog(catalog_name, uri="unsupported:xxx")
|
169 | 169 |
|
170 | 170 |
|
| 171 | +def test_creation_with_echo_parameter(catalog_name: str, warehouse: Path) -> None: |
| 172 | + # echo_param, expected_echo_value |
| 173 | + test_cases = [(None, strtobool(DEFAULT_ECHO_VALUE)), ("debug", "debug"), ("true", True), ("false", False)] |
| 174 | + |
| 175 | + for echo_param, expected_echo_value in test_cases: |
| 176 | + props = { |
| 177 | + "uri": f"sqlite:////{warehouse}/sql-catalog.db", |
| 178 | + "warehouse": f"file://{warehouse}", |
| 179 | + } |
| 180 | + # None is for default value |
| 181 | + if echo_param is not None: |
| 182 | + props["echo"] = echo_param |
| 183 | + catalog = SqlCatalog(catalog_name, **props) |
| 184 | + assert catalog.engine._echo == expected_echo_value, ( |
| 185 | + f"Assertion failed: expected echo value {expected_echo_value}, " |
| 186 | + f"but got {catalog.engine._echo}. For echo_param={echo_param}" |
| 187 | + ) |
| 188 | + |
| 189 | + |
| 190 | +def test_creation_with_pool_pre_ping_parameter(catalog_name: str, warehouse: Path) -> None: |
| 191 | + # pool_pre_ping_param, expected_pool_pre_ping_value |
| 192 | + test_cases = [ |
| 193 | + (None, strtobool(DEFAULT_POOL_PRE_PING_VALUE)), |
| 194 | + ("true", True), |
| 195 | + ("false", False), |
| 196 | + ] |
| 197 | + |
| 198 | + for pool_pre_ping_param, expected_pool_pre_ping_value in test_cases: |
| 199 | + props = { |
| 200 | + "uri": f"sqlite:////{warehouse}/sql-catalog.db", |
| 201 | + "warehouse": f"file://{warehouse}", |
| 202 | + } |
| 203 | + # None is for default value |
| 204 | + if pool_pre_ping_param is not None: |
| 205 | + props["pool_pre_ping"] = pool_pre_ping_param |
| 206 | + |
| 207 | + catalog = SqlCatalog(catalog_name, **props) |
| 208 | + assert catalog.engine.pool._pre_ping == expected_pool_pre_ping_value, ( |
| 209 | + f"Assertion failed: expected pool_pre_ping value {expected_pool_pre_ping_value}, " |
| 210 | + f"but got {catalog.engine.pool._pre_ping}. For pool_pre_ping_param={pool_pre_ping_param}" |
| 211 | + ) |
| 212 | + |
| 213 | + |
171 | 214 | @pytest.mark.parametrize(
|
172 | 215 | "catalog",
|
173 | 216 | [
|
|
0 commit comments