Skip to content

Commit 7127924

Browse files
committed
add unit tests, correct issue with init file
1 parent 709450a commit 7127924

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

dataretrieval/waterdata/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
get_latest_daily,
2121
get_monitoring_locations,
2222
get_por_stats,
23+
get_reference_table,
2324
get_samples,
2425
get_time_series_metadata,
2526
)
@@ -40,6 +41,7 @@
4041
"get_latest_daily",
4142
"get_monitoring_locations",
4243
"get_por_stats",
44+
"get_reference_table",
4345
"get_samples",
4446
"get_time_series_metadata",
4547
"CODE_SERVICES",

tests/waterdata_test.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
get_latest_daily,
1717
get_field_measurements,
1818
get_time_series_metadata,
19-
get_reference_table
19+
get_reference_table,
20+
get_por_stats,
21+
get_date_range_stats
2022
)
2123

2224
def mock_request(requests_mock, request_url, file_path):
@@ -265,3 +267,47 @@ def test_get_reference_table_wrong_name():
265267
with pytest.raises(ValueError):
266268
get_reference_table("agency-cod")
267269

270+
def test_get_por_stats():
271+
df,_ = get_por_stats(
272+
monitoring_location_id="USGS-12451000",
273+
parameter_code="00060",
274+
start_date="01-01",
275+
end_date="01-01"
276+
)
277+
assert type(df) is DataFrame
278+
assert df['computation'].isin(['median', 'maximum', 'minimum', 'arithmetic_mean', 'percentile']).all()
279+
assert df['time_of_year'].isin(['01-01', '01']).all()
280+
assert df.loc[df['computation'] == "minimum", "percentile"].unique().tolist() == [0.0]
281+
assert df.loc[df['computation'] == "arithmetic_mean", "percentile"].isnull().all()
282+
283+
def test_get_por_stats_expanded_false():
284+
df,_ = get_por_stats(
285+
monitoring_location_id="USGS-12451000",
286+
parameter_code="00060",
287+
start_date="01-01",
288+
end_date="01-01",
289+
expand_percentiles=False,
290+
computation_type=["minimum", "percentile"]
291+
)
292+
assert df.shape[0] == 4
293+
assert df.shape[1] == 21
294+
assert "percentile" not in df.columns
295+
assert "percentiles" in df.columns
296+
assert type(df['percentiles'][2]) is list
297+
assert df.loc[~df['percentiles'].isna(), "value"].isnull().all()
298+
299+
def test_get_date_range_stats():
300+
df,_ = get_date_range_stats(
301+
monitoring_location_id="USGS-12451000",
302+
parameter_code="00060",
303+
start_date="2025-01-01",
304+
end_date="2025-01-01",
305+
computation_type="maximum"
306+
)
307+
308+
assert df.shape[0] == 3
309+
assert df.shape[1] == 21
310+
assert "interval_type" in df.columns
311+
assert "percentile" in df.columns
312+
assert df['interval_type'].isin(['month', 'calendar_year', 'water_year']).all()
313+

0 commit comments

Comments
 (0)