| Conditions | 2 |
| Total Lines | 64 |
| 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 |
||
| 121 | def test_extract_documentation_PYTHON3(self): |
||
| 122 | data = DocumentationExtractionTest.load_testdata("data.py") |
||
| 123 | |||
| 124 | docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3", |
||
| 125 | "default") |
||
| 126 | docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3", |
||
| 127 | "doxygen") |
||
| 128 | |||
| 129 | expected = (DocumentationComment( |
||
| 130 | ("\n" |
||
| 131 | "Module description.\n" |
||
| 132 | "\n" |
||
| 133 | "Some more foobar-like text.\n"), |
||
| 134 | docstyle_PYTHON3_default.markers[0], |
||
| 135 | TextRange.from_values(1, 1, 5, 4)), |
||
| 136 | DocumentationComment( |
||
| 137 | ("\n" |
||
| 138 | "A nice and neat way of documenting code.\n" |
||
| 139 | ":param radius: The explosion radius.\n"), |
||
| 140 | docstyle_PYTHON3_default.markers[0], |
||
| 141 | TextRange.from_values(8, 5, 11, 8)), |
||
| 142 | DocumentationComment( |
||
| 143 | ("\n" |
||
| 144 | "Docstring with layouted text.\n" |
||
| 145 | "\n" |
||
| 146 | " layouts inside docs are preserved for these " |
||
| 147 | "documentation styles.\n" |
||
| 148 | "this is intended.\n"), |
||
| 149 | docstyle_PYTHON3_default.markers[0], |
||
| 150 | TextRange.from_values(14, 1, 19, 4)), |
||
| 151 | DocumentationComment( |
||
| 152 | (" Docstring directly besides triple quotes.\n" |
||
| 153 | " Continues here. "), |
||
| 154 | docstyle_PYTHON3_default.markers[0], |
||
| 155 | TextRange.from_values(21, 1, 22, 24)), |
||
| 156 | DocumentationComment( |
||
| 157 | ("super\n" |
||
| 158 | " nicely\n" |
||
| 159 | "short"), |
||
| 160 | docstyle_PYTHON3_default.markers[0], |
||
| 161 | TextRange.from_values(35, 1, 37, 9))) |
||
| 162 | |||
| 163 | self.assertEqual( |
||
| 164 | tuple(extract_documentation(data, "PYTHON3", "default")), |
||
| 165 | expected) |
||
| 166 | |||
| 167 | # Change only the docstyle in expected results. |
||
| 168 | expected = list(DocumentationComment(r.documentation, |
||
| 169 | r.marker, |
||
| 170 | r.range) |
||
| 171 | for r in expected) |
||
| 172 | |||
| 173 | expected.insert(4, DocumentationComment( |
||
| 174 | (" Alternate documentation style in doxygen.\n" |
||
| 175 | " Subtext\n" |
||
| 176 | " More subtext (not correctly aligned)\n" |
||
| 177 | " sub-sub-text\n" |
||
| 178 | "\n"), |
||
| 179 | docstyle_PYTHON3_doxygen.markers[1], |
||
| 180 | TextRange.from_values(25, 1, 30, 1))) |
||
| 181 | |||
| 182 | self.assertEqual( |
||
| 183 | list(extract_documentation(data, "PYTHON3", "doxygen")), |
||
| 184 | expected) |
||
| 185 | |||
| 189 |