Skip to content

Commit e9221ac

Browse files
committed
start unit tests on new functions
1 parent 5c546e7 commit e9221ac

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

tests/waterdata_test.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from dataretrieval.waterdata import (
77
_check_profiles,
88
get_samples,
9+
get_daily,
10+
get_monitoring_locations,
11+
get_latest_continuous,
12+
get_field_measurements,
13+
get_time_series_metadata,
914
_SERVICES,
1015
_PROFILES
1116
)
@@ -105,3 +110,88 @@ def test_samples_organizations():
105110
)
106111
assert len(df) == 1
107112
assert df.size == 3
113+
114+
def test_get_daily():
115+
df = get_daily(
116+
monitoring_location_id="USGS-05427718",
117+
parameter_code="00060",
118+
time="2025-01-01/.."
119+
)
120+
assert "daily_id" in df.columns
121+
assert "geometry" in df.columns
122+
assert df.shape[1] == 12
123+
assert df.parameter_code.unique().tolist() == ["00060"]
124+
assert df.monitoring_location_id.unique().tolist() == ["USGS-05427718"]
125+
assert df["time"].apply(lambda x: isinstance(x, datetime.date)).all()
126+
assert df["value"].dtype == "float64"
127+
128+
def test_get_daily_properties():
129+
df = get_daily(
130+
monitoring_location_id="USGS-05427718",
131+
parameter_code="00060",
132+
time="2025-01-01/..",
133+
properties=["daily_id", "monitoring_location_id", "parameter_code", "time", "value", "geometry"]
134+
)
135+
assert "daily_id" in df.columns
136+
assert "geometry" in df.columns
137+
assert df.shape[1] == 6
138+
assert (df["time"] >= datetime.date(2025, 1, 1)).all()
139+
140+
def test_get_daily_no_geometry():
141+
df = get_daily(
142+
monitoring_location_id="USGS-05427718",
143+
parameter_code="00060",
144+
time="2025-01-01/..",
145+
skipGeometry=True
146+
)
147+
assert "geometry" not in df.columns
148+
assert df.shape[1] == 11
149+
assert isinstance(df, DataFrame)
150+
151+
def test_get_monitoring_locations():
152+
df = get_monitoring_locations(
153+
state_name="Connecticut",
154+
site_type_code="GW"
155+
)
156+
assert df.site_type_code.unique().tolist() == ["GW"]
157+
158+
def test_get_monitoring_locations_hucs():
159+
df = get_monitoring_locations(
160+
hydrologic_unit_code=["010802050102", "010802050103"]
161+
)
162+
assert set(df.hydrologic_unit_code.unique().tolist()) == {"010802050102", "010802050103"}
163+
164+
def test_get_latest_continuous():
165+
df = get_latest_continuous(
166+
monitoring_location_id=["USGS-05427718", "USGS-05427719"],
167+
parameter_code=["00060", "00065"]
168+
)
169+
assert df.shape[0] <= 4
170+
assert df.statistic_id.unique().tolist() == ["00011"]
171+
try:
172+
datetime.datetime.strptime(df['time'].iloc[0], "%Y-%m-%dT%H:%M:%S+00:00")
173+
out=True
174+
except:
175+
out=False
176+
assert out
177+
178+
def test_get_field_measurements():
179+
df = get_field_measurements(
180+
monitoring_location_id="USGS-05427718",
181+
unit_of_measure="ft^3/s",
182+
time="2025-01-01/2025-10-01",
183+
skipGeometry=True
184+
)
185+
assert "field_measurement_id" in df.columns
186+
assert "geometry" not in df.columns
187+
assert df.unit_of_measure.unique().tolist() == ["ft^3/s"]
188+
189+
def test_get_time_series_metadata():
190+
df = get_time_series_metadata(
191+
bbox=[-89.840355,42.853411,-88.818626,43.422598],
192+
parameter_code=["00060", "00065", "72019"],
193+
skipGeometry=True
194+
)
195+
assert set(df['parameter_name'].unique().tolist()) == {"Gage height", "Water level, depth LSD", "Discharge"}
196+
197+

0 commit comments

Comments
 (0)