From 3eac79568ca4d031edda5fa924c865cc6c0b0cd3 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 26 Jan 2023 16:10:13 +0100 Subject: [PATCH] remove some pauses --- src/textual/pilot.py | 9 ++++++--- tests/listview/test_inherit_listview.py | 4 ---- tests/test_auto_pilot.py | 1 - tests/test_binding_inheritance.py | 16 +++++++--------- tests/test_dark_toggle.py | 1 - tests/test_test_runner.py | 1 - tests/tree/test_tree_messages.py | 4 ---- 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/textual/pilot.py b/src/textual/pilot.py index 3ddb12e8d..6c8375c61 100644 --- a/src/textual/pilot.py +++ b/src/textual/pilot.py @@ -34,14 +34,17 @@ class Pilot(Generic[ReturnType]): if 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. 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, - 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: """Wait for any animation to complete.""" diff --git a/tests/listview/test_inherit_listview.py b/tests/listview/test_inherit_listview.py index f5dfefeb1..2f147a28a 100644 --- a/tests/listview/test_inherit_listview.py +++ b/tests/listview/test_inherit_listview.py @@ -31,10 +31,8 @@ async def test_empty_inherited_list_view() -> None: """An empty self-populating inherited ListView should work as expected.""" async with ListViewApp().run_test() as pilot: await pilot.press("tab") - await pilot.pause(2 / 100) assert pilot.app.query_one(MyListView).index is None await pilot.press("down") - await pilot.pause(2 / 100) 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.""" async with ListViewApp(30).run_test() as pilot: await pilot.press("tab") - await pilot.pause(2 / 100) assert pilot.app.query_one(MyListView).index == 0 await pilot.press("down") - await pilot.pause(2 / 100) assert pilot.app.query_one(MyListView).index == 1 diff --git a/tests/test_auto_pilot.py b/tests/test_auto_pilot.py index dde2ad18c..5e2834c83 100644 --- a/tests/test_auto_pilot.py +++ b/tests/test_auto_pilot.py @@ -14,7 +14,6 @@ def test_auto_pilot() -> None: async def auto_pilot(pilot: Pilot) -> None: await pilot.press("tab", *"foo") - await pilot.pause(1 / 100) await pilot.exit("bar") app = TestApp() diff --git a/tests/test_binding_inheritance.py b/tests/test_binding_inheritance.py index 6aad85e37..5afb5e531 100644 --- a/tests/test_binding_inheritance.py +++ b/tests/test_binding_inheritance.py @@ -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.""" async with AppWithMovementKeysBound().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALPHAS) - await pilot.pause(2 / 100) + await pilot.pause() 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.""" async with AppWithMovementKeysBound().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + await pilot.pause() 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.""" async with AppWithWidgetWithBindings().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + 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.""" async with AppWithScreenWithBindingsWidgetNoBindings().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + 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.""" async with AppWithScreenWithBindingsWrappedWidgetNoBindings().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + 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.""" async with AppWithWidgetWithBindingsNoInherit().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + 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.""" async with AppWithScreenWithBindingsWidgetNoBindingsNoInherit().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) + 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.""" async with AppWithScreenWithBindingsWidgetEmptyBindingsNoInherit().run_test() as pilot: await pilot.press(*AppKeyRecorder.ALL_KEYS) - await pilot.pause(2 / 100) pilot.app.all_recorded("screenly_") @@ -602,7 +601,6 @@ async def test_overlapping_priority_bindings() -> None: """Test an app stack with overlapping bindings.""" async with PriorityOverlapApp().run_test() as pilot: await pilot.press(*"0abcdef") - await pilot.pause(2 / 100) assert pilot.app.pressed_keys == [ "widget_0", "app_a", diff --git a/tests/test_dark_toggle.py b/tests/test_dark_toggle.py index cbceb766c..1a746e4bd 100644 --- a/tests/test_dark_toggle.py +++ b/tests/test_dark_toggle.py @@ -40,5 +40,4 @@ async def test_toggle_dark_in_action() -> None: """It should be possible to toggle dark mode with an action.""" async with OnMountDarkSwitch().run_test() as pilot: await pilot.press("d") - await pilot.pause(2 / 100) assert not pilot.app.dark diff --git a/tests/test_test_runner.py b/tests/test_test_runner.py index e513284fd..0435d31d9 100644 --- a/tests/test_test_runner.py +++ b/tests/test_test_runner.py @@ -16,7 +16,6 @@ async def test_run_test() -> None: str(pilot) == "" ) await pilot.press("tab", *"foo") - await pilot.pause(1 / 100) await pilot.exit("bar") assert app.return_value == "bar" diff --git a/tests/tree/test_tree_messages.py b/tests/tree/test_tree_messages.py index f271d4e42..67620d70e 100644 --- a/tests/tree/test_tree_messages.py +++ b/tests/tree/test_tree_messages.py @@ -45,7 +45,6 @@ async def test_tree_node_selected_message() -> None: """Selecting a node should result in a selected message being emitted.""" async with TreeApp().run_test() as pilot: await pilot.press("enter") - await pilot.pause(2 / 100) 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.""" async with TreeApp().run_test() as pilot: await pilot.press("enter") - await pilot.pause(2 / 100) 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.""" async with TreeApp().run_test() as pilot: await pilot.press("enter", "enter") - await pilot.pause(2 / 100) assert pilot.app.messages == [ "NodeExpanded", "NodeSelected", @@ -74,5 +71,4 @@ async def test_tree_node_highlighted_message() -> None: """Highlighting a node should result in a highlighted message being emitted.""" async with TreeApp().run_test() as pilot: await pilot.press("enter", "down") - await pilot.pause(2 / 100) assert pilot.app.messages == ["NodeExpanded", "NodeSelected", "NodeHighlighted"]