Skip to content

Commit

Permalink
[AC Spider] adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dehatanes committed Mar 13, 2022
1 parent 8d1bdaa commit 3dc625b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
Binary file added tests/data/AC/TO-2022-01-30.pdf
Binary file not shown.
Binary file added tests/data/AC/TO-2022-02-12.pdf
Binary file not shown.
24 changes: 24 additions & 0 deletions tests/data/AC/TO-2022-02-25.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
municipio,confirmados,mortes
Acrelândia,2.700,39
Assis Brasil,1.995,25
Brasileia,3.574,46
Bujari,1.588,17
Capixaba,848,17
Cruzeiro do Sul,10.724,184
Epitaciolândia,1.850,38
Feijó,3.747,67
Jordão,722,2
Mâncio Lima,3.070,36
Manoel Urbano,995,17
M. Thaumaturgo,1.613,13
Plácido de Castro,2.624,25
Porto Acre,2.044,42
Porto Walter,558,7
Rio Branco,60.653,1.161
Rodrigues Alves,1.040,14
Santa Rosa do Purus,1.164,7
Sena Madureira,6.995,86
Senador Guiomard,1.703,43
Tarauacá,7.001,50
Xapuri,3.361,33
TOTAL,120.569,1.969
Binary file added tests/data/AC/TO-2022-02-25.pdf
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/test_parser_acre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import csv
from pathlib import Path

from covid19br.parsers.acre import AcreBulletinExtractor


def sorted_dicts(data):
# Prepare dicts to be compared
return sorted(sorted((key, str(value)) for key, value in obj.items()) for obj in data)


def run_parser_asserts(pdf_filename, expected_official_total):
parser = AcreBulletinExtractor(pdf_filename)

assert parser.official_total == expected_official_total

expected_csv = pdf_filename.parent / pdf_filename.name.replace(".pdf", ".csv")
with open(expected_csv) as fobj:
expected_data = list(csv.DictReader(fobj))
data = list(parser.data)
assert sorted_dicts(expected_data) == sorted_dicts(data)


def test_01_pdf_with_ghost_objs_in_first_page():
parser = AcreBulletinExtractor(Path("tests/data/AC/TO-2022-01-30.pdf"))
assert parser.official_total == {"confirmados": "98.149", "mortes": "1.868"}
assert not list(parser.data)


def test_02_pdf_without_cities_table():
parser = AcreBulletinExtractor(Path("tests/data/AC/TO-2022-02-12.pdf"))
assert parser.official_total == {"confirmados": "110.430", "mortes": "1.917"}
assert not list(parser.data)


def test_03_pdf_with_cities_table():
run_parser_asserts(Path("tests/data/AC/TO-2022-02-25.pdf"), {"confirmados": "120.569", "mortes": "1.969"})

0 comments on commit 3dc625b

Please sign in to comment.