-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_cell_padding.py
82 lines (73 loc) · 2.79 KB
/
test_cell_padding.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import pytest
from table2ascii import Alignment, table2ascii as t2a
def test_without_cell_padding():
text = t2a(
header=["#", "G", "H", "R", "S"],
body=[[1, 2, 3, 4, 5]],
footer=["A", "B", 1, 2, 3],
first_col_heading=True,
cell_padding=0,
)
expected = (
"╔═╦═══════╗\n"
"║#║G H R S║\n"
"╟─╫───────╢\n"
"║1║2 3 4 5║\n"
"╟─╫───────╢\n"
"║A║B 1 2 3║\n"
"╚═╩═══════╝"
)
assert text == expected
def test_column_width_and_alignment_without_cell_padding():
text = t2a(
header=["#", "G", "H", "R", "S"],
body=[[1, 2, 3, 4, 5]],
footer=["A", "B", 1, 2, 3],
column_widths=[4, 8, 5, 4, 5],
alignments=[
Alignment.LEFT,
Alignment.CENTER,
Alignment.RIGHT,
Alignment.LEFT,
Alignment.RIGHT,
],
first_col_heading=True,
cell_padding=0,
)
expected = (
"╔════╦═════════════════════════╗\n"
"║# ║ G H R S║\n"
"╟────╫─────────────────────────╢\n"
"║1 ║ 2 3 4 5║\n"
"╟────╫─────────────────────────╢\n"
"║A ║ B 1 2 3║\n"
"╚════╩═════════════════════════╝"
)
assert text == expected
def test_cell_padding_more_than_one():
text = t2a(
header=["#", "G", "H", "R", "S"],
body=[[1, 2, 3, 4, 5]],
footer=["A", "B", 1, 2, 3],
first_col_heading=True,
cell_padding=2,
)
expected = (
"╔═════╦═══════════════════════╗\n"
"║ # ║ G H R S ║\n"
"╟─────╫───────────────────────╢\n"
"║ 1 ║ 2 3 4 5 ║\n"
"╟─────╫───────────────────────╢\n"
"║ A ║ B 1 2 3 ║\n"
"╚═════╩═══════════════════════╝"
)
assert text == expected
def test_negative_cell_padding():
with pytest.raises(ValueError):
t2a(
header=["#", "G", "H", "R", "S"],
body=[[1, 2, 3, 4, 5]],
footer=["A", "B", 1, 2, 3],
first_col_heading=True,
cell_padding=-1,
)