Skip to content

Commit

Permalink
Add a test for Textualize#1351
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Dec 13, 2022
1 parent e74dbab commit 0251a4b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_binding_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,42 @@ async def test_focused_child_widget_with_movement_bindings_no_inherit() -> None:
async with AppWithWidgetWithBindingsNoInherit().run_test() as pilot:
await pilot.press("x", *MOVEMENT_KEYS, "x")
assert pilot.app.pressed_keys == ["locally_x", *[f"locally_{key}" for key in MOVEMENT_KEYS], "locally_x"]

##############################################################################
class FocusableWidgetWithNoBindingsNoInherit(Static, can_focus=True, inherit_bindings=False):
"""A widget that can receive focus but has no bindings and doesn't inherit bindings."""

class ScreenWithMovementBindingsNoInheritChild(Screen):
"""A screen that binds keys, including movement keys."""

BINDINGS = [
Binding("x", "screen_record('x')", "x"),
*[Binding(key, f"screen_record('{key}')", key) for key in MOVEMENT_KEYS]
]

async def action_screen_record(self, key: str) -> None:
# Sneaky forward reference. Just for the purposes of testing.
await self.app.action_record(f"screen_{key}")

def compose(self) -> ComposeResult:
yield FocusableWidgetWithNoBindingsNoInherit()

def on_mount(self) -> None:
self.query_one(FocusableWidgetWithNoBindingsNoInherit).focus()

class AppWithScreenWithBindingsWidgetNoBindingsNoInherit(AppKeyRecorder):
"""An app with a non-default screen that handles movement key bindings, child no-inherit."""

SCREENS = {"main":ScreenWithMovementBindingsNoInheritChild}

def on_mount(self) -> None:
self.push_screen("main")

@pytest.mark.xfail(
reason="A child widget that doesn't inherit bindings, but has no bindings, incorrectly defers to its parent class [issue#1351]"
)
async def test_focused_child_widget_no_inherit_with_movement_bindings_on_screen() -> None:
"""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("x", *MOVEMENT_KEYS, "x")
assert pilot.app.pressed_keys == ["screen_x", *[f"screen_{key}" for key in MOVEMENT_KEYS], "screen_x"]

0 comments on commit 0251a4b

Please sign in to comment.