From 9dede19a1fc759f463cc1ae80ad928267da19e51 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Wed, 18 Jan 2023 10:27:58 +0000 Subject: [PATCH] Add a test for inheriting from a ListView Added to test the fail in #1588. Any fix for this should cause this test to pass. --- tests/listview/test_inherit_listview.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/listview/test_inherit_listview.py diff --git a/tests/listview/test_inherit_listview.py b/tests/listview/test_inherit_listview.py new file mode 100644 index 0000000000..bb9197646d --- /dev/null +++ b/tests/listview/test_inherit_listview.py @@ -0,0 +1,26 @@ +from textual.app import App, ComposeResult +from textual.widgets import ListView, ListItem, Label + + +class MyListView(ListView): + def compose(self) -> ComposeResult: + """Compose the child widgets.""" + for n in range(20): + yield ListView(Label(f"This is item {n}")) + + +class ListViewApp(App[None]): + """ListView test app.""" + + def compose(self) -> ComposeResult: + """Compose the child widgets.""" + yield MyListView() + + +async def test_inherited_list_view() -> None: + """A self-populating inherited ListView should work as normal.""" + async with ListViewApp().run_test() as pilot: + await pilot.press("tab") + assert pilot.app.query_one(MyListView).index == 0 + await pilot.press("down") + assert pilot.app.query_one(MyListView).index == 1