-
Notifications
You must be signed in to change notification settings - Fork 529
/
test_util_flinnengdahl.py
44 lines (37 loc) · 1.5 KB
/
test_util_flinnengdahl.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from obspy.scripts.flinnengdahl import main as obspy_flinnengdahl
from obspy.geodetics import FlinnEngdahl
from obspy.core.util.misc import CatchOutput
class TestUtilFlinnEngdahl:
def test_coordinates(self, testdata):
with open(testdata['flinnengdahl.csv'], 'r') as fh:
for line in fh:
longitude, latitude, checked_region = line.strip().split('\t')
longitude = float(longitude)
latitude = float(latitude)
region = FlinnEngdahl().get_region(longitude, latitude)
assert region == \
checked_region, \
"(%f, %f) got %s instead of %s" % (
longitude,
latitude,
region,
checked_region
)
def test_script(self, testdata):
with open(testdata['flinnengdahl.csv'], 'r') as fh:
# Testing once is sufficient.
line = fh.readline()
longitude, latitude, checked_region = line.strip().split('\t')
with CatchOutput() as out:
obspy_flinnengdahl([longitude, latitude])
region = out.stdout.strip()
assert region == \
checked_region, \
'(%s, %s) got %s instead of %s' % (
longitude,
latitude,
region,
checked_region
)