Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 0 additions & 46 deletions tests/data/nwis_site_seriescatalog.txt

This file was deleted.

86 changes: 1 addition & 85 deletions tests/nwis_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import json
import re
import warnings
Expand All @@ -14,14 +13,12 @@
_read_rdb,
get_discharge_measurements,
get_gwlevels,
get_info,
get_iv,
get_pmcodes,
get_qwdata,
get_record,
get_water_use,
preformat_peaks_response,
what_sites,
)

START_DATE = "2018-01-24"
Expand All @@ -30,9 +27,8 @@
DATETIME_COL = "datetime"
SITENO_COL = "site_no"

# Legacy NWIS endpoints these tests mock — this module makes no live calls.
# Legacy NWIS site endpoint these tests mock — this module makes no live calls.
_SITE_RE = re.compile(r"^https://waterservices\.usgs\.gov/nwis/site(\?.*)?$")
_IV_RE = re.compile(r"^https://waterservices\.usgs\.gov/nwis/iv(\?.*)?$")


def _load_mock_json(file_name):
Expand Down Expand Up @@ -223,86 +219,6 @@ def test_get_record_defunct_service_water_use(self):
get_record(service="water_use")


class TestTZ:
"""Tests relating to GitHub Issue #60 — merging IV results across sites
yields a proper datetime index. Mocked against fixture responses."""

def _mock(self, httpx_mock):
_mock_site(httpx_mock)
httpx_mock.add_response(
method="GET", url=_IV_RE, json=_load_mock_json("nwis_iv_mock.json")
)

def test_multiple_tz_01(self, httpx_mock):
"""Issue #60 - merging IV across sites yields a datetime index."""
self._mock(httpx_mock)
sites, _ = what_sites(stateCd="MD")
iv, _ = get_iv(sites=sites.site_no.values[:25].tolist())
assert "datetime" in iv.index.names
assert isinstance(iv.index[0][1], datetime.datetime)

def test_multiple_tz_02(self, httpx_mock):
"""Issue #60 - the same-tz path also yields a datetime index."""
self._mock(httpx_mock)
sites, _ = what_sites(stateCd="MD")
iv, _ = get_iv(sites=sites.site_no.values[:20].tolist())
assert "datetime" in iv.index.names
assert isinstance(iv.index[0][1], datetime.datetime)


class TestSiteseriesCatalogOutput:
"""Tests relating to GitHub Issue #34 — ``seriesCatalogOutput`` adds the
data-inventory columns (begin_date / end_date / count_nu). Mocked against
fixture responses (the chosen fixture, not the request param, decides which
columns come back)."""

_SERIESCATALOG = "nwis_site_seriescatalog.txt"

def test_seriesCatalogOutput_get_record(self, httpx_mock):
"""seriesCatalogOutput=True with get_record exposes inventory columns."""
_mock_site(httpx_mock, self._SERIESCATALOG)
data = get_record(
huc="20", parameterCd="00060", service="site", seriesCatalogOutput="True"
)
assert "begin_date" in data.columns
assert "end_date" in data.columns
assert "count_nu" in data.columns

def test_seriesCatalogOutput_get_info(self, httpx_mock):
"""seriesCatalogOutput=TRUE with get_info exposes inventory columns."""
_mock_site(httpx_mock, self._SERIESCATALOG)
data, _ = get_info(huc="20", parameterCd="00060", seriesCatalogOutput="TRUE")
assert "begin_date" in data.columns
assert "end_date" in data.columns
assert "count_nu" in data.columns

def test_seriesCatalogOutput_bool(self, httpx_mock):
"""A boolean seriesCatalogOutput is accepted and exposes inventory cols."""
_mock_site(httpx_mock, self._SERIESCATALOG)
data, _ = get_info(huc="20", parameterCd="00060", seriesCatalogOutput=True)
assert "begin_date" in data.columns
assert "end_date" in data.columns
assert "count_nu" in data.columns

def test_expandedrdb_get_record(self, httpx_mock):
"""The default expanded-rdb format omits the inventory columns."""
_mock_site(httpx_mock)
data = get_record(
huc="20", parameterCd="00060", service="site", seriesCatalogOutput="False"
)
assert "begin_date" not in data.columns
assert "end_date" not in data.columns
assert "count_nu" not in data.columns

def test_expandedrdb_get_info(self, httpx_mock):
"""get_info default omits the inventory columns."""
_mock_site(httpx_mock)
data, _ = get_info(huc="20", parameterCd="00060")
assert "begin_date" not in data.columns
assert "end_date" not in data.columns
assert "count_nu" not in data.columns


def test_empty_timeseries(httpx_mock):
"""Test based on empty case from GitHub Issue #26."""
sites = "011277906"
Expand Down
16 changes: 0 additions & 16 deletions tests/waterdata_filters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,6 @@ def test_quote_cql_str_doubles_embedded_quotes():
assert _quote_cql_str("a'b'c") == "a''b''c"


def test_construct_filter_passthrough():
"""`filter` is forwarded verbatim as a query parameter."""
expr = (
"(time >= '2023-01-06T16:00:00Z' AND time <= '2023-01-06T18:00:00Z') "
"OR (time >= '2023-01-10T18:00:00Z' AND time <= '2023-01-10T20:00:00Z')"
)
req = _construct_api_requests(
service="continuous",
monitoring_location_id="USGS-07374525",
parameter_code="72255",
filter=expr,
)
qs = _query_params(req)
assert qs["filter"] == [expr]


def test_construct_filter_lang_hyphenated():
"""The Python kwarg `filter_lang` is sent as URL key `filter-lang`."""
req = _construct_api_requests(
Expand Down