File: test_style_properties.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 (32 lines) | stat: -rw-r--r-- 1,120 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
import pytest
from rich.style import Style

from textual.color import Color
from textual.css.errors import StyleValueError
from textual.css.styles import Styles


def test_box_normalization():
    """Check that none or hidden is normalized to empty string."""
    styles = Styles()
    styles.border_left = ("none", "red")
    assert styles.border_left == ("", Color.parse("red"))


@pytest.mark.parametrize("style_attr", ["text_style", "link_style"])
def test_text_style_none_with_others(style_attr):
    """Style "none" mixed with others should give custom Textual exception."""
    styles = Styles()

    with pytest.raises(StyleValueError):
        setattr(styles, style_attr, "bold none underline italic")


@pytest.mark.parametrize("style_attr", ["text_style", "link_style"])
def test_text_style_set_to_none(style_attr):
    """Setting text style to "none" should clear the styles."""
    styles = Styles()
    setattr(styles, style_attr, "bold underline italic")
    assert getattr(styles, style_attr) != Style.null()
    setattr(styles, style_attr, "none")
    assert getattr(styles, style_attr) == Style.null()