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

Function test_select_remove

tests/test_widget.py:734–768  ·  view source on GitHub ↗

Test selecting text after a widget is removed. Regression test for https://github.com/Textualize/textual/issues/6452

()

Source from the content-addressed store, hash-verified

732
733
734async def test_select_remove():
735 """Test selecting text after a widget is removed.
736
737 Regression test for https://github.com/Textualize/textual/issues/6452
738
739 """
740
741 top_text = "Hello, World " * 20
742 vanish_text = "This will vanish " * 10
743
744 class SelApp(App):
745
746 BINDINGS = [("space", "vanish")]
747
748 def compose(self) -> ComposeResult:
749 yield Static(top_text)
750 yield Static(vanish_text, id="vanish")
751
752 def action_vanish(self) -> None:
753 self.query_one("#vanish").remove()
754
755 app = SelApp()
756 # Simulate mouse down, move to second widget, remove second widget, move mouse, mouse up
757 # Prior to the fix this would result in an error as the second widget was no longer attached
758 # Post fix, there should be no error, and the selected text should be from the first widget.
759 async with app.run_test() as pilot:
760 await pilot.mouse_down(offset=(5, 2))
761 await pilot.hover(offset=(20, 5))
762 await app.query_one("#vanish").remove()
763 await pilot.hover(offset=(25, 6))
764 await pilot.mouse_up(offset=(30, 5))
765 selected_text = app.screen.get_selected_text()
766 expected = ", World Hello, World Hello, World Hello, World Hello, World Hello, World Hello, World Hello, World "
767 print(repr(selected_text))
768 assert selected_text == expected

Callers

nothing calls this directly

Calls 8

SelAppClass · 0.85
run_testMethod · 0.80
mouse_downMethod · 0.80
hoverMethod · 0.80
query_oneMethod · 0.80
mouse_upMethod · 0.80
get_selected_textMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…