Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / tools / lint / test / test_perfdocs_helpers.py
blob02c1abfecc3f8260282af986f941ca7c3de2c942
1 import mozunit
2 import pytest
4 LINTER = "perfdocs"
6 testdata = [
8 "table_specifications": {
9 "title": ["not a string"],
10 "widths": [10, 10, 10, 10],
11 "header_rows": 1,
12 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
13 "indent": 2,
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"),
21 "header_rows": 1,
22 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
23 "indent": 2,
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"],
31 "header_rows": 1,
32 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
33 "indent": 2,
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"]],
43 "indent": 2,
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],
51 "header_rows": 1,
52 "headers": ("not", "a", "list"),
53 "indent": 2,
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],
61 "header_rows": 1,
62 "headers": ["not", "two", "dimensional"],
63 "indent": 2,
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],
71 "header_rows": 1,
72 "headers": [[1, 2, 3]],
73 "indent": 2,
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],
81 "header_rows": 1,
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],
92 "header_rows": 1,
93 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
94 "indent": 2,
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:
106 TableBuilder(
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],
123 "header_rows": 1,
124 "headers": [["Coconut 1", "Coconut 2", "Coconut 3"]],
125 "indent": 2,
128 with pytest.raises(MismatchedRowLengthsException) as error:
129 TableBuilder(
130 table_specifications["title"],
131 table_specifications["widths"],
132 table_specifications["header_rows"],
133 table_specifications["headers"],
134 table_specifications["indent"],
136 assert (
137 str(error.value)
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:
153 table.add_row(
154 ["big ones", "small ones", "some as big as your head!", "(and bigger)"]
156 assert (
157 str(error.value)
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:
173 table.add_rows(
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!"])
190 table.add_row(
191 ["Give 'em a twist", "A flick of the wrist", "That's what the showman said!"]
193 table = table.finish_table()
194 print(table)
195 assert (
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__":
206 mozunit.main()