Test Failed
Push — master ( f337c2...a26c02 )
by Oliver
02:03
created

test_person.test_person_MoP()   A

Complexity

Conditions 1

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 38
rs 9.16
c 0
b 0
f 0
cc 1
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A test_person.test_person_AttrDisplay() 0 20 1
1
#!/usr/bin/env python
2
# test_person.py
3
"""Tests for `person` package."""
4
from dataclasses import dataclass
5
6
import pytest
7
from context import constants  # noqa
8
from context import helpers  # noqa
9
from context import person
10
11
# pylint: disable=redefined-outer-name
12
13
14
names = [
15
    ["Alfons-Reimund Horst Emil", "Boeselager"],
16
    ["Horatio R.", "Pimpernell"],
17
    ["Sven Jakob", "Große Brömer"],
18
]
19
20
21
def equivalent_names(n1, n2):
22
    fn = n2[0].split()[0]
23
    ln = n2[-1]
24
    try:
25
        mn_2 = n2[0].split()[2]
26
    except IndexError:
27
        mn_2 = None
28
    try:
29
        mn_1 = n2[0].split()[1]
30
    except IndexError:
31
        mn_1 = None
32
33
    return (
34
        (n1.first_name == fn)
35
        and (n1.middle_name_1 == mn_1)
36
        and (n1.middle_name_2 == mn_2)
37
        and (n1.last_name == ln)
38
    )
39
40
41
@pytest.mark.parametrize("n", names)
42
def test_person_Name_para(n):
43
    name = person.Name(*n)
44
    assert equivalent_names(name, n)
45
46
47
def test_person_Name(name_fixture):
48
    # pylint: disable=W0612, W0613
49
50
    name = person.Name("Alfons-Reimund Horst Emil", "Boeselager")
51
    assert name.first_name == "Alfons-Reimund"
52
    assert name.middle_name_1 == "Horst"
53
    assert name.middle_name_2 == "Emil"
54
    assert name.last_name == "Boeselager"
55
56
57
def test_person_Academic(academic_fixture):
58
    # pylint: disable=W0612, W0613
59
60
    academic = person.Academic(
61
        "Horatio",
62
        "Pimpernell",
63
        middle_name_1="R.",
64
        academic_title="Prof.Dr.   Dr",  # noqa
65
    )
66
    assert academic.first_name == "Horatio"
67
    assert academic.middle_name_1 == "R."
68
    assert academic.last_name == "Pimpernell"
69
    assert academic.academic_title == "Prof. Dr. Dr."
70
71
    academic = person.Academic(
72
        "Horatio Rübennase D.", "Pimpernell", academic_title="Prof.Dr.Dr"
73
    )
74
    assert academic.first_name == "Horatio"
75
    assert academic.middle_name_1 == "Rübennase"
76
    assert academic.middle_name_2 == "D."
77
    assert academic.last_name == "Pimpernell"
78
    assert academic.academic_title == "Prof. Dr. Dr."
79
80
    academic = person.Academic("Horatio", "Pimpernell", academic_title="B.A.")
81
    assert academic.academic_title == "B. A."
82
83
84
def test_person_Noble(noble_fixture):
85
    # pylint: disable=W0612, W0613
86
87
    noble = person.Noble("Sepp Theo", "Müller", peer_title="von und zu")
88
89
    assert noble.first_name == "Sepp"
90
    assert noble.middle_name_1 == "Theo"
91
    assert noble.last_name == "Müller"
92
    assert noble.peer_preposition == "von und zu"
93
94
    noble = person.Noble("Seppl", "Müller", peer_title="Junker van")
95
96
    assert noble.first_name == "Seppl"
97
    assert noble.last_name == "Müller"
98
    assert noble.peer_title == "Junker"
99
    assert noble.peer_preposition == "van"
100
101
    noble = person.Noble("Sven Oskar", "Müller", peer_title="Graf Eumel von")
102
103
    assert noble.first_name == "Sven"
104
    assert noble.middle_name_1 == "Oskar"
105
    assert noble.last_name == "Müller"
106
    assert noble.peer_title == "Graf"
107
    assert noble.peer_preposition == "von"
108
109
110
def test_person_Person(person_fixture):
111
    # pylint: disable=W0612, W0613
112
113
    pers = person.Person("Hugo", "Berserker", academic_title="MBA", born="2000")  # noqa
114
115
    assert pers.gender == "male"
116
    assert pers.academic_title == "MBA"
117
    assert pers.age == "20"
118
119
    pers = person.Person("Siggi Mathilde", "Berserker", born="1980-2010")
120
121
    assert pers.gender == "unknown"
122
    assert pers.middle_name_1 == "Mathilde"
123
    assert pers.born == "1980"
124
    assert pers.deceased == "2010"
125
126
    pers = person.Person("Sigrid", "Berserker", date_of_birth="10.1.1979")  # noqa
127
128
    assert pers.gender == "female"
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
229
    pol_5 = person.Politician(
230
        "Heiner", "Wiekeiner", "Linke", electoral_ward="Köln I"
231
    )  # noqa
232
233
    assert pol_5.ward_no == 13
234
    assert pol_5.voter_count == 121721
235
236
    pol_6 = person.Politician("Heiner", "Wiekeiner", "Grüne")
237
238
    assert pol_6.electoral_ward == "ew"
239
    assert pol_6.ward_no is None
240
    assert pol_6.voter_count is None
241
242
    pol_6.change_ward("Essen III")
243
244
    assert pol_6.electoral_ward == "Essen III"
245
    assert pol_6.ward_no == 67
246
    assert pol_6.voter_count == 104181
247
248
249
def test_person_TooManyFirstNames(toomanyfirstnames_fixture):
250
    # pylint: disable=W0612, W0613
251
252
    name = person.Name
253
    with pytest.raises(helpers.TooManyFirstNames):
254
        name("Alfons-Reimund Horst Emil Pupsi", "Schulze")
255
256
257
def test_person_AttrDisplay(capsys, attrdisplay_fixture):
258
    # pylint: disable=W0612, W0613
259
260
    @dataclass
261
    class MockClass(helpers.AttrDisplay):
262
        a: str
263
        b: str
264
        c: str
265
266
    var_1 = "späm"
267
    var_2 = "ham"
268
    var_3 = "ew"
269
270
    mock_instance = MockClass(var_1, var_2, var_3)
271
    print(mock_instance)
272
    captured = capsys.readouterr()
273
274
    expected = """MockClass:\na=späm\nb=ham\n\n"""
275
276
    assert expected == captured.out
277