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