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:
Dave Pearson
2022-12-13 21:56:43 +00:00
parent 5330d2a425
commit 87e18de605

View File

@@ -188,16 +188,13 @@ class AppKeyRecorder(App[None]):
"""
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?
Args:
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:
await pilot.press(*AppKeyRecorder.ALL_KEYS)
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:
await pilot.press(*AppKeyRecorder.ALL_KEYS)
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.
@@ -346,7 +343,7 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
async with AppWithWidgetWithBindingsNoInherit().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALL_KEYS)
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.
@@ -391,7 +388,7 @@ async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen(
async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALL_KEYS)
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
@@ -438,4 +435,4 @@ async def test_focused_child_widget_no_inherit_empty_bindings_with_movement_bind
async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALL_KEYS)
await pilot.pause(2/100)
assert pilot.app.all_recorded("screenly_")
pilot.app.all_recorded("screenly_")