-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsearchers_test.py
297 lines (263 loc) · 10.6 KB
/
searchers_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
"""Serachers unit tests
"""
import pytest
import pandas as pd
@pytest.mark.parametrize(
"raw_html, clean_text",
[
("<div><a>Any text</a></div>", "Any text"),
("<div><div><p>Any text</a></div>", "Any text"),
("Any text</a></div>", "Any text"),
("Any text", "Any text"),
("<a></a>", ""),
("<></>", ""),
("", ""),
],
)
def test_clean_html(dou_searcher, raw_html, clean_text):
assert dou_searcher._clean_html(raw_html) == clean_text
@pytest.mark.parametrize(
"raw_html, start_name, match_name",
[
("PRIOR<>MATCHED NAME<>EVENTUALLY END NAME", "PRIOR", "MATCHED NAME"),
(
"JOSE<span class='highlight' style='background:#FFA;'>"
"ANTONIO DE OLIVEIRA</span>CAMARGO",
"JOSE",
"ANTONIO DE OLIVEIRA",
),
(
"<span class='highlight' style='background:#FFA;'>"
"ANTONIO DE OLIVEIRA</span>CAMARGO",
"",
"ANTONIO DE OLIVEIRA",
),
],
)
def test_get_prior_and_matched_name(dou_searcher, raw_html, start_name, match_name):
assert dou_searcher._get_prior_and_matched_name(raw_html) == (
start_name,
match_name,
)
@pytest.mark.parametrize(
"raw_text, normalized_text",
[
("Nitái Bêzêrrá", "nitai bezerra"),
("Nitái-Bêzêrrá", "nitai-bezerra"),
("Normaliza çedilha", "normaliza cedilha"),
("ìÌÒòùÙúÚáÁÀeççÇÇ~ A", "iioouuuuaaaecccc~ a"),
("a %&* / aáá 3d_U", "a %&* / aaa 3d_u"),
],
)
def test_normalize(dou_searcher, raw_text, normalized_text):
assert dou_searcher._normalize(raw_text) == normalized_text
@pytest.mark.parametrize(
"search_term, abstract",
[
(
"ANTONIO DE OLIVEIRA",
"<span class='highlight' style='background:#FFA;'>ANTONIO DE OLIVEIRA"
"</span> FREITAS - Diretor Geral.EXTRATO DE COMPROMISSO PRONAS/PCD: "
"Termo de Compromisso que entre si celebram a União, por intermédio "
"do Ministério da Saúde,...",
),
(
"ANTONIO DE OLIVEIRA",
"JOSÉ <span class='highlight' style='background:#FFA;'>ANTONIO DE "
"OLIVEIRA</span> FREITAS - Diretor Geral.EXTRATO DE COMPROMISSO "
"PRONAS/PCD: Termo de Compromisso que entre si celebram a União, "
"por intermédio do Ministério da Saúde,...",
),
("MATCHED NAME", "PRIOR<>MATCHED NAME<>EVENTUALLY END NAME"),
],
)
def test_is_signature(dou_searcher, search_term, abstract):
assert dou_searcher._is_signature(search_term, abstract)
@pytest.mark.parametrize(
"search_term, abstract",
[
(
"ANTONIO DE OLIVEIRA",
"<span class='highlight' style='background:#FFA;'>ANTONIO DE "
"OLIVEIRA</span> FREITAS - Diretor Geral.EXTRATO DE COMPROMISSO "
"PRONAS/PCD: Termo de Compromisso que entre si celebram a União, "
"por intermédio do Ministério da Saúde,...",
),
("MATCHED NAME", "PRIOR<>MATCHED NAME<>EVENTUALLY END NAME"),
("MATCHED NAME", "PRIOR MATCHED<> NAME<>EVENTUALLY END NAME"),
("MATCHED NAME", "PRIOR MATCHED<> NAME <>EVENTUALLY END NAME"),
("MATCHED NAME", "PRIOR MATCHED<> ... NAME<>EVENTUALLY END NAME"),
(
"ANTONIO DE OLIVEIRA",
"Secretário-Executivo Adjunto do Ministério da Saúde; <span>ANTONIO"
"</span> ... DE <span>OLIVEIRA</span> FREITAS JUNIOR - Diretor "
"Geral.EXTRATO DE COMPROMISSO PRONAS/PCD: Termo de ,...",
),
],
)
def test_really_matched(dou_searcher, search_term, abstract):
assert dou_searcher._really_matched(search_term, abstract)
def test_match_department(dou_searcher):
department = ["Ministério da Defesa"]
results = [
{
"section": "Seção 3",
"title": "EXTRATO DE COMPROMISSO",
"href": "https://www.in.gov.br/web/dou/-/extrato-de-compromisso-342504508",
"abstract": "ALESSANDRO GLAUCO DOS ANJOS DE VASCONCELOS - Secretário-Executivo Adjunto...",
"date": "02/09/2021",
"hierarchyList": [
"Ministério da Defesa",
"Comando do Exército",
"Comando Militar do Nordeste",
"6ª Região Militar",
"28º Batalhão de Caçadores",
],
},
{
"section": "Seção 3",
"title": "EXTRATO DE COMPROMISSO",
"href": "https://www.in.gov.br/web/dou/-/extrato-de-compromisso-342504508",
"abstract": "ALESSANDRO GLAUCO DOS ANJOS DE VASCONCELOS - Secretário-Executivo Adjunto...",
"date": "02/09/2021",
"hierarchyList": ["Ministério dos Povos Indígenas"],
},
]
dou_searcher._match_department(results, department)
assert len(results) == 1
def test_match_pubtype(dou_searcher):
pubtype = ["Edital"]
results = [
{
"section": "Seção 3",
"title": "EXTRATO DE COMPROMISSO",
"href": "https://www.in.gov.br/web/dou/-/extrato-de-compromisso-342504508",
"abstract": "ALESSANDRO GLAUCO DOS ANJOS DE VASCONCELOS - Secretário-Executivo Adjunto...",
"date": "02/09/2021",
"arttype": [
"Edital",
"Ata",
"Portaria",
],
},
{
"section": "Seção 3",
"title": "EXTRATO DE COMPROMISSO",
"href": "https://www.in.gov.br/web/dou/-/extrato-de-compromisso-342504508",
"abstract": "ALESSANDRO GLAUCO DOS ANJOS DE VASCONCELOS - Secretário-Executivo Adjunto...",
"date": "02/09/2021",
"arttype": ["Portaria"],
},
]
dou_searcher._match_pubtype(results, pubtype)
assert len(results) == 1
@pytest.mark.parametrize(
"pre_term_list, casted_term_list",
[
(
"""{
"servidor":{
"0":"ANTONIO",
"1":"JOSE",
"2":"SILVA"
},
"carreira":{
"0":"EPPGG",
"1":"ATI",
"2":"OIA"
}
}
""",
["ANTONIO", "JOSE", "SILVA"],
),
(
"""{
"tanto_faz":{
"0":"NITAI",
"1":"BEZERRA DA",
"2":"SILVA"
},
"o_nome_das_colunas":{
"0":"ESSE",
"1":"VALOR",
"2":"E IGNORADO"
}
}
""",
["NITAI", "BEZERRA DA", "SILVA"],
),
],
)
def test_cast_term_list__str_param(dou_searcher, pre_term_list, casted_term_list):
assert tuple(dou_searcher._cast_term_list(pre_term_list)) == tuple(casted_term_list)
def test_cast_term_list__list_param(dou_searcher):
pre_term_list = ["a", "b", "c"]
assert tuple(dou_searcher._cast_term_list(pre_term_list)) == tuple(pre_term_list)
def assert_grouped_term_result(grouped_result):
assert "ATI" in grouped_result
assert "SILVA" in grouped_result["ATI"]
assert len(grouped_result["ATI"]["SILVA"]) == 4
assert "EPPGG" in grouped_result
assert "ANTONIO DE OLIVEIRA" in grouped_result["EPPGG"]
assert len(grouped_result["EPPGG"]["ANTONIO DE OLIVEIRA"]) == 3
def assert_grouped_term_dept_result(grouped_result):
assert "ATI" in grouped_result
assert "SILVA" in grouped_result["ATI"]
assert len(grouped_result["ATI"]["SILVA"]["single_department"]) == 4
assert "EPPGG" in grouped_result
assert "ANTONIO DE OLIVEIRA" in grouped_result["EPPGG"]
assert len(grouped_result["EPPGG"]["ANTONIO DE OLIVEIRA"]["single_department"]) == 3
# TODO incluir teste com search_results vazio
def test_group_by_term_group(dou_searcher, search_results, term_n_group):
grouped_result = dou_searcher._group_by_term_group(search_results, term_n_group)
assert_grouped_term_result(grouped_result)
def test_group_by_department(dou_searcher, search_results):
grouped_result = dou_searcher._group_by_department(search_results, None)
assert "single_department" in grouped_result["ANTONIO DE OLIVEIRA"]
assert "single_department" in grouped_result["SILVA"]
assert len(grouped_result["SILVA"]["single_department"]) == 4
def test_group_results__sql_term_list_with_group(
dou_searcher, search_results, term_n_group
):
grouped_result = dou_searcher._group_results(search_results, term_n_group)
assert_grouped_term_dept_result(grouped_result)
def test_group_results__sql_term_list_without_group(dou_searcher, search_results):
terms_str = """{
"nomes":{
"0":"ANTONIO DE OLIVEIRA",
"1":"SILVA"}
}"""
grouped_result = dou_searcher._group_results(search_results, terms_str)
assert "ANTONIO DE OLIVEIRA" in grouped_result["single_group"]
assert "SILVA" in grouped_result["single_group"]
def test_group_results__list_term_list(dou_searcher, search_results):
any_list_object = []
grouped_result = dou_searcher._group_results(search_results, any_list_object)
assert "ANTONIO DE OLIVEIRA" in grouped_result["single_group"]
assert "SILVA" in grouped_result["single_group"]
def test_add_standard_highlight_formatting(dou_searcher):
results = [
{
"section": "DOU - Seção 1",
"title": "PORTARIA GM/MMA Nº 404, DE 14 DE MARÇO DE 2023",
"href": "https://www.in.gov.br/web/dou/-/"
"portaria-gm/mma-n-404-de-14-de-marco-de-2023-470057067",
"abstract": "As manifestações registradas na Plataforma Fala.BR versando "
"sobre a <span class='highlight' style='background:#FFA;'>"
"Lei</span> de <span class='highlight' style='background:"
"#FFA;'>Acesso à Informação</span> têm ritoPORTARIA GM/MMA "
"Nº 404, DE 14 DE MARÇO DE 2023 Estabelece, no âmbito do "
"Ministério do Meio Ambiente e Mudança do Clima, os "
"procedimentos para o recebimento e o "
"tratamento de manifestações...",
"date": "15/03/2023",
}
]
dou_searcher._add_standard_highlight_formatting(results)
assert results[0]["abstract"] == (
"As manifestações registradas na Plataforma Fala.BR versando sobre "
"a <%%>Lei</%%> de <%%>Acesso à Informação</%%> têm ritoPORTARIA "
"GM/MMA Nº 404, DE 14 DE MARÇO DE 2023 Estabelece, no âmbito do "
"Ministério do Meio Ambiente e Mudança do Clima, os procedimentos "
"para o recebimento e o tratamento de manifestações..."
)