Skip to content

Commit 842295b

Browse files
committed
fix(tests): simplifying tests, reverting some things
Signed-off-by: Cortland Goffena <30168413+cmgoffena13@users.noreply.github.com>
1 parent a784d55 commit 842295b

3 files changed

Lines changed: 40 additions & 29 deletions

File tree

‎sqlmesh/cli/project_init.py‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _gen_example_objects(schema_name: str) -> ExampleObjects:
229229
FROM
230230
{seed_model_name}
231231
WHERE
232-
event_date BETWEEN @start_date AND @end_date
232+
event_date BETWEEN @start_ds AND @end_ds
233233
"""
234234

235235
sql_models[seed_model_name] = f"""MODEL (
@@ -286,25 +286,6 @@ def _gen_example_objects(schema_name: str) -> ExampleObjects:
286286
num_orders: 1
287287
"""
288288

289-
tests["test_incremental_model"] = f"""test_example_incremental_model:
290-
model: {incremental_model_name}
291-
vars:
292-
start: 2020-01-01
293-
end: 2020-01-02
294-
inputs:
295-
{seed_model_name}:
296-
rows:
297-
- id: 1
298-
item_id: 1
299-
event_date: 2020-01-01
300-
outputs:
301-
query:
302-
rows:
303-
- id: 1
304-
item_id: 1
305-
event_date: 2020-01-01
306-
"""
307-
308289
return ExampleObjects(
309290
sql_models=sql_models,
310291
python_models=python_models,

‎tests/cli/test_cli.py‎

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ def create_example_project(temp_dir, template=ProjectTemplate.DEFAULT) -> None:
5959
)
6060

6161

62+
def add_unchanged_incremental_model_test(temp_dir) -> None:
63+
with open(temp_dir / "tests" / "test_incremental_model.yaml", "w", encoding="utf-8") as f:
64+
f.write(
65+
"""
66+
test_example_incremental_model:
67+
model: sqlmesh_example.incremental_model
68+
vars:
69+
start: 2020-01-01
70+
end: 2020-01-02
71+
inputs:
72+
sqlmesh_example.seed_model:
73+
rows:
74+
- id: 1
75+
item_id: 1
76+
event_date: 2020-01-01
77+
outputs:
78+
query:
79+
rows:
80+
- id: 1
81+
item_id: 1
82+
event_date: 2020-01-01
83+
"""
84+
)
85+
86+
6287
def update_incremental_model(temp_dir) -> None:
6388
with open(temp_dir / "models" / "incremental_model.sql", "w", encoding="utf-8") as f:
6489
f.write(
@@ -117,7 +142,7 @@ def init_prod_and_backfill(runner, temp_dir) -> None:
117142

118143

119144
def assert_duckdb_test(result) -> None:
120-
assert "Successfully Ran 2 tests against duckdb" in result.output
145+
assert "Successfully Ran 1 tests against duckdb" in result.output
121146

122147

123148
def assert_new_env(result, new_env="prod", from_env="prod", initialize=True) -> None:
@@ -188,7 +213,7 @@ def test_plan_skip_tests(runner, tmp_path):
188213
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--skip-tests"], input="y\n"
189214
)
190215
assert result.exit_code == 0
191-
assert "Successfully Ran 2 tests against duckdb" not in result.output
216+
assert "Successfully Ran 1 tests against duckdb" not in result.output
192217
assert_new_env(result)
193218
assert_backfill_success(result)
194219

@@ -201,7 +226,7 @@ def test_plan_no_changes_runs_tests_by_default(runner, tmp_path):
201226
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--no-prompts"], input="\n"
202227
)
203228
assert result.exit_code == 0
204-
assert "Successfully Ran 2 tests against duckdb" in result.output
229+
assert "Successfully Ran 1 tests against duckdb" in result.output
205230
assert "No changes to plan" in result.output or "No changes" in result.output
206231

207232

@@ -229,6 +254,7 @@ def test_plan_test_changed_only_with_no_changes(runner, tmp_path):
229254
def test_plan_test_changed_only_runs_only_changed_model_tests(runner, tmp_path):
230255
create_example_project(tmp_path)
231256
init_prod_and_backfill(runner, tmp_path)
257+
add_unchanged_incremental_model_test(tmp_path)
232258

233259
full_model_path = tmp_path / "models" / "full_model.sql"
234260
full_model_path.write_text(
@@ -256,14 +282,18 @@ def test_plan_test_changed_only_runs_only_changed_model_tests(runner, tmp_path):
256282
def test_plan_select_model_test_changed_only_scopes_tests(runner, tmp_path):
257283
create_example_project(tmp_path)
258284
init_prod_and_backfill(runner, tmp_path)
285+
add_unchanged_incremental_model_test(tmp_path)
259286

260287
full_model_path = tmp_path / "models" / "full_model.sql"
261288
full_model_path.write_text(
262289
full_model_path.read_text().replace("COUNT(DISTINCT id)", "COUNT(id)")
263290
)
264291
incremental_model_path = tmp_path / "models" / "incremental_model.sql"
265292
incremental_model_path.write_text(
266-
incremental_model_path.read_text().replace("'a' as new_col,", "'b' as new_col,")
293+
incremental_model_path.read_text().replace(
294+
" item_id,\n event_date,",
295+
" item_id,\n 'b' as new_col,\n event_date,",
296+
)
267297
)
268298

269299
result = runner.invoke(
@@ -355,7 +385,7 @@ def test_plan_skip_backfill(runner, tmp_path, flag):
355385
assert_virtual_layer_updated(result)
356386
assert "Model batches executed" not in result.output
357387
# Dry-run still runs plan-scoped unit tests
358-
assert "Successfully Ran 2 tests against duckdb" in result.output
388+
assert "Successfully Ran 1 tests against duckdb" in result.output
359389

360390

361391
def test_plan_min_intervals(runner, tmp_path):

‎tests/core/test_test.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,13 +2622,13 @@ def test_test_output_with_invalid_model_name(tmp_path: Path) -> None:
26222622
f"""Model '"invalid_model"' was not found at {wrong_test_file}"""
26232623
in mock_logger.call_args[0][0]
26242624
)
2625-
assert "Successfully Ran 2 tests" in output.stdout
2625+
assert "Successfully Ran 1 test" in output.stdout
26262626

26272627

26282628
def test_number_of_tests_found(tmp_path: Path) -> None:
26292629
init_example_project(tmp_path, engine_type="duckdb")
26302630

2631-
# Example project contains 2 tests and we add a new file with 2 tests
2631+
# Example project contains 1 test and we add a new file with 2 tests
26322632
test_file = tmp_path / "tests" / "test_new.yaml"
26332633
test_file.write_text(
26342634
"""
@@ -2674,9 +2674,9 @@ def test_number_of_tests_found(tmp_path: Path) -> None:
26742674

26752675
context = Context(paths=tmp_path)
26762676

2677-
# Case 1: All 4 tests should run without any tests specified
2677+
# Case 1: All 3 tests should run without any tests specified
26782678
results = context.test()
2679-
assert len(results.successes) == 4
2679+
assert len(results.successes) == 3
26802680

26812681
# Case 2: The "new_test.yaml" should amount to 2 subtests
26822682
results = context.test(tests=[f"{test_file}"])

0 commit comments

Comments
 (0)