Conditions | 2 |
Total Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import unittest |
||
134 | def test_extract_documentation_PYTHON3(self): |
||
135 | data = load_testdata("data.py") |
||
136 | docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3", |
||
137 | "default") |
||
138 | docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3", |
||
139 | "doxygen") |
||
140 | |||
141 | expected = (DocumentationComment( |
||
142 | ("\n" |
||
143 | "Module description.\n" |
||
144 | "\n" |
||
145 | "Some more foobar-like text.\n"), |
||
146 | docstyle_PYTHON3_default, "", |
||
147 | docstyle_PYTHON3_default.markers[0], |
||
148 | TextRange.from_values(1, 1, 5, 4)), |
||
149 | DocumentationComment( |
||
150 | ("\n" |
||
151 | "A nice and neat way of documenting code.\n" |
||
152 | ":param radius: The explosion radius.\n"), |
||
153 | docstyle_PYTHON3_default, " " * 4, |
||
154 | docstyle_PYTHON3_default.markers[0], |
||
155 | TextRange.from_values(8, 5, 11, 8)), |
||
156 | DocumentationComment( |
||
157 | "\nA function that returns 55.\n", |
||
158 | docstyle_PYTHON3_default, " " * 8, |
||
159 | docstyle_PYTHON3_default.markers[0], |
||
160 | TextRange.from_values(13, 9, 15, 12)), |
||
161 | DocumentationComment( |
||
162 | ("\n" |
||
163 | "Docstring with layouted text.\n" |
||
164 | "\n" |
||
165 | " layouts inside docs are preserved for these " |
||
166 | "documentation styles.\n" |
||
167 | "this is intended.\n"), |
||
168 | docstyle_PYTHON3_default, "", |
||
169 | docstyle_PYTHON3_default.markers[0], |
||
170 | TextRange.from_values(19, 1, 24, 4)), |
||
171 | DocumentationComment( |
||
172 | (" Docstring directly besides triple quotes.\n" |
||
173 | " Continues here. "), |
||
174 | docstyle_PYTHON3_default, "", |
||
175 | docstyle_PYTHON3_default.markers[0], |
||
176 | TextRange.from_values(26, 1, 27, 24)), |
||
177 | DocumentationComment( |
||
178 | ("super\n" |
||
179 | " nicely\n" |
||
180 | "short"), |
||
181 | docstyle_PYTHON3_default, "", |
||
182 | docstyle_PYTHON3_default.markers[0], |
||
183 | TextRange.from_values(40, 1, 42, 9))) |
||
184 | |||
185 | self.assertEqual( |
||
186 | tuple(extract_documentation(data, "PYTHON3", "default")), |
||
187 | expected) |
||
188 | |||
189 | # Change only the docstyle in expected results. |
||
190 | expected = list(DocumentationComment(r.documentation, |
||
191 | docstyle_PYTHON3_doxygen, |
||
192 | r.indent, |
||
193 | r.marker, |
||
194 | r.range) |
||
195 | for r in expected) |
||
196 | |||
197 | expected.insert(5, DocumentationComment( |
||
198 | (" Alternate documentation style in doxygen.\n" |
||
199 | " Subtext\n" |
||
200 | " More subtext (not correctly aligned)\n" |
||
201 | " sub-sub-text\n" |
||
202 | "\n"), |
||
203 | docstyle_PYTHON3_doxygen, "", |
||
204 | docstyle_PYTHON3_doxygen.markers[1], |
||
205 | TextRange.from_values(30, 1, 35, 1))) |
||
206 | |||
207 | self.assertEqual( |
||
208 | list(extract_documentation(data, "PYTHON3", "doxygen")), |
||
209 | expected) |
||
210 | |||
237 |