Skip to content

Commit ee07916

Browse files
committed
Expand test coverage for errors
1 parent 98b4303 commit ee07916

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

tobac/analysis/spatial.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def calculate_distance(
109109
raise ValueError(
110110
"method_distance parameter must be provided if eithe hdim1_coord or hdim2_coord are specified"
111111
)
112+
113+
if method_distance not in [None, "xy", "latlon"]:
114+
raise ValueError("method_distance invalid, must be one of (None, 'xy', 'latlon')")
112115

113116
feature_1_coord = find_dataframe_horizontal_coords(
114117
feature_1,
@@ -148,8 +151,7 @@ def calculate_distance(
148151
feature_2[hdim1_coord],
149152
feature_2[hdim2_coord],
150153
)
151-
else:
152-
raise ValueError("method undefined")
154+
153155
return distance
154156

155157

tobac/tests/test_analysis_spatial.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def test_calculate_distance():
6565

6666

6767
def test_calculate_distance_errors():
68+
# Test invalid method_distance
69+
with pytest.raises(ValueError, match="method_distance invalid*"):
70+
calculate_distance(pd.DataFrame(), pd.DataFrame(), method_distance="invalid_method_distance")
71+
6872
# Test no horizontal coordinates"
6973
test_features = pd.DataFrame(
7074
{

tobac/tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from cycler import V
12
import pytest
23
import tobac.testing
34
import tobac.testing as tbtest
@@ -117,6 +118,10 @@ def test_get_indices_of_labels_from_reg_prop_dict():
117118
y_indices[index_key] < ny_2D
118119
)
119120

121+
# Test error if empty dict is passed:
122+
with pytest.raises(ValueError, match="No regions!"):
123+
tb_utils.get_indices_of_labels_from_reg_prop_dict({})
124+
120125

121126
@pytest.mark.parametrize(
122127
"feature_loc, min_max_coords, lengths, expected_coord_interp",

0 commit comments

Comments
 (0)