From 2f210a420160db68c1c36981659dcbcc9736883a Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Tue, 19 May 2026 17:47:49 -0700 Subject: [PATCH 1/2] test: add async fetch coverage for TimeWindow data source --- test/data/test_time_window.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/data/test_time_window.py b/test/data/test_time_window.py index ad13a4d02..665ec4bbd 100644 --- a/test/data/test_time_window.py +++ b/test/data/test_time_window.py @@ -16,6 +16,7 @@ """Tests for TimeWindow data wrapper.""" +import asyncio from datetime import datetime, timedelta import numpy as np @@ -85,6 +86,10 @@ def __call__(self, time, variable): }, ) + async def fetch(self, time, variable): + """Mock async data fetch.""" + return self(time, variable) + class TestTimeWindowInitialization: """Test TimeWindow initialization and validation.""" @@ -357,6 +362,31 @@ def test_time_coordinate_alignment(self): assert len(result.time) == 1 assert result.time.values[0] == np.datetime64(base_time) + def test_fetch_matches_sync_output_coordinates(self): + """Test async fetch applies offsets and preserves output coordinates.""" + ds = MockDataSource() + tw = TimeWindow( + datasource=ds, + offsets=[timedelta(hours=-6), timedelta(hours=0), timedelta(hours=6)], + suffixes=["_tm1", "_t", "_tp1"], + ) + + base_time = datetime(2024, 1, 1, 12, 0) + result = asyncio.run(tw.fetch(base_time, ["t2m", "u10m"])) + + expected_vars = [ + "t2m_tm1", + "t2m_t", + "t2m_tp1", + "u10m_tm1", + "u10m_t", + "u10m_tp1", + ] + actual_vars = [str(v) for v in result.coords["variable"].values] + assert actual_vars == expected_vars + assert result.time.values[0] == np.datetime64(base_time) + assert ds.call_history[0]["time"] == [datetime(2024, 1, 1, 6, 0)] + class TestTimeWindowErrorHandling: """Test error handling in TimeWindow.""" From 105f12aebaa18cc92e4afa6f50ba6eb01ed38d6c Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Tue, 19 May 2026 18:09:00 -0700 Subject: [PATCH 2/2] test: align TimeWindow async fetch coverage --- test/data/test_time_window.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/data/test_time_window.py b/test/data/test_time_window.py index 665ec4bbd..1e18405e0 100644 --- a/test/data/test_time_window.py +++ b/test/data/test_time_window.py @@ -16,7 +16,6 @@ """Tests for TimeWindow data wrapper.""" -import asyncio from datetime import datetime, timedelta import numpy as np @@ -362,7 +361,8 @@ def test_time_coordinate_alignment(self): assert len(result.time) == 1 assert result.time.values[0] == np.datetime64(base_time) - def test_fetch_matches_sync_output_coordinates(self): + @pytest.mark.asyncio + async def test_fetch_matches_sync_output_coordinates(self): """Test async fetch applies offsets and preserves output coordinates.""" ds = MockDataSource() tw = TimeWindow( @@ -372,7 +372,7 @@ def test_fetch_matches_sync_output_coordinates(self): ) base_time = datetime(2024, 1, 1, 12, 0) - result = asyncio.run(tw.fetch(base_time, ["t2m", "u10m"])) + result = await tw.fetch(base_time, ["t2m", "u10m"]) expected_vars = [ "t2m_tm1", @@ -385,7 +385,9 @@ def test_fetch_matches_sync_output_coordinates(self): actual_vars = [str(v) for v in result.coords["variable"].values] assert actual_vars == expected_vars assert result.time.values[0] == np.datetime64(base_time) - assert ds.call_history[0]["time"] == [datetime(2024, 1, 1, 6, 0)] + assert ds.call_history[0]["time"] == [datetime(2024, 1, 1, 6, 0)] # -6h + assert ds.call_history[1]["time"] == [datetime(2024, 1, 1, 12, 0)] # 0h + assert ds.call_history[2]["time"] == [datetime(2024, 1, 1, 18, 0)] # +6h class TestTimeWindowErrorHandling: