Skip to content
Merged
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
8 changes: 7 additions & 1 deletion tests/differential/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ def run(
:param path: Optional persistent ``--path`` directory. By default
``clickhouse local`` uses an ephemeral temp dir per process.
"""
args = [self.binary, "local", "--query", sql, "--format", fmt]
# Select the output format in SQL rather than with the CLI's generic
# ``--format`` option. Since ClickHouse 26.9, that option also selects
# the INSERT input format, causing inline ``VALUES`` tuples in the seed
# script to be parsed as TSV. The SQL FORMAT clause works on both the
# old 26.5 baseline and current releases.
formatted_sql = f"{sql.rstrip().rstrip(';')} FORMAT {fmt}"
args = [self.binary, "local", "--query", formatted_sql]
if path is not None:
args += ["--path", path]
proc = subprocess.run(
Expand Down
42 changes: 42 additions & 0 deletions tests/test_differential_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Unit tests for the ClickHouse differential-test subprocess wrapper."""

from __future__ import annotations

import subprocess

from tests.differential import conftest as differential_conftest


def test_clickhouse_local_sets_only_the_output_format(monkeypatch):
"""The output format must not override how inline VALUES are parsed."""
calls = []

def fake_run(args, **kwargs):
calls.append((args, kwargs))
return subprocess.CompletedProcess(args, 0, stdout="3\n", stderr="")

monkeypatch.setattr(differential_conftest.subprocess, "run", fake_run)

sql = (
"CREATE TABLE t (x UInt8) ENGINE=Memory; "
"INSERT INTO t VALUES (1), (2); "
"SELECT sum(x) FROM t"
)
runner = differential_conftest.ClickHouseLocal("/tmp/clickhouse")

assert runner.run(sql) == "3\n"
assert calls == [
(
[
"/tmp/clickhouse",
"local",
"--query",
f"{sql} FORMAT TabSeparated",
],
{
"capture_output": True,
"text": True,
"timeout": 60,
},
)
]
Loading