Skip to content

Commit e6be3a7

Browse files
simplify test
1 parent ddf7ebe commit e6be3a7

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

tests/test_cache/test_basic_cache_invalidation.py

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,22 @@ def test_change_task_version_blob(mocker):
280280
child_spy.assert_called_once()
281281

282282

283-
def test_change_lazy_query(mocker):
283+
@pytest.mark.parametrize(
284+
"get_tbl_obj",
285+
[
286+
lambda query_value: select_as(query_value, "x"),
287+
(lambda query_value: pl.DataFrame({"x": [query_value]})) if pl else None,
288+
],
289+
ids=["sql", "polars"],
290+
)
291+
def test_change_lazy_query(mocker, get_tbl_obj):
292+
if get_tbl_obj is None:
293+
pytest.skip("Polars is not installed, skipping Polars test.")
284294
query_value = 1
285295

286296
@materialize(lazy=True, nout=2)
287297
def lazy_task():
288-
return 0, Table(select_as(query_value, "x"), name="lazy_table")
298+
return 0, Table(get_tbl_obj(query_value), name="lazy_table")
289299

290300
@materialize(input_type=pd.DataFrame, version="1.0")
291301
def get_first(table, col):
@@ -1045,35 +1055,3 @@ def get_flow():
10451055
# from a lazy task, hence res_constant should be cache valid and the task
10461056
# producing res_select should not be called.
10471057
constant_spy.assert_not_called()
1048-
1049-
1050-
@pytest.mark.polars
1051-
def test_lazy_polars_dataframe(mocker):
1052-
value = -1
1053-
1054-
@materialize(lazy=True)
1055-
def polars_task():
1056-
return Table(pl.DataFrame({"x": [value]}), name="polars_table")
1057-
1058-
with Flow() as flow:
1059-
with Stage("stage_1"):
1060-
polars_table = polars_task()
1061-
res_val = m.take_first(polars_table, as_int=True)
1062-
1063-
# Initial Call for cache invalidation
1064-
with StageLockContext():
1065-
res = flow.run()
1066-
assert res.get(res_val) == -1
1067-
1068-
# Change the value and run the flow again
1069-
value = 0
1070-
take_first_spy = spy_task(mocker, res_val)
1071-
with StageLockContext():
1072-
res = flow.run()
1073-
assert res.get(res_val) == 0
1074-
1075-
with StageLockContext():
1076-
res = flow.run()
1077-
assert res.get(res_val) == 0
1078-
1079-
take_first_spy.assert_called_once()

0 commit comments

Comments
 (0)