File: test_style_parse.py

package info (click to toggle)
textual 2.1.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,080 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (56 lines) | stat: -rw-r--r-- 2,114 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pytest

from textual.color import Color
from textual.style import Style


@pytest.mark.parametrize(
    ["markup", "style"],
    [
        ("", Style()),
        (
            "b",
            Style(bold=True),
        ),
        ("i", Style(italic=True)),
        ("u", Style(underline=True)),
        ("r", Style(reverse=True)),
        ("bold", Style(bold=True)),
        ("italic", Style(italic=True)),
        ("underline", Style(underline=True)),
        ("reverse", Style(reverse=True)),
        ("bold italic", Style(bold=True, italic=True)),
        ("not bold italic", Style(bold=False, italic=True)),
        ("bold not italic", Style(bold=True, italic=False)),
        ("rgb(10, 20, 30)", Style(foreground=Color(10, 20, 30))),
        ("rgba(10, 20, 30, 0.5)", Style(foreground=Color(10, 20, 30, 0.5))),
        ("rgb(10, 20, 30) 50%", Style(foreground=Color(10, 20, 30, 0.5))),
        ("on rgb(10, 20, 30)", Style(background=Color(10, 20, 30))),
        ("on rgb(10, 20, 30) 50%", Style(background=Color(10, 20, 30, 0.5))),
        ("@click=app.bell", Style.from_meta({"@click": "app.bell"})),
        ("@click='app.bell'", Style.from_meta({"@click": "app.bell"})),
        ('''@click="app.bell"''', Style.from_meta({"@click": "app.bell"})),
        ("@click=app.bell()", Style.from_meta({"@click": "app.bell()"})),
        (
            "@click=app.notify('hello')",
            Style.from_meta({"@click": "app.notify('hello')"}),
        ),
        (
            "@click=app.notify('hello [World]!')",
            Style.from_meta({"@click": "app.notify('hello [World]!')"}),
        ),
        (
            "@click=app.notify('hello') bold",
            Style(bold=True) + Style.from_meta({"@click": "app.notify('hello')"}),
        ),
    ],
)
def test_parse_style(markup: str, style: Style) -> None:
    """Check parsing of valid styles."""
    parsed_style = Style.parse(markup)
    print("parsed\t\t", repr(parsed_style))
    print("expected\t", repr(style))
    print(parsed_style.meta, style.meta)
    print(parsed_style._meta)
    print(style._meta)
    assert parsed_style == style