Skip to content

Commit e81bfef

Browse files
committed
use gdallocationinfo to do tests
1 parent ce98e49 commit e81bfef

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import re
12
import unittest
3+
import subprocess
24
from srtm import get_elevation, get_file_name
35

46

@@ -29,17 +31,27 @@
2931
]
3032

3133

34+
def get_elevation_from_gdallocationinfo(filename, lat, lon):
35+
output = subprocess.check_output([
36+
'gdallocationinfo', filename, '-wgs84', str(lon), str(lat)
37+
])
38+
return int(re.search('Value: (\d+)', str(output)).group(1))
39+
40+
3241
class TestSRTMMethods(unittest.TestCase):
3342

3443
def test_get_elevation(self):
3544
for mountain in TEST_DATA:
3645
elevation = get_elevation(mountain['lat'], mountain['lon'])
37-
self.assertEquals(elevation, mountain['alt'])
46+
gdal_elevation = get_elevation_from_gdallocationinfo(
47+
mountain['filename'], mountain['lat'], mountain['lon']
48+
)
49+
self.assertEqual(elevation, gdal_elevation)
3850

3951
def test_get_file_name(self):
4052
for mountain in TEST_DATA:
4153
filename = get_file_name(mountain['lat'], mountain['lon'])
42-
self.assertEquals(filename, mountain['filename'])
54+
self.assertEqual(filename, mountain['filename'])
4355

4456

4557
if __name__ == '__main__':

0 commit comments

Comments
 (0)