File: test_listview_initial_index.py

package info (click to toggle)
textual 2.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,084 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (42 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import pytest

from textual.app import App, ComposeResult
from textual.widgets import Label, ListItem, ListView


@pytest.mark.parametrize(
    "initial_index,expected_index",
    [
        (0, 1),
        (1, 1),
        (2, 4),
        (3, 4),
        (4, 4),
        (5, 5),
        (6, 7),
        (7, 7),
        (8, 1),
    ],
)
async def test_listview_initial_index(initial_index, expected_index) -> None:
    """Regression test for https://github.com/Textualize/textual/issues/4449"""

    class ListViewDisabledItemsApp(App[None]):
        def compose(self) -> ComposeResult:
            yield ListView(
                ListItem(Label("0"), disabled=True),
                ListItem(Label("1")),
                ListItem(Label("2"), disabled=True),
                ListItem(Label("3"), disabled=True),
                ListItem(Label("4")),
                ListItem(Label("5")),
                ListItem(Label("6"), disabled=True),
                ListItem(Label("7")),
                ListItem(Label("8"), disabled=True),
                initial_index=initial_index,
            )

    app = ListViewDisabledItemsApp()
    async with app.run_test() as pilot:
        list_view = pilot.app.query_one(ListView)
        assert list_view.index == expected_index