remove some pauses

This commit is contained in:
Will McGugan
2023-01-26 16:10:13 +01:00
parent 41be84b1a5
commit 3eac79568c
7 changed files with 13 additions and 23 deletions

View File

@@ -34,14 +34,17 @@ class Pilot(Generic[ReturnType]):
if keys: if keys:
await self._app._press_keys(keys) await self._app._press_keys(keys)
async def pause(self, delay: float = 50 / 1000) -> None: async def pause(self, delay: float | None = None) -> None:
"""Insert a pause. """Insert a pause.
Args: Args:
delay: Seconds to pause. Defaults to 50ms. delay: Seconds to pause, or None to wait for cpu idle. Defaults to None.
""" """
# These sleep zeros, are to force asyncio to give up a time-slice, # These sleep zeros, are to force asyncio to give up a time-slice,
await asyncio.sleep(delay) if delay is None:
await wait_for_idle(0)
else:
await asyncio.sleep(delay)
async def wait_for_animation(self) -> None: async def wait_for_animation(self) -> None:
"""Wait for any animation to complete.""" """Wait for any animation to complete."""

View File

@@ -31,10 +31,8 @@ async def test_empty_inherited_list_view() -> None:
"""An empty self-populating inherited ListView should work as expected.""" """An empty self-populating inherited ListView should work as expected."""
async with ListViewApp().run_test() as pilot: async with ListViewApp().run_test() as pilot:
await pilot.press("tab") await pilot.press("tab")
await pilot.pause(2 / 100)
assert pilot.app.query_one(MyListView).index is None assert pilot.app.query_one(MyListView).index is None
await pilot.press("down") await pilot.press("down")
await pilot.pause(2 / 100)
assert pilot.app.query_one(MyListView).index is None assert pilot.app.query_one(MyListView).index is None
@@ -42,8 +40,6 @@ async def test_populated_inherited_list_view() -> None:
"""A self-populating inherited ListView should work as normal.""" """A self-populating inherited ListView should work as normal."""
async with ListViewApp(30).run_test() as pilot: async with ListViewApp(30).run_test() as pilot:
await pilot.press("tab") await pilot.press("tab")
await pilot.pause(2 / 100)
assert pilot.app.query_one(MyListView).index == 0 assert pilot.app.query_one(MyListView).index == 0
await pilot.press("down") await pilot.press("down")
await pilot.pause(2 / 100)
assert pilot.app.query_one(MyListView).index == 1 assert pilot.app.query_one(MyListView).index == 1

View File

@@ -14,7 +14,6 @@ def test_auto_pilot() -> None:
async def auto_pilot(pilot: Pilot) -> None: async def auto_pilot(pilot: Pilot) -> None:
await pilot.press("tab", *"foo") await pilot.press("tab", *"foo")
await pilot.pause(1 / 100)
await pilot.exit("bar") await pilot.exit("bar")
app = TestApp() app = TestApp()

View File

@@ -238,7 +238,7 @@ async def test_pressing_alpha_on_app() -> None:
"""Test that pressing the alpha key, when it's bound on the app, results in an action fire.""" """Test that pressing the alpha key, when it's bound on the app, results in an action fire."""
async with AppWithMovementKeysBound().run_test() as pilot: async with AppWithMovementKeysBound().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALPHAS) await pilot.press(*AppKeyRecorder.ALPHAS)
await pilot.pause(2 / 100) await pilot.pause()
assert pilot.app.pressed_keys == [*AppKeyRecorder.ALPHAS] assert pilot.app.pressed_keys == [*AppKeyRecorder.ALPHAS]
@@ -246,7 +246,7 @@ async def test_pressing_movement_keys_app() -> None:
"""Test that pressing the movement keys, when they're bound on the app, results in an action fire.""" """Test that pressing the movement keys, when they're bound on the app, results in an action fire."""
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()
pilot.app.all_recorded() pilot.app.all_recorded()
@@ -284,7 +284,7 @@ async def test_focused_child_widget_with_movement_bindings() -> None:
"""A focused child widget with movement bindings should handle its own actions.""" """A focused child widget with movement bindings should handle its own actions."""
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)
pilot.app.all_recorded("locally_") pilot.app.all_recorded("locally_")
@@ -331,7 +331,7 @@ async def test_focused_child_widget_with_movement_bindings_on_screen() -> None:
"""A focused child widget, with movement bindings in the screen, should trigger screen actions.""" """A focused child widget, with movement bindings in the screen, should trigger screen actions."""
async with AppWithScreenWithBindingsWidgetNoBindings().run_test() as pilot: async with AppWithScreenWithBindingsWidgetNoBindings().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALL_KEYS) await pilot.press(*AppKeyRecorder.ALL_KEYS)
await pilot.pause(2 / 100)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
@@ -374,7 +374,7 @@ async def test_contained_focused_child_widget_with_movement_bindings_on_screen()
"""A contained focused child widget, with movement bindings in the screen, should trigger screen actions.""" """A contained focused child widget, with movement bindings in the screen, should trigger screen actions."""
async with AppWithScreenWithBindingsWrappedWidgetNoBindings().run_test() as pilot: async with AppWithScreenWithBindingsWrappedWidgetNoBindings().run_test() as pilot:
await pilot.press(*AppKeyRecorder.ALL_KEYS) await pilot.press(*AppKeyRecorder.ALL_KEYS)
await pilot.pause(2 / 100)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
@@ -413,7 +413,7 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
"""A focused child widget with movement bindings and inherit_bindings=False should handle its own actions.""" """A focused child widget with movement bindings and inherit_bindings=False should handle its own actions."""
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)
pilot.app.all_recorded("locally_") pilot.app.all_recorded("locally_")
@@ -465,7 +465,7 @@ async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen(
"""A focused child widget, that doesn't inherit bindings, with movement bindings in the screen, should trigger screen actions.""" """A focused child widget, that doesn't inherit bindings, with movement bindings in the screen, should trigger screen actions."""
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)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
@@ -520,7 +520,6 @@ async def test_focused_child_widget_no_inherit_empty_bindings_with_movement_bind
"""A focused child widget, that doesn't inherit bindings and sets BINDINGS empty, with movement bindings in the screen, should trigger screen actions.""" """A focused child widget, that doesn't inherit bindings and sets BINDINGS empty, with movement bindings in the screen, should trigger screen actions."""
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)
pilot.app.all_recorded("screenly_") pilot.app.all_recorded("screenly_")
@@ -602,7 +601,6 @@ async def test_overlapping_priority_bindings() -> None:
"""Test an app stack with overlapping bindings.""" """Test an app stack with overlapping bindings."""
async with PriorityOverlapApp().run_test() as pilot: async with PriorityOverlapApp().run_test() as pilot:
await pilot.press(*"0abcdef") await pilot.press(*"0abcdef")
await pilot.pause(2 / 100)
assert pilot.app.pressed_keys == [ assert pilot.app.pressed_keys == [
"widget_0", "widget_0",
"app_a", "app_a",

View File

@@ -40,5 +40,4 @@ async def test_toggle_dark_in_action() -> None:
"""It should be possible to toggle dark mode with an action.""" """It should be possible to toggle dark mode with an action."""
async with OnMountDarkSwitch().run_test() as pilot: async with OnMountDarkSwitch().run_test() as pilot:
await pilot.press("d") await pilot.press("d")
await pilot.pause(2 / 100)
assert not pilot.app.dark assert not pilot.app.dark

View File

@@ -16,7 +16,6 @@ async def test_run_test() -> None:
str(pilot) == "<Pilot app=TestApp(title='TestApp', classes={'-dark-mode'})>" str(pilot) == "<Pilot app=TestApp(title='TestApp', classes={'-dark-mode'})>"
) )
await pilot.press("tab", *"foo") await pilot.press("tab", *"foo")
await pilot.pause(1 / 100)
await pilot.exit("bar") await pilot.exit("bar")
assert app.return_value == "bar" assert app.return_value == "bar"

View File

@@ -45,7 +45,6 @@ async def test_tree_node_selected_message() -> None:
"""Selecting a node should result in a selected message being emitted.""" """Selecting a node should result in a selected message being emitted."""
async with TreeApp().run_test() as pilot: async with TreeApp().run_test() as pilot:
await pilot.press("enter") await pilot.press("enter")
await pilot.pause(2 / 100)
assert pilot.app.messages == ["NodeExpanded", "NodeSelected"] assert pilot.app.messages == ["NodeExpanded", "NodeSelected"]
@@ -53,7 +52,6 @@ async def test_tree_node_expanded_message() -> None:
"""Expanding a node should result in an expanded message being emitted.""" """Expanding a node should result in an expanded message being emitted."""
async with TreeApp().run_test() as pilot: async with TreeApp().run_test() as pilot:
await pilot.press("enter") await pilot.press("enter")
await pilot.pause(2 / 100)
assert pilot.app.messages == ["NodeExpanded", "NodeSelected"] assert pilot.app.messages == ["NodeExpanded", "NodeSelected"]
@@ -61,7 +59,6 @@ async def test_tree_node_collapsed_message() -> None:
"""Collapsing a node should result in a collapsed message being emitted.""" """Collapsing a node should result in a collapsed message being emitted."""
async with TreeApp().run_test() as pilot: async with TreeApp().run_test() as pilot:
await pilot.press("enter", "enter") await pilot.press("enter", "enter")
await pilot.pause(2 / 100)
assert pilot.app.messages == [ assert pilot.app.messages == [
"NodeExpanded", "NodeExpanded",
"NodeSelected", "NodeSelected",
@@ -74,5 +71,4 @@ async def test_tree_node_highlighted_message() -> None:
"""Highlighting a node should result in a highlighted message being emitted.""" """Highlighting a node should result in a highlighted message being emitted."""
async with TreeApp().run_test() as pilot: async with TreeApp().run_test() as pilot:
await pilot.press("enter", "down") await pilot.press("enter", "down")
await pilot.pause(2 / 100)
assert pilot.app.messages == ["NodeExpanded", "NodeSelected", "NodeHighlighted"] assert pilot.app.messages == ["NodeExpanded", "NodeSelected", "NodeHighlighted"]