8 "table_specifications": {
9 "title": ["not a string"],
10 "widths": [10, 10, 10, 10],
12 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
15 "error_msg": "TableBuilder attribute title must be a string.",
18 "table_specifications": {
19 "title": "I've got a lovely bunch of coconuts",
20 "widths": ("not", "a", "list"),
22 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
25 "error_msg": "TableBuilder attribute widths must be a list of integers.",
28 "table_specifications": {
29 "title": "There they are all standing in a row",
30 "widths": ["not an integer"],
32 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
35 "error_msg": "TableBuilder attribute widths must be a list of integers.",
38 "table_specifications": {
39 "title": "Big ones, small ones",
40 "widths": [10, 10, 10, 10],
41 "header_rows": "not an integer",
42 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
45 "error_msg": "TableBuilder attribute header_rows must be an integer.",
48 "table_specifications": {
49 "title": "Some as big as your head!",
50 "widths": [10, 10, 10, 10],
52 "headers": ("not", "a", "list"),
55 "error_msg": "TableBuilder attribute headers must be a two-dimensional list of strings.",
58 "table_specifications": {
59 "title": "(And bigger)",
60 "widths": [10, 10, 10, 10],
62 "headers": ["not", "two", "dimensional"],
65 "error_msg": "TableBuilder attribute headers must be a two-dimensional list of strings.",
68 "table_specifications": {
69 "title": "Give 'em a twist, a flick of the wrist'",
70 "widths": [10, 10, 10, 10],
72 "headers": [[1, 2, 3]],
75 "error_msg": "TableBuilder attribute headers must be a two-dimensional list of strings.",
78 "table_specifications": {
79 "title": "That's what the showman said!",
80 "widths": [10, 10, 10, 10],
82 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
83 "indent": "not an integer",
85 "error_msg": "TableBuilder attribute indent must be an integer.",
89 table_specifications
= {
90 "title": "I've got a lovely bunch of coconuts",
91 "widths": [10, 10, 10],
93 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
98 @pytest.mark
.parametrize("testdata", testdata
)
99 def test_table_builder_invalid_attributes(testdata
):
100 from perfdocs
.doc_helpers
import TableBuilder
102 table_specifications
= testdata
["table_specifications"]
103 error_msg
= testdata
["error_msg"]
105 with pytest
.raises(TypeError) as error
:
107 table_specifications
["title"],
108 table_specifications
["widths"],
109 table_specifications
["header_rows"],
110 table_specifications
["headers"],
111 table_specifications
["indent"],
114 assert str(error
.value
) == error_msg
117 def test_table_builder_mismatched_columns():
118 from perfdocs
.doc_helpers
import MismatchedRowLengthsException
, TableBuilder
120 table_specifications
= {
121 "title": "I've got a lovely bunch of coconuts",
122 "widths": [10, 10, 10, 42],
124 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
128 with pytest
.raises(MismatchedRowLengthsException
) as error
:
130 table_specifications
["title"],
131 table_specifications
["widths"],
132 table_specifications
["header_rows"],
133 table_specifications
["headers"],
134 table_specifications
["indent"],
138 == "Number of table headers must match number of column widths."
142 def test_table_builder_add_row_too_long():
143 from perfdocs
.doc_helpers
import MismatchedRowLengthsException
, TableBuilder
145 table
= TableBuilder(
146 table_specifications
["title"],
147 table_specifications
["widths"],
148 table_specifications
["header_rows"],
149 table_specifications
["headers"],
150 table_specifications
["indent"],
152 with pytest
.raises(MismatchedRowLengthsException
) as error
:
154 ["big ones", "small ones", "some as big as your head!", "(and bigger)"]
158 == "Number of items in a row must must number of columns defined."
162 def test_table_builder_add_rows_type_error():
163 from perfdocs
.doc_helpers
import TableBuilder
165 table
= TableBuilder(
166 table_specifications
["title"],
167 table_specifications
["widths"],
168 table_specifications
["header_rows"],
169 table_specifications
["headers"],
170 table_specifications
["indent"],
172 with pytest
.raises(TypeError) as error
:
174 ["big ones", "small ones", "some as big as your head!", "(and bigger)"]
176 assert str(error
.value
) == "add_rows() requires a two-dimensional list of strings."
179 def test_table_builder_validate():
180 from perfdocs
.doc_helpers
import TableBuilder
182 table
= TableBuilder(
183 table_specifications
["title"],
184 table_specifications
["widths"],
185 table_specifications
["header_rows"],
186 table_specifications
["headers"],
187 table_specifications
["indent"],
189 table
.add_row(["big ones", "small ones", "some as big as your head!"])
191 ["Give 'em a twist", "A flick of the wrist", "That's what the showman said!"]
193 table
= table
.finish_table()
196 table
== " .. list-table:: **I've got a lovely bunch of coconuts**\n"
197 " :widths: 10 10 10\n :header-rows: 1\n\n"
198 " * - **Coconut 1**\n - Coconut 2\n - Coconut 3\n"
199 " * - **big ones**\n - small ones\n - some as big as your head!\n"
200 " * - **Give 'em a twist**\n - A flick of the wrist\n"
201 " - That's what the showman said!\n\n"
205 if __name__
== "__main__":