| Conditions | 2 |
| Total Lines | 71 |
| Lines | 0 |
| Ratio | 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 os.path |
||
| 162 | def test_extract_documentation_PYTHON3(self): |
||
| 163 | data = DocumentationExtractionTest.load_testdata("data.py") |
||
| 164 | |||
| 165 | docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3", |
||
| 166 | "default") |
||
| 167 | docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3", |
||
| 168 | "doxygen") |
||
| 169 | |||
| 170 | expected = (DocumentationComment( |
||
| 171 | ("\n" |
||
| 172 | "Module description.\n" |
||
| 173 | "\n" |
||
| 174 | "Some more foobar-like text.\n"), |
||
| 175 | docstyle_PYTHON3_default, |
||
| 176 | docstyle_PYTHON3_default.markers[0], |
||
| 177 | TextRange.from_values(1, 1, 5, 4)), |
||
| 178 | DocumentationComment( |
||
| 179 | ("\n" |
||
| 180 | "A nice and neat way of documenting code.\n" |
||
| 181 | ":param radius: The explosion radius.\n"), |
||
| 182 | docstyle_PYTHON3_default, |
||
| 183 | docstyle_PYTHON3_default.markers[0], |
||
| 184 | TextRange.from_values(8, 5, 11, 8)), |
||
| 185 | DocumentationComment( |
||
| 186 | ("\n" |
||
| 187 | "Docstring with layouted text.\n" |
||
| 188 | "\n" |
||
| 189 | " layouts inside docs are preserved for these " |
||
| 190 | "documentation styles.\n" |
||
| 191 | "this is intended.\n"), |
||
| 192 | docstyle_PYTHON3_default, |
||
| 193 | docstyle_PYTHON3_default.markers[0], |
||
| 194 | TextRange.from_values(14, 1, 19, 4)), |
||
| 195 | DocumentationComment( |
||
| 196 | (" Docstring directly besides triple quotes.\n" |
||
| 197 | " Continues here. "), |
||
| 198 | docstyle_PYTHON3_default, |
||
| 199 | docstyle_PYTHON3_default.markers[0], |
||
| 200 | TextRange.from_values(21, 1, 22, 24)), |
||
| 201 | DocumentationComment( |
||
| 202 | ("super\n" |
||
| 203 | " nicely\n" |
||
| 204 | "short"), |
||
| 205 | docstyle_PYTHON3_default, |
||
| 206 | docstyle_PYTHON3_default.markers[0], |
||
| 207 | TextRange.from_values(35, 1, 37, 9))) |
||
| 208 | |||
| 209 | self.assertEqual( |
||
| 210 | tuple(extract_documentation(data, "PYTHON3", "default")), |
||
| 211 | expected) |
||
| 212 | |||
| 213 | # Change only the docstyle in expected results. |
||
| 214 | expected = list(DocumentationComment(r.documentation, |
||
| 215 | docstyle_PYTHON3_doxygen, |
||
| 216 | r.marker, |
||
| 217 | r.range) |
||
| 218 | for r in expected) |
||
| 219 | |||
| 220 | expected.insert(4, DocumentationComment( |
||
| 221 | (" Alternate documentation style in doxygen.\n" |
||
| 222 | " Subtext\n" |
||
| 223 | " More subtext (not correctly aligned)\n" |
||
| 224 | " sub-sub-text\n" |
||
| 225 | "\n"), |
||
| 226 | docstyle_PYTHON3_doxygen, |
||
| 227 | docstyle_PYTHON3_doxygen.markers[1], |
||
| 228 | TextRange.from_values(25, 1, 29, 3))) |
||
| 229 | |||
| 230 | self.assertEqual( |
||
| 231 | list(extract_documentation(data, "PYTHON3", "doxygen")), |
||
| 232 | expected) |
||
| 233 | |||
| 237 |