blob: bc4e4e8498c5395f0b2dd5992e20371771a58196 (
plain) (
blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
from __future__ import annotations
from prettytable import PrettyTable, TableStyle
def test_rst_output_without_header(helper_table: PrettyTable) -> None:
helper_table.set_style(TableStyle.RST)
assert helper_table.get_string(header=False).strip() == """
+---+---------+--------+--------+
| 1 | value 1 | value2 | value3 |
+---+---------+--------+--------+
| 4 | value 4 | value5 | value6 |
+---+---------+--------+--------+
| 7 | value 7 | value8 | value9 |
+---+---------+--------+--------+
""".strip()
def test_rst_output_with_fields(helper_table: PrettyTable) -> None:
helper_table.set_style(TableStyle.RST)
assert helper_table.get_string(fields=["Field 1", "Field 3"]).strip() == """
+---------+---------+
| Field 1 | Field 3 |
+=========+=========+
| value 1 | value3 |
+---------+---------+
| value 4 | value6 |
+---------+---------+
| value 7 | value9 |
+---------+---------+
""".strip()
def test_rst_header_uses_equals(helper_table: PrettyTable) -> None:
# Arrange
helper_table.set_style(TableStyle.RST)
# Act
result = helper_table.get_string()
# Assert
lines = result.splitlines()
# The header separator (line after header row) should use "="
header_sep = lines[2]
assert "=" in header_sep
assert header_sep.startswith("+")
assert header_sep.endswith("+")
# Data separators should use "-"
data_sep = lines[4]
assert "=" not in data_sep
assert "-" in data_sep
def test_rst_style_does_not_leak(helper_table: PrettyTable) -> None:
# Arrange
original = helper_table.get_string()
# Act
helper_table.set_style(TableStyle.RST)
helper_table.set_style(TableStyle.DEFAULT)
# Assert
assert helper_table.get_string() == original
def test_rst_output_with_multiline_title(helper_table: PrettyTable) -> None:
# Arrange
helper_table.set_style(TableStyle.RST)
# Act
helper_table.title = "Line 1\nLine 2"
# Assert
assert helper_table.get_string() == """
+---------------------------------+
| Line 1 |
| Line 2 |
+---+---------+---------+---------+
| | Field 1 | Field 2 | Field 3 |
+===+=========+=========+=========+
| 1 | value 1 | value2 | value3 |
+---+---------+---------+---------+
| 4 | value 4 | value5 | value6 |
+---+---------+---------+---------+
| 7 | value 7 | value8 | value9 |
+---+---------+---------+---------+
""".strip()
def test_markdown_to_rst_does_not_leak(helper_table: PrettyTable) -> None:
# Arrange
helper_table.set_style(TableStyle.MARKDOWN)
helper_table.set_style(TableStyle.RST)
# Act
result = helper_table.get_string()
# Assert: Markdown's ":" alignment char should not appear in RST output
assert ":" not in result
|