-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_get_wa_fire_data.py
More file actions
98 lines (84 loc) · 3.59 KB
/
test_get_wa_fire_data.py
File metadata and controls
98 lines (84 loc) · 3.59 KB
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
from datetime import date
from unittest import TestCase
import get_wa_fire_data
import utilities
from data_store import DataStore
class Test(TestCase):
def test_get_size(self):
f = None
self.assertEqual(0, get_wa_fire_data.get_size(f))
f = {}
self.assertEqual(0, get_wa_fire_data.get_size(f))
f = {"Acres":"40 Acres"}
self.assertEqual(40, get_wa_fire_data.get_size(f))
f = {"Acres":" ,"}
self.assertEqual(0, get_wa_fire_data.get_size(f))
f = {"Acres":" "}
self.assertEqual(0, get_wa_fire_data.get_size(f))
def test_get_containment(self):
f = None
self.assertEqual(0, get_wa_fire_data.get_containment(f))
f = {}
self.assertEqual(0, get_wa_fire_data.get_containment(f))
f = {"Percent Contained":"40%"}
self.assertEqual(40, get_wa_fire_data.get_containment(f))
f = {"Percent Contained":"40 %"}
self.assertEqual(40, get_wa_fire_data.get_containment(f))
f = {"Percent Contained":" "}
self.assertEqual(0, get_wa_fire_data.get_containment(f))
def test_get_value(self):
fn = lambda x: x.split()[0]
k = "Acres"
f = None
self.assertEqual(0, utilities.get_value(f, k, ",", fn))
f = {}
self.assertEqual(0, utilities.get_value(f, k, ",", fn))
f = {"Acres":"40 Acres"}
self.assertEqual(40, utilities.get_value(f, k, ",", fn))
f = {"Acres":" ,"}
self.assertEqual(0, utilities.get_value(f, k, ",", fn))
f = {"Acres":" "}
self.assertEqual(0, utilities.get_value(f, k, ",", fn))
f = {"Acres":" 10 "}
fn = lambda x: " " # Contorted edge case to make sure we get code coverage on a test.
self.assertEqual(0, utilities.get_value(f, k, ",", fn))
def test_summarize(self):
data_store = DataStore("data/data_wa")
# Just running it forces all data to be loaded and checked that it's valid.
summary = get_wa_fire_data.summarize(data_store)
print(summary)
def test_summary_no_yesterday(self):
# Check the 'only have one day of data' case. (no yesterday)
data_store = DataStore("data/data_test/data_wa")
# Just running it forces all data to be loaded and checked that it's valid.
summary = get_wa_fire_data.summarize(data_store)
print(summary)
def test_get_unique_id(self):
incident = {
'Incident Number': 1,
'Incident Name': "Name!"
}
self.assertEqual(1, get_wa_fire_data.get_unique_id(incident))
incident = {
'Incident Name': "Name!"
}
self.assertEqual("Name!", get_wa_fire_data.get_unique_id(incident))
incident = {}
with self.assertRaises(KeyError):
get_wa_fire_data.get_unique_id(incident)
def test_parse(self):
data = get_wa_fire_data.get_data_store().get_source_data(date(2021,6,27))
results = get_wa_fire_data.parse(data)
self.assertEqual(3, len(results))
self.assertEqual("6,679", results[0]["Acres"])
def test_get_annual_acres(self):
data_store = DataStore("data/data_test/data_wa")
# Should be no data in 2019, test for that.
days, totals = get_wa_fire_data.get_annual_acres(data_store, 2019)
self.assertEqual(0, len(days))
days, total = get_wa_fire_data.get_annual_acres(data_store, 2020)
self.assertEqual(1, len(days))
self.assertEqual(2020, days[0][0])
self.assertEqual(9, days[0][1])
self.assertEqual(12, days[0][2])
self.assertEqual(1530890, total)