11import datetime
22import json
3+ from pathlib import Path
34from unittest import mock
45
56import numpy as np
2930
3031def _load_mock_json (file_name ):
3132 """Helper to load mock JSON from tests/data."""
32- with open (f"tests/data/{ file_name } " ) as f :
33+ path = Path (__file__ ).parent / "data" / file_name
34+ with open (path , encoding = "utf-8" ) as f :
3335 return json .load (f )
3436
3537
@@ -40,15 +42,15 @@ def _test_iv_service(requests_mock):
4042 service = "iv"
4143 site = ["03339000" , "05447500" , "03346500" ]
4244
43- # Minimal mock response
44- mock_url = (
45- "https://waterservices.usgs.gov/nwis/iv?format=json&"
46- f"startDT={ start } &endDT={ end } &sites=03339000%2C05447500%2C03346500"
47- )
4845 # We use a very simple JSON structure just to satisfy the parser
4946 mock_json = _load_mock_json ("nwis_iv_mock.json" )
5047
51- requests_mock .get (mock_url , json = mock_json )
48+ # Match the base URL and ensure query parameters are correct
49+ requests_mock .get (
50+ "https://waterservices.usgs.gov/nwis/iv" ,
51+ json = mock_json ,
52+ complete_qs = False ,
53+ )
5254
5355 return get_record (site , start , end , service = service )
5456
@@ -139,19 +141,19 @@ def test_get_water_use_raises(self):
139141 get_water_use ()
140142
141143 def test_get_record_defunct_service_measurements (self ):
142- with pytest .raises (NameError , match = "get_discharge_measurements " ):
144+ with pytest .raises (NameError , match = "no longer supported by get_record " ):
143145 get_record (service = "measurements" )
144146
145147 def test_get_record_defunct_service_gwlevels (self ):
146- with pytest .raises (NameError , match = "get_gwlevels " ):
148+ with pytest .raises (NameError , match = "no longer supported by get_record " ):
147149 get_record (service = "gwlevels" )
148150
149151 def test_get_record_defunct_service_pmcodes (self ):
150- with pytest .raises (NameError , match = "get_pmcodes " ):
152+ with pytest .raises (NameError , match = "no longer supported by get_record " ):
151153 get_record (service = "pmcodes" )
152154
153155 def test_get_record_defunct_service_water_use (self ):
154- with pytest .raises (NameError , match = "get_water_use " ):
156+ with pytest .raises (NameError , match = "no longer supported by get_record " ):
155157 get_record (service = "water_use" )
156158
157159
@@ -233,12 +235,13 @@ def test_empty_timeseries(requests_mock):
233235 start = "2010-07-20"
234236 end = "2010-07-20"
235237
236- mock_url = (
237- f"https://waterservices.usgs.gov/nwis/iv?format=json&"
238- f"startDT={ start } &endDT={ end } &sites={ sites } "
239- )
240238 mock_json = _load_mock_json ("nwis_iv_empty_mock.json" )
241- requests_mock .get (mock_url , json = mock_json )
239+ # Match the base URL and ensure query parameters are correct
240+ requests_mock .get (
241+ "https://waterservices.usgs.gov/nwis/iv" ,
242+ json = mock_json ,
243+ complete_qs = False ,
244+ )
242245
243246 df = get_record (sites = sites , service = "iv" , start = start , end = end )
244247 assert df .empty is True
0 commit comments