Skip to content

Commit b254221

Browse files
committed
fix(duckshop): list unit-test mock columns in declared order and plan unit tests in CI
1 parent 974e719 commit b254221

6 files changed

Lines changed: 62 additions & 13 deletions

File tree

‎benchmarks/duckshop/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ earlier ones:
162162
same results on every run: added SKUs are sorted, the weekday average utilisation is an exact
163163
decimal sum over a count, the busiest slot of equally busy ones is the earliest, and the top
164164
exception code of equally frequent ones is the first in alphabetical order.
165+
- The mocks of `stg_wishlist_items`, `stg_purchase_order_lines` and `int_loyalty_tier_changes` in
166+
three unit tests list their columns in the models' declared order, which unit-test planning
167+
requires for a `SELECT *` reader. Only compiled tests change; compiled models are the same, so
168+
model benchmarks stay comparable.
165169

166170
## Status
167171

‎benchmarks/duckshop/project/tests/unit/intermediate/customers/test_int_wishlist_demand__counts_purchases_made_after_wishlisting.sql‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ TEST (name "int_wishlist_demand__counts_purchases_made_after_wishlisting");
22

33
WITH __ref__stg_wishlist_items AS (
44
SELECT
5+
'W1#1' AS wishlist_item_key,
56
'W1' AS wishlist_id,
67
'C1' AS customer_id,
7-
'W1#1' AS wishlist_item_key,
88
'DUCK-1' AS sku,
99
'2026-03-01 00:00:00 +00:00'::TIMESTAMPTZ AS added_at,
1010
NULL AS item_position
1111
UNION ALL
1212
SELECT
13+
'W2#1',
1314
'W2',
1415
'C1',
15-
'W2#1',
1616
'DUCK-1',
1717
'2026-03-02 00:00:00 +00:00'::TIMESTAMPTZ,
1818
NULL
1919
UNION ALL
2020
SELECT
21+
'W3#1',
2122
'W3',
2223
'C2',
23-
'W3#1',
2424
'DUCK-1',
2525
'2026-03-05 00:00:00 +00:00'::TIMESTAMPTZ,
2626
NULL

‎benchmarks/duckshop/project/tests/unit/intermediate/inventory/test_int_purchase_order_lines_received__measures_fill_and_lateness_in_warehouse_time.sql‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ WITH __ref__stg_po_receipts AS (
3232

3333
__ref__stg_purchase_order_lines AS (
3434
SELECT
35-
'PO1' AS po_id,
36-
NULL AS currency_code,
3735
'PO1#1' AS po_line_key,
36+
'PO1' AS po_id,
3837
'DUCK-1' AS sku,
3938
10 AS ordered_qty,
40-
NULL AS unit_cost_minor
39+
NULL AS unit_cost_minor,
40+
NULL AS currency_code
4141
UNION ALL
4242
SELECT
43-
'PO1',
44-
NULL,
4543
'PO1#2',
44+
'PO1',
4645
'DUCK-2',
4746
5,
47+
NULL,
4848
NULL
4949
),
5050

‎benchmarks/duckshop/project/tests/unit/marts/core/test_dim_customers__combines_profile_value_consent_and_loyalty.sql‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,23 @@ __ref__int_customer_consent_state AS (
115115

116116
__ref__int_loyalty_tier_changes AS (
117117
SELECT
118+
'LA1:1' AS tier_change_key,
118119
NULL AS loyalty_account_id,
119120
'C1' AS customer_id,
121+
1 AS change_sequence,
120122
'DUCKLING' AS tier_code,
121123
NULL AS previous_tier_code,
122-
'LA1:1' AS tier_change_key,
123-
1 AS change_sequence,
124124
NULL AS changed_at,
125125
NULL AS direction,
126126
NULL AS days_in_previous_tier
127127
UNION ALL
128128
SELECT
129+
'LA1:2',
129130
NULL,
130131
'C1',
132+
2,
131133
'GOLDEN_DUCK',
132134
NULL,
133-
'LA1:2',
134-
2,
135135
NULL,
136136
NULL,
137137
NULL

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/_test_types.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,16 @@ class BenchmarkProjectCompileTestCase:
12551255
expected_warnings: int
12561256

12571257

1258+
@dataclass(frozen=True)
1259+
class BenchmarkProjectTestPlanTestCase:
1260+
"""A benchmark project whose unit tests must plan without a warehouse connection."""
1261+
1262+
description: str
1263+
project_dir: Path
1264+
expected_final_line_prefix: str
1265+
expected_final_line_suffix: str
1266+
1267+
12581268
@dataclass(frozen=True)
12591269
class BenchmarkCoreCopyCompileTestCase:
12601270
"""A script that copies a benchmark project without an area, and the copy's compiled output.

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/test_duckshop_benchmark_compile.py‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from tests.e2e.src.sqlbuild.cli.commands.main.compile._test_types import (
1515
BenchmarkCoreCopyCompileTestCase,
1616
BenchmarkProjectCompileTestCase,
17+
BenchmarkProjectTestPlanTestCase,
1718
)
1819
from tests.e2e.src.sqlbuild.cli.commands.shared.helpers import REPO_ROOT, run_sqb
1920

@@ -63,6 +64,40 @@ def test_given_benchmark_project_when_compiling_then_reports_no_errors_or_warnin
6364
assert summary["tests"] > 0
6465

6566

67+
@pytest.mark.parametrize(
68+
"test_case",
69+
[
70+
BenchmarkProjectTestPlanTestCase(
71+
description="duckshop",
72+
project_dir=REPO_ROOT / "benchmarks" / "duckshop" / "project",
73+
expected_final_line_prefix="Test plan inspection complete: ",
74+
expected_final_line_suffix=" selected, 0 errors.",
75+
)
76+
],
77+
ids=lambda case: case.description,
78+
)
79+
def test_given_benchmark_project_when_inspecting_test_plan_then_every_unit_test_plans(
80+
test_case: BenchmarkProjectTestPlanTestCase, tmp_path: Path
81+
) -> None:
82+
"""Mock fixtures are checked against declared columns only when tests are planned."""
83+
project_dir: Path = tmp_path / test_case.description
84+
shutil.copytree(
85+
test_case.project_dir,
86+
project_dir,
87+
ignore=shutil.ignore_patterns(*_LOCAL_ONLY_PATHS),
88+
)
89+
90+
result: subprocess.CompletedProcess[str] = run_sqb(
91+
command=("--no-color", "test", "--inspect"),
92+
project_dir=project_dir,
93+
)
94+
95+
assert result.returncode == 0, result.stdout + result.stderr
96+
final_line: str = result.stdout.strip().splitlines()[-1]
97+
assert final_line.startswith(test_case.expected_final_line_prefix), result.stdout
98+
assert final_line.endswith(test_case.expected_final_line_suffix), result.stdout
99+
100+
66101
@pytest.mark.parametrize(
67102
"test_case",
68103
[
@@ -73,7 +108,7 @@ def test_given_benchmark_project_when_compiling_then_reports_no_errors_or_warnin
73108
expected_errors=0,
74109
expected_warnings=0,
75110
expected_compiled_checksum=(
76-
"1ff1d0955ea3839b3c969707fd47ca9a4d7d7216753759d23911836f6ea5879d"
111+
"7661e2ad98b33b8230c9df9c6c780e959cb7e18398b14a2cef36e12d19bd0bb6"
77112
),
78113
)
79114
],

0 commit comments

Comments
 (0)