File: test_style_inheritance.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 (37 lines) | stat: -rw-r--r-- 1,099 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
from textual.app import App, ComposeResult
from textual.widgets import Button, Static


async def test_text_style_inheritance():
    """Check that changes to text style are inherited in children."""

    class FocusableThing(Static, can_focus=True):
        DEFAULT_CSS = """
        FocusableThing {
            text-style: bold;
        }

        FocusableThing:focus {
            text-style: bold reverse;
        }
        """

        def compose(self) -> ComposeResult:
            yield Static("test", id="child-of-focusable-thing")

    class InheritanceApp(App):
        def compose(self) -> ComposeResult:
            yield Button("button1")
            yield FocusableThing()
            yield Button("button2")

    app = InheritanceApp()
    async with app.run_test() as pilot:
        await pilot.pause()
        child = app.query_one("#child-of-focusable-thing")
        assert child.rich_style.bold
        assert not child.rich_style.reverse
        await pilot.press("tab")
        await pilot.pause()
        assert child.rich_style.bold
        assert child.rich_style.reverse