-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parser.py
105 lines (92 loc) · 3.49 KB
/
test_parser.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
import pytest
from project0 import parser
@pytest.fixture
def sample_unparsed_incidents():
return [('2/24/2022 1:05',
'2022-00010284',
'1306 168TH AVE NE',
'911 Call Nature Unknown',
'OK0140200'),
('2/24/2022 1:14',
'2022-00003461',
'700 S TELEPHONE RD',
'Transfer/Interfacility',
'EMSSTAT'),
('2/24/2022 2:09',
'2022-00010285',
'2320 W MAIN ST',
'Welfare Check',
'OK0140200'),
('2/24/2022 2:31',
'2022-00010286',
'CHAUTAUQUA AVE / W STATE HWY 9 HWY',
'Traffic Stop',
'OK0140200'),
('2/24/2022 8:20', '2022-00003471', '', '', 'EMSSTAT'),
('2/24/2022 18:01', '2022-00003507', '', '', 'EMSSTAT')]
def test_extract_incidents_should_return_a_list(
sample_unparsed_incidents):
got = parser.extract_incidents(sample_unparsed_incidents)
want = [
parser.Incident(
sample_unparsed_incidents[0][0],
sample_unparsed_incidents[0][1],
sample_unparsed_incidents[0][2],
sample_unparsed_incidents[0][3],
sample_unparsed_incidents[0][4]),
parser.Incident(
sample_unparsed_incidents[1][0],
sample_unparsed_incidents[1][1],
sample_unparsed_incidents[1][2],
sample_unparsed_incidents[1][3],
sample_unparsed_incidents[1][4]),
parser.Incident(
sample_unparsed_incidents[2][0],
sample_unparsed_incidents[2][1],
sample_unparsed_incidents[2][2],
sample_unparsed_incidents[2][3],
sample_unparsed_incidents[2][4]),
parser.Incident(
sample_unparsed_incidents[3][0],
sample_unparsed_incidents[3][1],
sample_unparsed_incidents[3][2],
sample_unparsed_incidents[3][3],
sample_unparsed_incidents[3][4]),
parser.Incident(
sample_unparsed_incidents[4][0],
sample_unparsed_incidents[4][1],
sample_unparsed_incidents[4][2],
sample_unparsed_incidents[4][3],
sample_unparsed_incidents[4][4]),
parser.Incident(
sample_unparsed_incidents[5][0],
sample_unparsed_incidents[5][1],
sample_unparsed_incidents[5][2],
sample_unparsed_incidents[5][3],
sample_unparsed_incidents[5][4]),
]
assert len(got) == 6
assert got == want
def test_incident_class():
raw = ('2/24/2022 1:05',
'2022-00010284',
'1306 168TH AVE NE',
'911 Call Nature Unknown',
'OK0140200')
incident = parser.Incident(raw[0], raw[1], raw[2], raw[3], raw[4])
# Testing __repr__()
got = incident.__repr__()
want = "%s(%r)" % (incident.__class__, incident.__dict__)
assert got == want
# Testing __str__()
got = incident.__str__()
want = f'Incident (\n\tDateTime: {incident.date_time}\n\tIncidentNumber: {incident.incident_number}\n\tLocation: {incident.location}\n\tNature: {incident.nature}\n\tIncidentORI: {incident.incident_ori}\n)'
assert got == want
# Testing __eq__ ( == )
got = incident
want = parser.Incident('2/24/2022 1:05',
'2022-00010284',
'1306 168TH AVE NE',
'911 Call Nature Unknown',
'OK0140200')
assert got == want