Add a test for public and private computes

This fails for now.
This commit is contained in:
Dave Pearson
2023-05-25 15:23:33 +01:00
parent abda34aa13
commit bd6717f3d5

View File

@@ -435,3 +435,27 @@ async def test_public_and_private_validate() -> None:
pilot.app.counter += 1
assert calls["private"] is True
assert calls["public"] is True
async def test_public_and_private_compute() -> None:
"""If a reactive/var has public and private compute both should get called."""
calls: dict[str, bool] = {"private": False, "public": False}
class PrivateComputeTest(App):
counter = var(0, init=False)
def compute_counter(self) -> int:
calls["public"] = True
return 23
def _compute_counter(self) -> int:
calls["private"] = True
return 42
async with PrivateComputeTest().run_test() as pilot:
assert calls["private"] is False
assert calls["public"] is False
_ = pilot.app.counter
assert calls["private"] is True
assert calls["public"] is True