From abda34aa13fa6a9678d712dd6573923eead0cafb Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 25 May 2023 11:48:04 +0100 Subject: [PATCH 1/3] 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 1f6b47647b..7cfcac90ff 100644 --- a/tests/test_reactive.py +++ b/tests/test_reactive.py @@ -413,3 +413,25 @@ def _watch_counter(self) -> 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 From bd6717f3d57d85d344dc4ed50e0826cec32633dd Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 25 May 2023 15:23:33 +0100 Subject: [PATCH 2/3] Add a test for public and private computes This fails for now. --- tests/test_reactive.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_reactive.py b/tests/test_reactive.py index 7cfcac90ff..9351ac4e49 100644 --- a/tests/test_reactive.py +++ b/tests/test_reactive.py @@ -435,3 +435,27 @@ def _validate_counter(self, _: int) -> 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 From fa47d0bd41e8c43f63372a23bf3e7c41c45e63f4 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Thu, 25 May 2023 15:27:27 +0100 Subject: [PATCH 3/3] Mark the public/private validate and compute tests as xfails --- tests/test_reactive.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_reactive.py b/tests/test_reactive.py index 9351ac4e49..f0db5dcdf0 100644 --- a/tests/test_reactive.py +++ b/tests/test_reactive.py @@ -415,6 +415,7 @@ def _watch_counter(self) -> None: 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.""" @@ -437,6 +438,7 @@ def _validate_counter(self, _: int) -> None: 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."""