Debian Codegraph @

tests/test_box.py

raw
1 import pytest
2
3 from rich.console import ConsoleOptions, ConsoleDimensions
4 from rich.box import (
5 ASCII,
6 DOUBLE,
7 ROUNDED,
8 HEAVY,
9 SQUARE,
10 MINIMAL_HEAVY_HEAD,
11 MINIMAL,
12 SIMPLE_HEAVY,
13 SIMPLE,
14 HEAVY_EDGE,
15 HEAVY_HEAD,
16 )
17
18
19 def test_str():
20 assert str(ASCII) == "+--+\n| ||\n|-+|\n| ||\n|-+|\n|-+|\n| ||\n+--+\n"
21
22
23 def test_repr():
24 assert repr(ASCII) == "Box(...)"
25
26
27 def test_get_top():
28 top = HEAVY.get_top(widths=[1, 2])
29 assert top == "┏━┳━━┓"
30
31
32 def test_get_row():
33 head_row = DOUBLE.get_row(widths=[3, 2, 1], level="head")
34 assert head_row == "╠═══╬══╬═╣"
35
36 row = ASCII.get_row(widths=[1, 2, 3], level="row")
37 assert row == "|-+--+---|"
38
39 foot_row = ROUNDED.get_row(widths=[2, 1, 3], level="foot")
40 assert foot_row == "├──┼─┼───┤"
41
42 with pytest.raises(ValueError):
43 ROUNDED.get_row(widths=[1, 2, 3], level="FOO")
44
45
46 def test_get_bottom():
47 bottom = HEAVY.get_bottom(widths=[1, 2, 3])
48 assert bottom == "┗━┻━━┻━━━┛"
49
50
51 def test_box_substitute_for_same_box():
52 options = ConsoleOptions(
53 ConsoleDimensions(80, 25),
54 legacy_windows=False,
55 min_width=1,
56 max_width=100,
57 is_terminal=True,
58 encoding="utf-8",
59 max_height=25,
60 )
61
62 assert ROUNDED.substitute(options) == ROUNDED
63 assert MINIMAL_HEAVY_HEAD.substitute(options) == MINIMAL_HEAVY_HEAD
64 assert SIMPLE_HEAVY.substitute(options) == SIMPLE_HEAVY
65 assert HEAVY.substitute(options) == HEAVY
66 assert HEAVY_EDGE.substitute(options) == HEAVY_EDGE
67 assert HEAVY_HEAD.substitute(options) == HEAVY_HEAD
68
69
70 def test_box_substitute_for_different_box_legacy_windows():
71 options = ConsoleOptions(
72 ConsoleDimensions(80, 25),
73 legacy_windows=True,
74 min_width=1,
75 max_width=100,
76 is_terminal=True,
77 encoding="utf-8",
78 max_height=25,
79 )
80
81 assert ROUNDED.substitute(options) == SQUARE
82 assert MINIMAL_HEAVY_HEAD.substitute(options) == MINIMAL
83 assert SIMPLE_HEAVY.substitute(options) == SIMPLE
84 assert HEAVY.substitute(options) == SQUARE
85 assert HEAVY_EDGE.substitute(options) == SQUARE
86 assert HEAVY_HEAD.substitute(options) == SQUARE
87
88
89 def test_box_substitute_for_different_box_ascii_encoding():
90 options = ConsoleOptions(
91 ConsoleDimensions(80, 25),
92 legacy_windows=True,
93 min_width=1,
94 max_width=100,
95 is_terminal=True,
96 encoding="ascii",
97 max_height=25,
98 )
99
100 assert ROUNDED.substitute(options) == ASCII
101 assert MINIMAL_HEAVY_HEAD.substitute(options) == ASCII
102 assert SIMPLE_HEAVY.substitute(options) == ASCII
103 assert HEAVY.substitute(options) == ASCII
104 assert HEAVY_EDGE.substitute(options) == ASCII
105 assert HEAVY_HEAD.substitute(options) == ASCII