Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (currently xfailing) tests for private reactive validation and compute methods #2656

Merged
merged 3 commits into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions tests/test_reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,51 @@ def _watch_counter(self) -> None:
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_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