| Conditions | 2 |
| Total Lines | 99 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | #!/usr/bin/env python |
||
| 129 | assert pers.born == "1979" |
||
| 130 | |||
| 131 | |||
| 132 | def test_person_Politician(politician_fixture): |
||
| 133 | # pylint: disable=W0612, W0613 |
||
| 134 | |||
| 135 | pol_1 = person.Politician( |
||
| 136 | "Regina", |
||
| 137 | "Dinther", |
||
| 138 | "CDU", |
||
| 139 | peer_title="van", |
||
| 140 | electoral_ward="Rhein-Sieg-Kreis IV", |
||
| 141 | ) |
||
| 142 | |||
| 143 | assert pol_1.first_name == "Regina" |
||
| 144 | assert pol_1.last_name == "Dinther" |
||
| 145 | assert pol_1.gender == "female" |
||
| 146 | assert pol_1.peer_preposition == "van" |
||
| 147 | assert pol_1.party_name == "CDU" |
||
| 148 | assert pol_1.ward_no == 28 |
||
| 149 | assert pol_1.voter_count == 110389 |
||
| 150 | |||
| 151 | pol_1.party_name = "fraktionslos" |
||
| 152 | assert pol_1.party_name == "fraktionslos" |
||
| 153 | assert pol_1.parties == [ |
||
| 154 | helpers.Party( |
||
| 155 | party_name="CDU", party_entry="unknown", party_exit="unknown" |
||
| 156 | ) # noqa |
||
| 157 | ] # noqa |
||
| 158 | |||
| 159 | pol_2 = person.Politician( |
||
| 160 | "Regina", |
||
| 161 | "Dinther", |
||
| 162 | "CDU", |
||
| 163 | electoral_ward="Landesliste", |
||
| 164 | ) # noqa |
||
| 165 | |||
| 166 | assert pol_2.electoral_ward == "ew" |
||
| 167 | |||
| 168 | pol_3 = person.Politician( |
||
| 169 | "Heiner", "Wiekeiner", "Piraten", electoral_ward="Kreis Aachen I" |
||
| 170 | ) # noqa |
||
| 171 | |||
| 172 | assert pol_3.voter_count == 116389 |
||
| 173 | |||
| 174 | with pytest.raises(helpers.NotGermanParty): |
||
| 175 | pol_4 = person.Politician("Thomas", "Gschwindner", "not_a_German_party") # noqa |
||
| 176 | |||
| 177 | pol_4 = person.Politician("Thomas", "Gschwindner", "FDP") |
||
| 178 | pol_4.add_Party("FDP") |
||
| 179 | |||
| 180 | assert pol_4.party_name == "FDP" |
||
| 181 | assert pol_4.parties == [ |
||
| 182 | helpers.Party( |
||
| 183 | party_name="FDP", party_entry="unknown", party_exit="unknown" |
||
| 184 | ) # noqa |
||
| 185 | ] # noqa |
||
| 186 | |||
| 187 | pol_4.add_Party("not_a_German_party") |
||
| 188 | |||
| 189 | assert pol_4.party_name == "FDP" |
||
| 190 | assert pol_4.parties == [ |
||
| 191 | helpers.Party( |
||
| 192 | party_name="FDP", party_entry="unknown", party_exit="unknown" |
||
| 193 | ) # noqa |
||
| 194 | ] # noqa |
||
| 195 | |||
| 196 | pol_4.add_Party("AfD") |
||
| 197 | |||
| 198 | assert pol_4.parties == [ |
||
| 199 | helpers.Party( |
||
| 200 | party_name="FDP", party_entry="unknown", party_exit="unknown" |
||
| 201 | ), # noqa |
||
| 202 | helpers.Party( |
||
| 203 | party_name="AfD", party_entry="unknown", party_exit="unknown" |
||
| 204 | ), # noqa |
||
| 205 | ] |
||
| 206 | |||
| 207 | pol_4.add_Party("AfD", party_entry="2019") |
||
| 208 | |||
| 209 | assert pol_4.party_entry == "2019" |
||
| 210 | assert pol_4.parties == [ |
||
| 211 | helpers.Party( |
||
| 212 | party_name="FDP", party_entry="unknown", party_exit="unknown" |
||
| 213 | ), # noqa |
||
| 214 | helpers.Party( |
||
| 215 | party_name="AfD", party_entry="2019", party_exit="unknown" |
||
| 216 | ), # noqa |
||
| 217 | ] |
||
| 218 | |||
| 219 | pol_4.add_Party("AfD", party_entry="2019", party_exit="2020") |
||
| 220 | |||
| 221 | assert pol_4.party_exit == "2020" |
||
| 222 | assert pol_4.parties == [ |
||
| 223 | helpers.Party( |
||
| 224 | party_name="FDP", party_entry="unknown", party_exit="unknown" |
||
| 225 | ), # noqa |
||
| 226 | helpers.Party(party_name="AfD", party_entry="2019", party_exit="2020"), |
||
| 227 | ] |
||
| 228 | |||
| 327 |