mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Move the assert on key records into all_recorded
While what I had worked, asserting on a boolean return from that method ended up masking what had gone wrong. This way we get to see the fail and *why* it failed.
This commit is contained in:
@@ -188,16 +188,13 @@ class AppKeyRecorder(App[None]):
|
|||||||
"""
|
"""
|
||||||
self.pressed_keys.append(key)
|
self.pressed_keys.append(key)
|
||||||
|
|
||||||
def all_recorded(self, prefix: str="") -> bool:
|
def all_recorded(self, prefix: str="") -> None:
|
||||||
"""Were all the bindings recorded from the presses?
|
"""Were all the bindings recorded from the presses?
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prefix (str, optional): An optional prefix.
|
prefix (str, optional): An optional prefix.
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: ``True`` if all the bindings were recorded, ``False``if not.
|
|
||||||
"""
|
"""
|
||||||
return self.pressed_keys == [f"{prefix}{key}" for key in self.ALL_KEYS]
|
assert self.pressed_keys == [f"{prefix}{key}" for key in self.ALL_KEYS]
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@@ -229,7 +226,7 @@ async def test_pressing_movement_keys_app() -> None:
|
|||||||
async with AppWithMovementKeysBound().run_test() as pilot:
|
async with AppWithMovementKeysBound().run_test() as pilot:
|
||||||
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
||||||
await pilot.pause(2/100)
|
await pilot.pause(2/100)
|
||||||
assert pilot.app.all_recorded()
|
pilot.app.all_recorded()
|
||||||
|
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
@@ -265,7 +262,7 @@ async def test_focused_child_widget_with_movement_bindings() -> None:
|
|||||||
async with AppWithWidgetWithBindings().run_test() as pilot:
|
async with AppWithWidgetWithBindings().run_test() as pilot:
|
||||||
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
||||||
await pilot.pause(2/100)
|
await pilot.pause(2/100)
|
||||||
assert pilot.app.all_recorded("locally_")
|
pilot.app.all_recorded("locally_")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# A focused widget within a screen that handles bindings.
|
# A focused widget within a screen that handles bindings.
|
||||||
@@ -346,7 +343,7 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
|
|||||||
async with AppWithWidgetWithBindingsNoInherit().run_test() as pilot:
|
async with AppWithWidgetWithBindingsNoInherit().run_test() as pilot:
|
||||||
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
||||||
await pilot.pause(2/100)
|
await pilot.pause(2/100)
|
||||||
assert pilot.app.all_recorded("locally_")
|
pilot.app.all_recorded("locally_")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# A focused widget with no bindings and no inheriting of bindings, on screen.
|
# A focused widget with no bindings and no inheriting of bindings, on screen.
|
||||||
@@ -391,7 +388,7 @@ async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen(
|
|||||||
async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot:
|
async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot:
|
||||||
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
||||||
await pilot.pause(2/100)
|
await pilot.pause(2/100)
|
||||||
assert pilot.app.all_recorded("screenly_")
|
pilot.app.all_recorded("screenly_")
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# A focused widget with zero bindings declared, but no inheriting of
|
# A focused widget with zero bindings declared, but no inheriting of
|
||||||
@@ -438,4 +435,4 @@ async def test_focused_child_widget_no_inherit_empty_bindings_with_movement_bind
|
|||||||
async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot:
|
async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot:
|
||||||
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
await pilot.press(*AppKeyRecorder.ALL_KEYS)
|
||||||
await pilot.pause(2/100)
|
await pilot.pause(2/100)
|
||||||
assert pilot.app.all_recorded("screenly_")
|
pilot.app.all_recorded("screenly_")
|
||||||
|
|||||||
Reference in New Issue
Block a user