1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
# test_person.py |
4
|
|
|
"""Tests for `person` package.""" |
5
|
|
|
from dataclasses import dataclass |
6
|
|
|
|
7
|
|
|
import pytest |
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) # nosec |
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" # nosec |
52
|
|
|
assert name.middle_name_1 == "Horst" # nosec |
53
|
|
|
assert name.middle_name_2 == "Emil" # nosec |
54
|
|
|
assert name.last_name == "Boeselager" # nosec |
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" # nosec |
67
|
|
|
assert academic.middle_name_1 == "R." # nosec |
68
|
|
|
assert academic.last_name == "Pimpernell" # nosec |
69
|
|
|
assert academic.academic_title == "Prof. Dr. Dr." # nosec |
70
|
|
|
|
71
|
|
|
academic = person.Academic( |
72
|
|
|
"Horatio Rübennase D.", "Pimpernell", academic_title="Prof.Dr.Dr" |
73
|
|
|
) |
74
|
|
|
assert academic.first_name == "Horatio" # nosec |
75
|
|
|
assert academic.middle_name_1 == "Rübennase" # nosec |
76
|
|
|
assert academic.middle_name_2 == "D." # nosec |
77
|
|
|
assert academic.last_name == "Pimpernell" # nosec |
78
|
|
|
assert academic.academic_title == "Prof. Dr. Dr." # nosec |
79
|
|
|
|
80
|
|
|
academic = person.Academic("Horatio", "Pimpernell", academic_title="B.A.") |
81
|
|
|
assert academic.academic_title == "B. A." # nosec |
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" # nosec |
90
|
|
|
assert noble.middle_name_1 == "Theo" # nosec |
91
|
|
|
assert noble.last_name == "Müller" # nosec |
92
|
|
|
assert noble.peer_preposition == "von und zu" # nosec |
93
|
|
|
|
94
|
|
|
noble = person.Noble("Seppl", "Müller", peer_title="Junker van") |
95
|
|
|
|
96
|
|
|
assert noble.first_name == "Seppl" # nosec |
97
|
|
|
assert noble.last_name == "Müller" # nosec |
98
|
|
|
assert noble.peer_title == "Junker" # nosec |
99
|
|
|
assert noble.peer_preposition == "van" # nosec |
100
|
|
|
|
101
|
|
|
noble = person.Noble("Sven Oskar", "Müller", peer_title="Graf Eumel von") |
102
|
|
|
|
103
|
|
|
assert noble.first_name == "Sven" # nosec |
104
|
|
|
assert noble.middle_name_1 == "Oskar" # nosec |
105
|
|
|
assert noble.last_name == "Müller" # nosec |
106
|
|
|
assert noble.peer_title == "Graf" # nosec |
107
|
|
|
assert noble.peer_preposition == "von" # nosec |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
def test_person_Person(person_fixture): |
111
|
|
|
# pylint: disable=W0612, W0613 |
112
|
|
|
|
113
|
|
|
pers = person.Person( |
114
|
|
|
"Hugo", "Berserker", academic_title="MBA", date_of_birth="2000" |
115
|
|
|
) # noqa |
116
|
|
|
|
117
|
|
|
assert pers.gender == "male" # nosec |
118
|
|
|
assert pers.academic_title == "MBA" # nosec |
119
|
|
|
assert pers.age == "20" # nosec |
120
|
|
|
|
121
|
|
|
pers = person.Person( |
122
|
|
|
"Siggi Mathilde", "Berserker", date_of_birth="1980-2010" |
123
|
|
|
) # noqa |
124
|
|
|
|
125
|
|
|
assert pers.gender == "unknown" # nosec |
126
|
|
|
assert pers.middle_name_1 == "Mathilde" # nosec |
127
|
|
|
assert pers.year_of_birth == "1980" # nosec |
128
|
|
|
assert pers.deceased is True # nosec |
129
|
|
|
assert pers.year_of_death == "2010" # nosec |
130
|
|
|
|
131
|
|
|
pers = person.Person("Sigrid", "Berserker", date_of_birth="10.1.1979") # noqa |
132
|
|
|
|
133
|
|
|
assert pers.gender == "female" # nosec |
134
|
|
|
assert pers.year_of_birth == "1979" # nosec |
135
|
|
|
|
136
|
|
|
pers = person.Person( |
137
|
|
|
"Sigrid", "Berserker", date_of_birth="10.1.1979 - 22.10.2019" |
138
|
|
|
) # noqa |
139
|
|
|
|
140
|
|
|
assert pers.date_of_birth == "10.1.1979" # nosec |
141
|
|
|
assert pers.date_of_death == "22.10.2019" # nosec |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
def test_person_TooManyFirstNames(toomanyfirstnames_fixture): |
145
|
|
|
# pylint: disable=W0612, W0613 |
146
|
|
|
|
147
|
|
|
name = person.Name |
148
|
|
|
with pytest.raises(helpers.TooManyFirstNames): |
149
|
|
|
name("Alfons-Reimund Horst Emil Pupsi", "Schulze") |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
def test_person_AttrDisplay(capsys, attrdisplay_fixture): |
153
|
|
|
# pylint: disable=W0612, W0613 |
154
|
|
|
|
155
|
|
|
@dataclass |
156
|
|
|
class MockClass(helpers.AttrDisplay): |
157
|
|
|
a: str |
158
|
|
|
b: str |
159
|
|
|
c: str |
160
|
|
|
|
161
|
|
|
var_1 = "späm" |
162
|
|
|
var_2 = "ham" |
163
|
|
|
var_3 = "ew" |
164
|
|
|
|
165
|
|
|
mock_instance = MockClass(var_1, var_2, var_3) |
166
|
|
|
print(mock_instance) |
167
|
|
|
captured = capsys.readouterr() |
168
|
|
|
|
169
|
|
|
expected = """MockClass:\na=späm\nb=ham\n\n""" |
170
|
|
|
|
171
|
|
|
assert expected == captured.out # nosec |
172
|
|
|
|