Using console.get_style, adding test ensuring style applies

This commit is contained in:
Darren Burns
2022-01-31 14:13:49 +00:00
parent 776284ddd0
commit 65eb1b0b4f
2 changed files with 30 additions and 31 deletions

View File

@@ -1,11 +1,11 @@
from rich.style import Style
from tests.utilities.render import render
from textual.renderables.underline_bar import UnderlineBar
MAGENTA = "\x1b[35m"
GREY = "\x1b[38;5;59m"
STOP = "\x1b[0m"
GREEN = "\x1b[32m"
RED = "\x1b[31m"
def test_no_highlight():
@@ -110,13 +110,17 @@ def test_highlight_full_range_out_of_bounds_start():
assert render(bar) == f"{GREY}━━━━━━{STOP}"
def test_init_with_str_style():
bar = UnderlineBar(background_style="green", highlight_style="yellow")
assert bar.background_style == Style(color="green")
assert bar.highlight_style == Style(color="yellow")
def test_init_with_object_style():
bar = UnderlineBar(background_style=Style(color="green"), highlight_style=Style(color="yellow"))
assert bar.background_style == Style(color="green")
assert bar.highlight_style == Style(color="yellow")
def test_custom_styles():
bar = UnderlineBar(
highlight_range=(2, 4),
highlight_style="red",
background_style="green",
width=6
)
assert render(bar) == (
f"{GREEN}{STOP}"
f"{GREEN}{STOP}"
f"{RED}━━{STOP}"
f"{GREEN}{STOP}"
f"{GREEN}{STOP}"
)