Updating styles on demand instead of on_idle (#2304)

* Updating styles on demand instead of on_idle

* Tidy up update_styles

* Fix LRU cache tests

* Remove some debugging code

* Adding test for pseudoclass style update

* Update changelog
This commit is contained in:
darrenburns
2023-04-18 11:36:00 +01:00
committed by GitHub
parent 01d67173e8
commit 496f8b4524
8 changed files with 35 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
from textual.app import App
from textual.app import App, ComposeResult
from textual.widgets import Button
def test_batch_update():
@@ -15,3 +16,23 @@ def test_batch_update():
assert app._batch_count == 1 # Exiting decrements
assert app._batch_count == 0 # Back to zero
class MyApp(App):
def compose(self) -> ComposeResult:
yield Button("Click me!")
async def test_hover_update_styles():
app = MyApp()
async with app.run_test() as pilot:
button = app.query_one(Button)
assert button.pseudo_classes == {"enabled"}
# Take note of the initial background colour
initial_background = button.styles.background
await pilot.hover(Button)
# We've hovered, so ensure the pseudoclass is present and background changed
assert button.pseudo_classes == {"enabled", "hover"}
assert button.styles.background != initial_background

View File

@@ -8,7 +8,7 @@ from textual._cache import FIFOCache, LRUCache
def test_lru_cache():
cache = LRUCache(3)
assert str(cache) == "<LRUCache maxsize=3 hits=0 misses=0>"
assert str(cache) == "<LRUCache size=0 maxsize=3 hits=0 misses=0>"
# insert some values
cache["foo"] = 1
@@ -65,7 +65,7 @@ def test_lru_cache_hits():
assert cache.hits == 3
assert cache.misses == 2
assert str(cache) == "<LRUCache maxsize=4 hits=3 misses=2>"
assert str(cache) == "<LRUCache size=1 maxsize=4 hits=3 misses=2>"
def test_lru_cache_get():