Skip to content

Commit f14d5f0

Browse files
committed
Update tests
1 parent 9c4b51e commit f14d5f0

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

climada/util/test/test_coordinates.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,29 @@ class TestFunc(unittest.TestCase):
392392
def test_check_geo_coords(self):
393393
"""Test the check_if_geo_coords function"""
394394
# test correct geographical coords
395-
lat, lon = np.array([0, -2, 5]), np.array([-179, 175, 178])
396-
self.assertEqual(u_coord.check_if_geo_coords(lat, lon), True)
397-
# test wrong lat
398-
lat, lon = np.array([0, 200, 5]), np.array([-179, 175, 178])
399-
self.assertEqual(u_coord.check_if_geo_coords(lat, lon), False)
400-
# test wrong lon
401-
lat, lon = np.array([0, -2, 5]), np.array([-400, 175, 176])
402-
self.assertEqual(u_coord.check_if_geo_coords(lat, lon), False)
403-
lat, lon = np.array([0, -2, 5]), np.array([700, 1000, 800])
404-
self.assertEqual(u_coord.check_if_geo_coords(lat, lon), False)
405-
# test wrong extent
406-
lat, lon = np.array([0, -2, 5]), np.array([-179, 175, 370])
407-
self.assertEqual(u_coord.check_if_geo_coords(lat, lon), False)
395+
lats_lons_true = (np.array([0, -2, 5]), np.array([-179, 175, 178]))
396+
u_coord.check_if_geo_coords(lats_lons_true[0], lats_lons_true[1])
397+
398+
# test wrong geographical coords
399+
lats_lons_wrong = (
400+
(np.array([0, 200, 5]), np.array([-179, 175, 178])), # test wrong lat
401+
(np.array([0, -2, 5]), np.array([-400, 175, 176])), # test wrong lon
402+
(np.array([0, -2, 5]), np.array([700, 1000, 800])),
403+
(np.array([0, -2, 5]), np.array([-179, 175, 370])), # test wrong extent
404+
)
405+
406+
for ilat, ilon in lats_lons_wrong:
407+
with self.assertRaises(ValueError) as cm:
408+
u_coord.check_if_geo_coords(ilat, ilon)
409+
self.assertIn(
410+
"Input lat and lon coordinates do not seem to correspond"
411+
" to geographic coordinates in degrees. This can be because"
412+
" total extents are > 180 for lat or > 360 for lon, lat coordinates"
413+
" are outside of -90<lat<90, or lon coordinates are outside of -540<lon<540."
414+
" If you use degree values outside of these ranges,"
415+
" please shift the coordinates to the valid ranges.",
416+
str(cm.exception),
417+
)
408418

409419
def test_lon_normalize(self):
410420
"""Test the longitude normalization function"""

0 commit comments

Comments
 (0)