mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #2656 from davep/private-validate-and-compute
Add (currently xfailing) tests for private reactive validation and compute methods
This commit is contained in:
@@ -413,3 +413,51 @@ async def test_public_and_private_watch() -> None:
|
|||||||
pilot.app.counter += 1
|
pilot.app.counter += 1
|
||||||
assert calls["private"] is True
|
assert calls["private"] is True
|
||||||
assert calls["public"] is True
|
assert calls["public"] is True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="https://github.com/Textualize/textual/issues/2539")
|
||||||
|
async def test_public_and_private_validate() -> None:
|
||||||
|
"""If a reactive/var has public and private validate both should get called."""
|
||||||
|
|
||||||
|
calls: dict[str, bool] = {"private": False, "public": False}
|
||||||
|
|
||||||
|
class PrivateValidateTest(App):
|
||||||
|
counter = var(0, init=False)
|
||||||
|
|
||||||
|
def validate_counter(self, _: int) -> None:
|
||||||
|
calls["public"] = True
|
||||||
|
|
||||||
|
def _validate_counter(self, _: int) -> None:
|
||||||
|
calls["private"] = True
|
||||||
|
|
||||||
|
async with PrivateValidateTest().run_test() as pilot:
|
||||||
|
assert calls["private"] is False
|
||||||
|
assert calls["public"] is False
|
||||||
|
pilot.app.counter += 1
|
||||||
|
assert calls["private"] is True
|
||||||
|
assert calls["public"] is True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason="https://github.com/Textualize/textual/issues/2539")
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user