From b48acc0bd58386d3840876cabba4bdff34ebdf48 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 13 Dec 2022 08:27:22 +0000 Subject: [PATCH] Update the movement binding tests to use all movement keys Rather than just test a single specific movement key (in this case "up"), go with all the affected keys. The cost to doing so is zero and it means we get a full coverage of testing for all the keys that have become a problem with 0.6.0. --- tests/test_binding_inheritance.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/test_binding_inheritance.py b/tests/test_binding_inheritance.py index e40849af7..b7a5fcf80 100644 --- a/tests/test_binding_inheritance.py +++ b/tests/test_binding_inheritance.py @@ -5,6 +5,20 @@ from textual.widgets import Static from textual.screen import Screen from textual.binding import Binding +############################################################################## +# These are the movement keys within Textual; they kind of have a special +# status in that they will get bound to movement-related methods. +MOVEMENT_KEYS = [ + "up", + "down", + "left", + "right", + "home", + "end", + "pageup", + "pagedown" +] + ############################################################################## class NoBindings(App[None]): """An app with zero bindings.""" @@ -103,24 +117,24 @@ class AppKeyRecorder(App[None]): self.pressed_keys.append(key) ############################################################################## -class AppWithUpKeyBound(AppKeyRecorder): +class AppWithMovementKeysBound(AppKeyRecorder): BINDINGS=[ Binding("x","record('x')","x"), - Binding("up","record('up')","up") + *[Binding(key,f"record({key}')",key) for key in MOVEMENT_KEYS] ] async def test_pressing_alpha_on_app() -> None: """Test that pressing the an alpha key, when it's bound on the app, results in an action fire.""" - async with AppWithUpKeyBound().run_test() as pilot: + async with AppWithMovementKeysBound().run_test() as pilot: await pilot.press(*"xxxxx") assert "".join(pilot.app.pressed_keys) == "xxxxx" @pytest.mark.xfail( reason="Up key isn't firing bound action on an app due to key inheritence of its screen [issue#1343]" ) -async def test_pressing_up_on_app() -> None: - """Test that pressing the up key, when it's bound on the app, results in an action fire.""" - async with AppWithUpKeyBound().run_test() as pilot: - await pilot.press("x", "up", "x") - assert pilot.app.pressed_keys == ["x", "up", "x"] +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("x", *MOVEMENT_KEYS, "x") + assert pilot.app.pressed_keys == ["x", *MOVEMENT_KEYS, "x"]