Spaces:
Sleeping
Sleeping
rmm
commited on
Commit
·
9a93980
1
Parent(s):
3a350b3
test: added unit tests for decimal_coords converter
Browse files- tests/test_input_handling.py +54 -1
tests/test_input_handling.py
CHANGED
@@ -2,7 +2,7 @@ import pytest
|
|
2 |
from pathlib import Path
|
3 |
|
4 |
from input_handling import is_valid_email, is_valid_number
|
5 |
-
from input_handling import get_image_datetime, get_image_latlon
|
6 |
|
7 |
# generate tests for is_valid_email
|
8 |
# - test with valid email
|
@@ -153,3 +153,56 @@ def test_get_image_latlon():
|
|
153 |
def test_get_image_latlon_empty():
|
154 |
assert get_image_latlon("") == None
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from pathlib import Path
|
3 |
|
4 |
from input_handling import is_valid_email, is_valid_number
|
5 |
+
from input_handling import get_image_datetime, get_image_latlon, decimal_coords
|
6 |
|
7 |
# generate tests for is_valid_email
|
8 |
# - test with valid email
|
|
|
153 |
def test_get_image_latlon_empty():
|
154 |
assert get_image_latlon("") == None
|
155 |
|
156 |
+
# tests for decimal_coords
|
157 |
+
# - without input, py raises TypeError
|
158 |
+
# - with the wrong length of input (expecting 3 elements in the tuple), expect ValueError
|
159 |
+
# - with string inputs instead of numeric, we get a TypeError (should the func bother checking this? happens as built in)
|
160 |
+
# - with ref direction not in ['N', 'S', 'E', 'W'], expect ValueError, try X, x, NW.
|
161 |
+
# - with valid inputs, expect the correct output
|
162 |
+
|
163 |
+
|
164 |
+
# test data for decimal_coords: (deg,min,sec), ref, expected output
|
165 |
+
coords_conversion_data = [
|
166 |
+
((30, 1, 2), 'W', -30.01722222),
|
167 |
+
((30, 1, 2), 'E', 30.01722222),
|
168 |
+
((30, 1, 2), 'N', 30.01722222),
|
169 |
+
((30, 1, 2), 'S', -30.01722222),
|
170 |
+
((46, 31, 6.97), 'N', 46.51860278),
|
171 |
+
((6, 33, 43.47), 'E', 6.56207500)
|
172 |
+
]
|
173 |
+
@pytest.mark.parametrize("input_coords, ref, expected_output", coords_conversion_data)
|
174 |
+
def test_decimal_coords(input_coords, ref, expected_output):
|
175 |
+
assert decimal_coords(input_coords, ref) == pytest.approx(expected_output)
|
176 |
+
|
177 |
+
def test_decimal_coords_no_input():
|
178 |
+
with pytest.raises(TypeError):
|
179 |
+
decimal_coords()
|
180 |
+
|
181 |
+
def test_decimal_coords_wrong_length():
|
182 |
+
with pytest.raises(ValueError):
|
183 |
+
decimal_coords((1, 2), 'W')
|
184 |
+
|
185 |
+
with pytest.raises(ValueError):
|
186 |
+
decimal_coords((30,), 'W')
|
187 |
+
|
188 |
+
with pytest.raises(ValueError):
|
189 |
+
decimal_coords((30, 1, 2, 4), 'W')
|
190 |
+
|
191 |
+
def test_decimal_coords_non_numeric():
|
192 |
+
with pytest.raises(TypeError):
|
193 |
+
decimal_coords(('1', '2', '3'), 'W')
|
194 |
+
|
195 |
+
|
196 |
+
def test_decimal_coords_invalid_ref():
|
197 |
+
with pytest.raises(ValueError):
|
198 |
+
decimal_coords((30, 1, 2), 'X')
|
199 |
+
|
200 |
+
with pytest.raises(ValueError):
|
201 |
+
decimal_coords((30, 1, 2), 'x')
|
202 |
+
|
203 |
+
with pytest.raises(ValueError):
|
204 |
+
decimal_coords((30, 1, 2), 'NW')
|
205 |
+
|
206 |
+
|
207 |
+
|
208 |
+
|