File: test_issue_4301.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 (38 lines) | stat: -rw-r--r-- 1,285 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
from itertools import product

import pytest

from textual.app import App, ComposeResult
from textual.widgets import TextArea
from textual.widgets.text_area import Selection

TEST_TEXT = "\n".join(f"01234567890 - {n}" for n in range(10))
TEST_SELECTED_TEXT = "567890 - 0\n01234567890 - 1\n01234"


class TextAreaApp(App[None]):

    def compose(self) -> ComposeResult:
        yield TextArea(TEST_TEXT)


@pytest.mark.parametrize(
    "selection, edit",
    product(
        [Selection((0, 5), (2, 5)), Selection((2, 5), (0, 5))],
        ["A", "delete", "backspace"],
    ),
)
async def test_issue_4301_reproduction(selection: Selection, edit: str) -> None:
    """Test https://github.com/Textualize/textual/issues/4301"""

    async with (app := TextAreaApp()).run_test() as pilot:
        assert app.query_one(TextArea).text == TEST_TEXT
        app.query_one(TextArea).selection = selection
        assert app.query_one(TextArea).selected_text == TEST_SELECTED_TEXT
        await pilot.press(edit)
        await pilot.press("ctrl+z")
        assert app.query_one(TextArea).text == TEST_TEXT
        # Note that the real test here is that the following code doesn't
        # result in a crash; everything above should really be a given.
        await pilot.press(*(["down"] * 10))