mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
@@ -328,6 +328,33 @@ async def test_reactive_inheritance():
|
||||
assert tertiary.baz == "baz"
|
||||
|
||||
|
||||
async def test_compute():
|
||||
"""Check compute method is called."""
|
||||
|
||||
class ComputeApp(App):
|
||||
count = var(0)
|
||||
count_double = var(0)
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.start = 0
|
||||
super().__init__()
|
||||
|
||||
def compute_count_double(self) -> int:
|
||||
return self.start + self.count * 2
|
||||
|
||||
app = ComputeApp()
|
||||
|
||||
async with app.run_test():
|
||||
assert app.count_double == 0
|
||||
app.count = 1
|
||||
assert app.count_double == 2
|
||||
assert app.count_double == 2
|
||||
app.count = 2
|
||||
assert app.count_double == 4
|
||||
app.start = 10
|
||||
assert app.count_double == 14
|
||||
|
||||
|
||||
async def test_watch_compute():
|
||||
"""Check that watching a computed attribute works."""
|
||||
|
||||
@@ -347,7 +374,9 @@ async def test_watch_compute():
|
||||
|
||||
app = Calculator()
|
||||
|
||||
async with app.run_test() as pilot:
|
||||
# Referencing the value calls compute
|
||||
# Setting any reactive values calls compute
|
||||
async with app.run_test():
|
||||
assert app.show_ac is True
|
||||
app.value = "1"
|
||||
assert app.show_ac is False
|
||||
@@ -356,4 +385,4 @@ async def test_watch_compute():
|
||||
app.numbers = "123"
|
||||
assert app.show_ac is False
|
||||
|
||||
assert watch_called == [True, False, True, False]
|
||||
assert watch_called == [True, True, False, False, True, True, False, False]
|
||||
|
||||
Reference in New Issue
Block a user