MCPcopy
hub / github.com/Textualize/textual / test_skip_action

Function test_skip_action

tests/test_binding_inheritance.py:608–642  ·  view source on GitHub ↗

Test that a binding may be skipped by an action raising SkipAction

()

Source from the content-addressed store, hash-verified

606
607
608async def test_skip_action() -> None:
609 """Test that a binding may be skipped by an action raising SkipAction"""
610
611 class Handle(Widget, can_focus=True):
612 BINDINGS = [("t", "test('foo')", "Test")]
613
614 def action_test(self, text: str) -> None:
615 self.app.exit(text)
616
617 no_handle_invoked = False
618
619 class NoHandle(Widget, can_focus=True):
620 BINDINGS = [("t", "test('bar')", "Test")]
621
622 def action_test(self, text: str) -> bool:
623 nonlocal no_handle_invoked
624 no_handle_invoked = True
625 raise SkipAction()
626
627 class SkipApp(App):
628 def compose(self) -> ComposeResult:
629 yield Handle(NoHandle())
630
631 def on_mount(self) -> None:
632 self.query_one(NoHandle).focus()
633
634 async with SkipApp().run_test() as pilot:
635 # Check the NoHandle widget has focus
636 assert pilot.app.query_one(NoHandle).has_focus
637 # Press the "t" key
638 await pilot.press("t")
639 # Check the action on the no handle widget was called
640 assert no_handle_invoked
641 # Check the return value, confirming that the action on Handle was called
642 assert pilot.app.return_value == "foo"

Callers

nothing calls this directly

Calls 4

SkipAppClass · 0.85
run_testMethod · 0.80
query_oneMethod · 0.80
pressMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…