From abda34aa13fa6a9678d712dd6573923eead0cafb Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 25 May 2023 11:48:04 +0100 Subject: [PATCH] Add a test for private validation Currently failing. --- tests/test_reactive.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_reactive.py b/tests/test_reactive.py index 1f6b47647..7cfcac90f 100644 --- a/tests/test_reactive.py +++ b/tests/test_reactive.py @@ -413,3 +413,25 @@ async def test_public_and_private_watch() -> None: pilot.app.counter += 1 assert calls["private"] is True assert calls["public"] is True + + +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