Skip to content

Commit 494d239

Browse files
committed
fix(cratedb): update CMD_OPTS type to list of tuples and add httpx dependency
1 parent 5c1b269 commit 494d239

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ cassandra = []
5454
clickhouse = ["clickhouse-driver"]
5555
cosmosdb = ["azure-cosmos>=4"]
5656
cockroachdb = []
57-
cratedb = ["sqlalchemy-cratedb"]
57+
cratedb = [
58+
"httpx",
59+
"sqlalchemy-cratedb"
60+
]
5861
db2 = [
5962
"sqlalchemy>=2",
6063
"ibm_db_sa; platform_machine != 'aarch64' and platform_machine != 'arm64'",

src/testcontainers/community/cratedb/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CrateDBContainer(SqlContainer):
4848

4949
# Default command-line options. CrateDB needs single-node discovery to run
5050
# as a one-node cluster suitable for testing.
51-
CMD_OPTS: ClassVar[dict[str, str]] = {"discovery.type": "single-node"}
51+
CMD_OPTS: ClassVar[list[tuple[str, str]]] = [("discovery.type", "single-node")]
5252

5353
def __init__(
5454
self,
@@ -57,7 +57,7 @@ def __init__(
5757
username: Optional[str] = None,
5858
password: Optional[str] = None,
5959
dialect: str = "crate",
60-
cmd_opts: Optional[dict[str, str]] = None,
60+
cmd_opts: Optional[list[tuple[str, str]]] = None,
6161
**kwargs,
6262
) -> None:
6363
"""
@@ -73,12 +73,13 @@ def __init__(
7373
merged over (and able to override) the defaults.
7474
"""
7575
raise_for_deprecated_parameter(kwargs, "user", "username")
76-
# Readiness is signalled by CrateDB's HTTP interface returning 200; this
76+
# Readiness is signaled by CrateDB's HTTP interface returning 200; this
7777
# keeps startup free of any database client library.
7878
super().__init__(image, wait_strategy=HttpWaitStrategy(HTTP_PORT).for_status_code(200), **kwargs)
7979

80-
cmd_opts = cmd_opts or {}
81-
self._command = self._build_cmd({**self.CMD_OPTS, **cmd_opts})
80+
cmd_opts = cmd_opts or []
81+
default_cmd_opts = [s for s in self.CMD_OPTS if s[0] not in {k[0] for k in cmd_opts}]
82+
self._command = self._build_cmd([*default_cmd_opts, *cmd_opts])
8283

8384
self.username = username or os.environ.get("CRATEDB_USER", "crate")
8485
self.password = password or os.environ.get("CRATEDB_PASSWORD", "crate")
@@ -88,10 +89,10 @@ def __init__(
8889
self.with_exposed_ports(HTTP_PORT, PSQL_PORT)
8990

9091
@staticmethod
91-
def _build_cmd(opts: dict[str, str]) -> str:
92+
def _build_cmd(opts: list[tuple[str, str]]) -> str:
9293
"""Render a CrateDB ``-C<key>=<value> ...`` command-line string."""
9394
cmd = []
94-
for key, val in opts.items():
95+
for key, val in opts:
9596
if isinstance(val, bool):
9697
val = str(val).lower()
9798
cmd.append(f"-C{key}={val}")

tests/community/cratedb/test_cratedb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ def test_cratedb_connection_url():
3030
"cmd_opts, expected",
3131
[
3232
pytest.param(
33-
{"indices.breaker.total.limit": "90%"},
33+
[("indices.breaker.total.limit", "90%")],
3434
"-Cdiscovery.type=single-node -Cindices.breaker.total.limit=90%",
3535
id="add_cmd_option",
3636
),
3737
pytest.param(
38-
{"discovery.type": "zen", "indices.breaker.total.limit": "90%"},
38+
[("discovery.type", "zen"), ("indices.breaker.total.limit", "90%")],
3939
"-Cdiscovery.type=zen -Cindices.breaker.total.limit=90%",
4040
id="override_defaults",
4141
),

uv.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)