2020-05-15 20:48:23 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-02-14 11:07:16 +00:00
|
|
|
from rich.console import ConsoleOptions, ConsoleDimensions
|
2020-10-08 17:18:25 +00:00
|
|
|
from rich.box import ASCII, DOUBLE, ROUNDED, HEAVY, SQUARE
|
2020-05-15 20:48:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_str():
|
|
|
|
assert str(ASCII) == "+--+\n| ||\n|-+|\n| ||\n|-+|\n|-+|\n| ||\n+--+\n"
|
|
|
|
|
|
|
|
|
|
|
|
def test_repr():
|
|
|
|
assert repr(ASCII) == "Box(...)"
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_top():
|
|
|
|
top = HEAVY.get_top(widths=[1, 2])
|
|
|
|
assert top == "┏━┳━━┓"
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_row():
|
|
|
|
head_row = DOUBLE.get_row(widths=[3, 2, 1], level="head")
|
|
|
|
assert head_row == "╠═══╬══╬═╣"
|
|
|
|
|
|
|
|
row = ASCII.get_row(widths=[1, 2, 3], level="row")
|
|
|
|
assert row == "|-+--+---|"
|
|
|
|
|
|
|
|
foot_row = ROUNDED.get_row(widths=[2, 1, 3], level="foot")
|
2020-06-28 10:10:59 +00:00
|
|
|
assert foot_row == "├──┼─┼───┤"
|
2020-05-15 20:48:23 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
ROUNDED.get_row(widths=[1, 2, 3], level="FOO")
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_bottom():
|
|
|
|
bottom = HEAVY.get_bottom(widths=[1, 2, 3])
|
|
|
|
assert bottom == "┗━┻━━┻━━━┛"
|
2020-06-28 10:10:59 +00:00
|
|
|
|
|
|
|
|
2020-10-08 17:18:25 +00:00
|
|
|
def test_box_substitute():
|
|
|
|
options = ConsoleOptions(
|
2021-02-14 11:07:16 +00:00
|
|
|
ConsoleDimensions(80, 25),
|
2020-10-08 17:18:25 +00:00
|
|
|
legacy_windows=True,
|
|
|
|
min_width=1,
|
|
|
|
max_width=100,
|
|
|
|
is_terminal=True,
|
|
|
|
encoding="utf-8",
|
2021-07-11 13:25:14 +00:00
|
|
|
max_height=25,
|
2020-10-08 17:18:25 +00:00
|
|
|
)
|
|
|
|
assert HEAVY.substitute(options) == SQUARE
|
|
|
|
|
|
|
|
options.legacy_windows = False
|
|
|
|
assert HEAVY.substitute(options) == HEAVY
|
|
|
|
|
|
|
|
options.encoding = "ascii"
|
2020-10-08 17:25:37 +00:00
|
|
|
assert HEAVY.substitute(options) == ASCII
|