@@ -253,10 +253,11 @@ def test_generate_gdds_get_time_slice_lists(self):
253253 self .assertEqual (h1_slices , expected_h1 )
254254
255255 # Check h2 slices (daily timesteps - full year)
256+ # For daily, starts at first_season (1986), not first_season + 1
256257 expected_h2 = [
258+ slice ("1986-01-02" , "1987-01-01" ),
257259 slice ("1987-01-02" , "1988-01-01" ),
258260 slice ("1988-01-02" , "1989-01-01" ),
259- slice ("1989-01-02" , "1990-01-01" ),
260261 ]
261262 self .assertEqual (h2_slices , expected_h2 )
262263
@@ -272,9 +273,10 @@ def test_generate_gdds_get_time_slice_lists_1yr(self):
272273 self .assertEqual (h1_slices , expected_h1 )
273274
274275 # Check h2 slices
276+ # For daily, starts at first_season (1987), not first_season + 1
275277 expected_h2 = [
278+ slice ("1987-01-02" , "1988-01-01" ),
276279 slice ("1988-01-02" , "1989-01-01" ),
277- slice ("1989-01-02" , "1990-01-01" ),
278280 ]
279281 self .assertEqual (h2_slices , expected_h2 )
280282
@@ -324,6 +326,51 @@ def test_generate_gdds_get_time_slice_lists_h2_year_long(self):
324326 self .assertEqual (stop_year , start_year + 1 )
325327
326328
329+ class TestGetHistoryYrRange (unittest .TestCase ):
330+ """Tests for _get_history_yr_range()"""
331+
332+ def test_get_history_yr_range_annual (self ):
333+ """Test _get_history_yr_range with annual frequency"""
334+ result = gg ._get_history_yr_range (1986 , 1987 , "annual" )
335+ # For annual: first_season + 1 through last_season + 2
336+ expected = range (1987 , 1990 )
337+ self .assertEqual (result , expected )
338+
339+ def test_get_history_yr_range_daily (self ):
340+ """Test _get_history_yr_range with daily frequency"""
341+ result = gg ._get_history_yr_range (1986 , 1987 , "daily" )
342+ # For daily: first_season through last_season + 1
343+ expected = range (1986 , 1989 )
344+ self .assertEqual (result , expected )
345+
346+ def test_get_history_yr_range_annual_single_year (self ):
347+ """Test _get_history_yr_range with annual frequency and single year"""
348+ result = gg ._get_history_yr_range (2000 , 2000 , "annual" )
349+ # Should give 2001, 2002
350+ expected = range (2001 , 2003 )
351+ self .assertEqual (result , expected )
352+
353+ def test_get_history_yr_range_daily_single_year (self ):
354+ """Test _get_history_yr_range with daily frequency and single year"""
355+ result = gg ._get_history_yr_range (2000 , 2000 , "daily" )
356+ # Should give 2000, 2001
357+ expected = range (2000 , 2002 )
358+ self .assertEqual (result , expected )
359+
360+ def test_get_history_yr_range_unknown_freq (self ):
361+ """Test _get_history_yr_range with unknown frequency"""
362+ with self .assertRaises (NotImplementedError ):
363+ gg ._get_history_yr_range (2000 , 2001 , "monthly" )
364+
365+ def test_get_history_yr_range_lengths_match (self ):
366+ """Test that annual and daily ranges have the same length"""
367+ annual_range = gg ._get_history_yr_range (2000 , 2005 , "annual" )
368+ daily_range = gg ._get_history_yr_range (2000 , 2005 , "daily" )
369+ self .assertEqual (len (annual_range ), len (daily_range ))
370+ # Should be last_season - first_season + 2
371+ self .assertEqual (len (annual_range ), 2005 - 2000 + 2 )
372+
373+
327374class TestCheckGridMatch (unittest .TestCase ):
328375 """Tests check_grid_match()"""
329376
@@ -617,14 +664,14 @@ def _create_test_file(self, filename):
617664 def test_get_file_lists_single_year (self ):
618665 """Test _get_file_lists with a single year of data"""
619666 # Create h1 and h2 files for 2000 and 2001
620- # (first_season=1999, last_season=1999 will request slices for both years)
667+ # Also need h2 file for 1999 since daily starts at first_season
668+ h2_file_1999 = self ._create_test_file ("test.clm2.h2i.1999-01-02-00000.nc" )
621669 h1_file_2000 = self ._create_test_file ("test.clm2.h1i.2000-01-01-00000.nc" )
622670 h2_file_2000 = self ._create_test_file ("test.clm2.h2i.2000-01-02-00000.nc" )
623671 h1_file_2001 = self ._create_test_file ("test.clm2.h1i.2001-01-01-00000.nc" )
624- h2_file_2001 = self ._create_test_file ("test.clm2.h2i.2001-01-02-00000.nc" )
625672
626673 # Get time slice lists for first_season=1999, last_season=1999
627- # This will give us slices for 2000 and 2001
674+ # This will give us slices for 2000 and 2001 (h1), and 1999, 2000, 2001 (h2)
628675 time_slice_lists_list = gg ._get_time_slice_lists (1999 , 1999 )
629676
630677 h1_file_lists , h2_file_lists = gg ._get_file_lists (
@@ -640,23 +687,24 @@ def test_get_file_lists_single_year(self):
640687 self .assertEqual (len (h1_file_lists [0 ]), 1 )
641688 self .assertEqual (h1_file_lists [0 ], [h1_file_2000 ])
642689 self .assertEqual (len (h2_file_lists [0 ]), 1 )
643- self .assertEqual (h2_file_lists [0 ], [h2_file_2000 ])
690+ self .assertEqual (h2_file_lists [0 ], [h2_file_1999 ])
644691 self .assertEqual (len (h1_file_lists [1 ]), 1 )
645692 self .assertEqual (h1_file_lists [1 ], [h1_file_2001 ])
646693 self .assertEqual (len (h2_file_lists [1 ]), 1 )
647- self .assertEqual (h2_file_lists [1 ], [h2_file_2001 ])
694+ self .assertEqual (h2_file_lists [1 ], [h2_file_2000 ])
648695
649696 def test_get_file_lists_multiple_years (self ):
650697 """Test _get_file_lists with multiple years of data"""
651698 # Create h1 and h2 files for 2000-2002
699+ # Also need h2 file for 1999 since daily starts at first_season
652700 h1_files = []
653- h2_files = []
701+ h2_files = [self . _create_test_file ( "test.clm2.h2i.1999-01-02-00000.nc" ) ]
654702 for year in [2000 , 2001 , 2002 ]:
655703 h1_files .append (self ._create_test_file (f"test.clm2.h1i.{ year } -01-01-00000.nc" ))
656704 h2_files .append (self ._create_test_file (f"test.clm2.h2i.{ year } -01-02-00000.nc" ))
657705
658706 # Get time slice lists for first_season=1999, last_season=2000
659- # This will give us slices for 2000, 2001, 2002
707+ # This will give us slices for 2000, 2001, 2002 (h1) and 1999, 2000, 2001 (h2)
660708 time_slice_lists_list = gg ._get_time_slice_lists (1999 , 2000 )
661709
662710 h1_file_lists , h2_file_lists = gg ._get_file_lists (
@@ -681,14 +729,15 @@ def test_get_file_lists_multiple_files_per_slice(self):
681729 h1_file_2000 = self ._create_test_file ("test.clm2.h1i.2000-01-01-00000.nc" )
682730 h1_file_2001 = self ._create_test_file ("test.clm2.h1i.2001-01-01-00000.nc" )
683731
684- # Create multiple h2 files for 2000 (daily throughout the year)
732+ # Create multiple h2 files for 1999 and 2000 (daily throughout the year)
733+ h2_files_1999 = []
734+ for month in ["01" , "06" , "12" ]:
735+ h2_files_1999 .append (self ._create_test_file (f"test.clm2.h2i.1999-{ month } -15-00000.nc" ))
736+
685737 h2_files_2000 = []
686738 for month in ["01" , "06" , "12" ]:
687739 h2_files_2000 .append (self ._create_test_file (f"test.clm2.h2i.2000-{ month } -15-00000.nc" ))
688740
689- # Create h2 file for 2001
690- h2_file_2001 = self ._create_test_file ("test.clm2.h2i.2001-01-02-00000.nc" )
691-
692741 # Get time slice lists for first_season=1999, last_season=1999
693742 time_slice_lists_list = gg ._get_time_slice_lists (1999 , 1999 )
694743
@@ -700,18 +749,18 @@ def test_get_file_lists_multiple_files_per_slice(self):
700749 self .assertEqual (len (h1_file_lists ), 2 )
701750 self .assertEqual (len (h2_file_lists ), 2 )
702751
703- # Check contents of file lists for first year (2000)
752+ # Check contents of file lists
704753 # pylint: disable=unsubscriptable-object
705754 self .assertEqual (len (h1_file_lists [0 ]), 1 )
706755 self .assertEqual (h1_file_lists [0 ], [h1_file_2000 ])
707756 self .assertEqual (len (h2_file_lists [0 ]), 3 )
708- self .assertEqual (h2_file_lists [0 ], sorted (h2_files_2000 ))
757+ self .assertEqual (h2_file_lists [0 ], sorted (h2_files_1999 ))
709758
710759 # Check second year (2001)
711760 self .assertEqual (len (h1_file_lists [1 ]), 1 )
712761 self .assertEqual (h1_file_lists [1 ], [h1_file_2001 ])
713- self .assertEqual (len (h2_file_lists [1 ]), 1 )
714- self .assertEqual (h2_file_lists [1 ], [ h2_file_2001 ] )
762+ self .assertEqual (len (h2_file_lists [1 ]), 3 )
763+ self .assertEqual (h2_file_lists [1 ], sorted ( h2_files_2000 ) )
715764
716765 def test_get_file_lists_no_h1_files (self ):
717766 """Test _get_file_lists when h1 files are missing"""
0 commit comments