-
Notifications
You must be signed in to change notification settings - Fork 13
/
tests.py
58 lines (47 loc) · 1.59 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
import re
import unittest
import subprocess
from srtm import get_elevation, get_file_name
'''
These elevation values were taken using gdallocationinfo command which is
a part of gdal-bin package. You can install it in Ubuntu (or derivatives)
using:
sudo apt-get install gdal-bin
'''
TEST_DATA = [
{
'name': 'Mt. Everest',
'lat': 27.988056,
'lon': 86.925278,
'filename': 'hgt/N27E086.hgt',
# gdallocationinfo N27E086.hgt -wgs84 86.925278 27.988056
'alt': 8840
},
{
'name': 'Mt. Kanchanjunga',
'lat': 27.7025,
'lon': 88.146667,
'filename': 'hgt/N27E088.hgt',
# gdallocationinfo N27E088.hgt -wgs84 88.146667 27.7025
'alt': 8464
}
]
def get_elevation_from_gdallocationinfo(filename, lat, lon):
output = subprocess.check_output([
'gdallocationinfo', filename, '-wgs84', str(lon), str(lat)
])
return int(re.search('Value: (\d+)', str(output)).group(1))
class TestSRTMMethods(unittest.TestCase):
def test_get_elevation(self):
for mountain in TEST_DATA:
elevation = get_elevation(mountain['lat'], mountain['lon'])
gdal_elevation = get_elevation_from_gdallocationinfo(
mountain['filename'], mountain['lat'], mountain['lon']
)
self.assertEqual(elevation, gdal_elevation)
def test_get_file_name(self):
for mountain in TEST_DATA:
filename = get_file_name(mountain['lat'], mountain['lon'])
self.assertEqual(filename, mountain['filename'])
if __name__ == '__main__':
unittest.main()