You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was thinking of writing some tests for persistent_cache and realized utilizing the native pytest ability might be a good way to go about it, such that the tests could leverage pytest's tmp_path.
This is what I came up with
tests/_save/test_persistent_cache.py
from __future__ importannotations# Run as direct script for access to fixtures.from_pytest.tmpdirimporttmp_pathastmp_path_fixtureimportmarimoapp=marimo.App()
@app.celldeffixtures():
tmp_path_fixture=None@app.celldefsetup():
importmarimoasmoimportospc=mo.persistent_cache@app.celldeftest_general_loader(os, pc, tmp_path_fixture):
print(tmp_path_fixture)
assertnotos.path.exists(tmp_path_fixture/"basic")
withpc("basic", save_path=tmp_path_fixture) ascache:
_b=1assert_b==1assertnotcache._cache.hitassertos.path.exists(tmp_path_fixture/"basic"/f"C_{cache._cache.hash}.pickle")
@app.celldeftest_general_loader_hit(os, pc, tmp_path_fixture, cache):
print(tmp_path_fixture)
withpc("basic", save_path=tmp_path_fixture) ascache_2:
_b=1assert_b==1assertcache_2._cache.hitassertcache._cache.hash==cache_2._cache.hashassertos.path.exists(tmp_path_fixture/"basic"/f"C_{cache._cache.hash}.pickle")
@app.celldeftest_json_loader(os, pc, tmp_path_fixture):
print(tmp_path_fixture)
assertnotos.path.exists(tmp_path_fixture/"json")
withpc("json", save_path=tmp_path_fixture, method="json") asjson_cache:
_b=1assert_b==1assertnotjson_cache._cache.hitassertos.path.exists(tmp_path_fixture/"json"/f"C_{json_cache._cache.hash}.json")
@app.celldeftest_json_loader_hit(os, pc, tmp_path_fixture, json_cache):
print(tmp_path_fixture)
withpc("json", save_path=tmp_path_fixture, method="json") asjson_cache_2:
_b=1assert_b==1assertjson_cache_2._cache.hitassertjson_cache._cache.hash==json_cache_2._cache.hashassertos.path.exists(tmp_path_fixture/"json"/f"C_{json_cache._cache.hash}.json")
The fixtures are successfully inserted, but this breaks for 2 reasons:
There is no context
Which is fair and reasonable, it's just cell.run, and might be worth working around in cache (mainly used for UI and state, but using them should be the failure point not cache) (context is definitely needed since graph dependent)
cell.run only injects definitions into the cell where run was called
This was a bit more surprising, but makes sense. So in the script above, test_json_loader_hit fails since the parent test_json_loader runs with tmp_path_fixture = None
It would be nice to have a run_with (maybe run_from?) where if the injected defs provided completely cover the input graph, then those parent nodes are skipped.
edit: Woops hit enter before I was done
The text was updated successfully, but these errors were encountered:
cell.run only injects definitions into the cell where run was called
It would be nice to have a run_with (maybe run_from?) where if the injected defs provided completely cover the input graph, then those parent nodes are skipped.
Oh ... I might consider this a bug. Perhaps we should just update cell.run() to propagate the injected variables to ancestors?
Got you. Wasn't sure if that was the expected behavior. What's the best way to handle the following case?
@app.celldefdep_1(): # Do we skip this cell all together? Has additional defs and a side effecta=1b=a+1print(1)
returna, b@app.celldefdep_2(): # Do we skip this cell all together? Has no other deps, and no side effectsc=3returnc@app.celldefintermediate(b):
d=b*2print(2)
returnd@app.celldefto_run(a, c, d):
e=a+c+dereturneto_run.run(a=7, c=8) # print 1?
Think on it first, and then here's my thoughts hidden to prevent bias
I think this should create an error. Overloaded parameters should cover should cover all defs in their cells. Error in the above case can be as simple as:
Run Exception: Consider defining `b` in a separate cell from `a`, or overloading a value for b
Then with the cell defs defined, that block is skipped. So the above example prints 2, but not 1
I was thinking of writing some tests for
persistent_cache
and realized utilizing the native pytest ability might be a good way to go about it, such that the tests could leverage pytest'stmp_path
.This is what I came up with
tests/_save/test_persistent_cache.py
The fixtures are successfully inserted, but this breaks for 2 reasons:
Which is fair and reasonable, it's just cell.run, and
might be worth working around in cache (mainly used for UI and state, but using them should be the failure point not cache)(context is definitely needed since graph dependent)cell.run
only injects definitions into the cell whererun
was calledThis was a bit more surprising, but makes sense. So in the script above,
test_json_loader_hit
fails since the parenttest_json_loader
runs withtmp_path_fixture
= NoneIt would be nice to have a
run_with
(mayberun_from
?) where if the injected defs provided completely cover the input graph, then those parent nodes are skipped.edit: Woops hit enter before I was done
The text was updated successfully, but these errors were encountered: