Skip to content

Commit 35c1707

Browse files
LeSingh1NickGeneva
andauthored
test: add async fetch coverage for TimeWindow data source (#869)
* test: add async fetch coverage for TimeWindow data source * test: align TimeWindow async fetch coverage --------- Co-authored-by: Nicholas Geneva <5533524+NickGeneva@users.noreply.github.com>
1 parent ea4e1c2 commit 35c1707

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

test/data/test_time_window.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def __call__(self, time, variable):
8585
},
8686
)
8787

88+
async def fetch(self, time, variable):
89+
"""Mock async data fetch."""
90+
return self(time, variable)
91+
8892

8993
class TestTimeWindowInitialization:
9094
"""Test TimeWindow initialization and validation."""
@@ -357,6 +361,34 @@ def test_time_coordinate_alignment(self):
357361
assert len(result.time) == 1
358362
assert result.time.values[0] == np.datetime64(base_time)
359363

364+
@pytest.mark.asyncio
365+
async def test_fetch_matches_sync_output_coordinates(self):
366+
"""Test async fetch applies offsets and preserves output coordinates."""
367+
ds = MockDataSource()
368+
tw = TimeWindow(
369+
datasource=ds,
370+
offsets=[timedelta(hours=-6), timedelta(hours=0), timedelta(hours=6)],
371+
suffixes=["_tm1", "_t", "_tp1"],
372+
)
373+
374+
base_time = datetime(2024, 1, 1, 12, 0)
375+
result = await tw.fetch(base_time, ["t2m", "u10m"])
376+
377+
expected_vars = [
378+
"t2m_tm1",
379+
"t2m_t",
380+
"t2m_tp1",
381+
"u10m_tm1",
382+
"u10m_t",
383+
"u10m_tp1",
384+
]
385+
actual_vars = [str(v) for v in result.coords["variable"].values]
386+
assert actual_vars == expected_vars
387+
assert result.time.values[0] == np.datetime64(base_time)
388+
assert ds.call_history[0]["time"] == [datetime(2024, 1, 1, 6, 0)] # -6h
389+
assert ds.call_history[1]["time"] == [datetime(2024, 1, 1, 12, 0)] # 0h
390+
assert ds.call_history[2]["time"] == [datetime(2024, 1, 1, 18, 0)] # +6h
391+
360392

361393
class TestTimeWindowErrorHandling:
362394
"""Test error handling in TimeWindow."""

0 commit comments

Comments
 (0)