Skip to content

Commit 10e9d66

Browse files
authored
Feat: allow omitting columns in unit tests (#1714)
* Feat: allow omitting columns in unit tests * Use None instead of np.nan * Ignore mypy
1 parent 6a69f77 commit 10e9d66

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

sqlmesh/core/test/definition.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def setUp(self) -> None:
7777
v = v.real if hasattr(v, "real") else v
7878
columns_to_types[i] = parse_one(type(v).__name__, into=exp.DataType)
7979

80-
columns_to_types = {k: v for k, v in columns_to_types.items() if k in df}
80+
for index, (column, dtype) in enumerate(columns_to_types.items()):
81+
if column not in df:
82+
# Fill in missing columns with NULL values
83+
df.insert(index, column, None) # type: ignore
84+
8185
table = exp.to_table(table_name)
8286

8387
if table.db:

tests/core/test_test.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,42 @@ def test_nan(sushi_context: Context, full_model_without_ctes: SqlModel) -> None:
277277
assert result and result.wasSuccessful()
278278

279279

280+
def test_partial_inputs(sushi_context: Context) -> None:
281+
model = t.cast(
282+
SqlModel,
283+
sushi_context.upsert_model(
284+
load_sql_based_model(
285+
parse(
286+
"""
287+
MODEL (
288+
name sushi.foo,
289+
kind FULL
290+
);
291+
292+
SELECT id, name FROM sushi.waiter_names;
293+
""",
294+
),
295+
),
296+
),
297+
)
298+
299+
body = load_yaml(
300+
"""
301+
test_foo:
302+
model: sushi.foo
303+
inputs:
304+
sushi.waiter_names:
305+
- id: 1
306+
outputs:
307+
query:
308+
- id: 1
309+
name: null
310+
"""
311+
)
312+
result = _create_test(body, "test_foo", model, sushi_context).run()
313+
assert result and result.wasSuccessful()
314+
315+
280316
@pytest.mark.parametrize("full_model_without_ctes", ["snowflake"], indirect=True)
281317
def test_normalization(full_model_without_ctes: SqlModel) -> None:
282318
body = load_yaml(

0 commit comments

Comments
 (0)