@@ -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
8993class 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
361393class TestTimeWindowErrorHandling :
362394 """Test error handling in TimeWindow."""
0 commit comments