@@ -734,18 +734,42 @@ def test_fix_metadata_amon_tas_invalid_time_units(self):
734734 assert self .mock_debug .call_count == 3
735735 assert self .mock_warning .call_count == 7
736736
737- def test_fix_metadata_amon_tas_invalid_time_attrs (self ):
737+ @pytest .mark .parametrize ("problem" , ["none" , "bad_units" , "bad_values" ])
738+ def test_fix_metadata_amon_tas_invalid_time_attrs (self , problem ):
738739 """Test ``fix_metadata`` with invalid time attributes."""
739740 short_name = "tas"
740741 project = "CMIP6"
741742 dataset = "__MODEL_WITH_NO_EXPLICIT_FIX__"
742743 mip = "Amon"
743744
744- self .cubes_2d_latlon [0 ].attributes = {
745- "parent_time_units" : "this is certainly not a unit" ,
746- "branch_time_in_parent" : "BRANCH TIME IN PARENT" ,
747- "branch_time_in_child" : "BRANCH TIME IN CHILD" ,
748- }
745+ attributes = {}
746+ expected_attributes = {}
747+ if problem == "bad_units" :
748+ attributes ["parent_time_units" ] = "this is certainly not a unit"
749+ else :
750+ attributes ["parent_time_units" ] = "days since 1000-01-01 00:00:0.0"
751+
752+ if problem == "bad_values" :
753+ attributes ["branch_time_in_child" ] = 1e9
754+ attributes ["branch_time_in_parent" ] = 1e9
755+ else :
756+ attributes ["branch_time_in_child" ] = 0.0
757+ attributes ["branch_time_in_parent" ] = 91676.0
758+
759+ if problem == "none" :
760+ expected_attributes = {
761+ "parent_time_units" : "days since 1850-1-1 00:00:00" ,
762+ "branch_time_in_child" : 365 ,
763+ "branch_time_in_parent" : - 218574 ,
764+ }
765+ else :
766+ expected_attributes = attributes .copy ()
767+ if problem == "bad_values" :
768+ expected_attributes ["parent_time_units" ] = (
769+ "days since 1850-1-1 00:00:00"
770+ )
771+
772+ self .cubes_2d_latlon [0 ].attributes = attributes
749773
750774 fixed_cubes = fix_metadata (
751775 self .cubes_2d_latlon ,
@@ -762,11 +786,7 @@ def test_fix_metadata_amon_tas_invalid_time_attrs(self):
762786 self .assert_lat_metadata (fixed_cube )
763787 self .assert_lon_metadata (fixed_cube )
764788
765- assert fixed_cube .attributes == {
766- "parent_time_units" : "this is certainly not a unit" ,
767- "branch_time_in_parent" : "BRANCH TIME IN PARENT" ,
768- "branch_time_in_child" : "BRANCH TIME IN CHILD" ,
769- }
789+ assert fixed_cube .attributes == expected_attributes
770790
771791 cmor_check_metadata (fixed_cube , project , mip , short_name )
772792
0 commit comments