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