-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
68 lines (52 loc) · 1.6 KB
/
tests.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
##########################################################################
#
# Name: forecast.py
# Author: Harrison Hubbell
# Date: 06/15/2015
# Description: Make sure the module can propery query spots and
# handle spot_ids that are not valid.
#
##########################################################################
import inspect
import msw
from msw.spots.north_america import new_hampshire
def key():
with open('util/key') as f:
return f.read().strip()
def print_result(result):
current = inspect.currentframe()
caller = inspect.getouterframes(current, 2)
callframe = caller[1][3]
print('[{}]: {}'.format(callframe, "Pass" if result else "Fail"))
def test_valid_id(msw, spot_id):
ok = False
if msw.get(spot_id):
ok = True
print_result(ok)
return ok
def test_invalid_id(m, spot_id):
ok = False
try:
m.get(spot_id)
except msw.SpotDataUnavailableError:
# This is supposed to fail
ok = True
print_result(ok)
return ok
def test_forecast(m, spot_id):
ok = False
s = m.get(spot_id)
#test a bunch of things that should exist
ok = (s.forecast and
s.forecast[0] and
s.forecast[0].swell.components.combined.direction and
s.forecast[0].wind and
s.forecast[0].condition.pressure)
print_result(ok)
return ok
if __name__ == '__main__':
key = key()
m = msw.MagicSeaweed(key)
test_valid_id(m, new_hampshire.THE_WALL)
test_invalid_id(m, 2000)
test_forecast(m, new_hampshire.THE_WALL)