11"""Test GDL-CM2P1 fixes."""
22import unittest
3+ from unittest import mock
34
45from cf_units import Unit
6+ import iris
57from iris .cube import Cube
68
79from esmvalcore .cmor .fix import Fix
8- from esmvalcore .cmor ._fixes .cmip5 .gfdl_cm2p1 import Sftof , AllVars , Areacello
10+ from esmvalcore .cmor ._fixes .cmip5 .gfdl_cm2p1 import (Sftof , AllVars ,
11+ Areacello , Sit )
912
1013
1114class TestSftof (unittest .TestCase ):
@@ -29,7 +32,8 @@ def test_fix_data(self):
2932
3033
3134class TestAreacello (unittest .TestCase ):
32- """Test sftof fixes."""
35+ """Test areacello fixes."""
36+
3337 def setUp (self ):
3438 """Prepare tests."""
3539 self .cube = Cube ([1.0 ], var_name = 'areacello' , units = 'm-2' )
@@ -53,3 +57,64 @@ def test_fix_data(self):
5357 cube = self .fix .fix_metadata ((self .cube , ))[0 ]
5458 self .assertEqual (cube .data [0 ], 1.0 )
5559 self .assertEqual (cube .units , Unit ('m2' ))
60+
61+
62+ class TestSit (unittest .TestCase ):
63+ """Test sit fixes."""
64+
65+ def setUp (self ):
66+ """Prepare tests."""
67+ self .cube = Cube ([1.0 , 2.0 ], var_name = 'sit' , units = 'm' )
68+ self .cube .add_dim_coord (
69+ iris .coords .DimCoord (
70+ points = [45000.5 , 45031.5 ],
71+ var_name = 'time' ,
72+ standard_name = 'time' ,
73+ long_name = 'time' ,
74+ units = 'days since 1850-01-01' ,
75+ bounds = [[1e8 , 1.1e8 ], [1.1e8 , 1.2e8 ]]
76+ ),
77+ 0
78+ )
79+ self .var_info_mock = mock .Mock ()
80+ self .var_info_mock .frequency = 'mon'
81+ self .fix = Sit (self .var_info_mock )
82+
83+ def test_get (self ):
84+ """Test fix get"""
85+ self .assertListEqual (
86+ Fix .get_fixes ('CMIP5' , 'GFDL-CM2P1' , 'OImon' , 'sit' ),
87+ [Sit (self .var_info_mock ), AllVars (None )])
88+
89+ def test_fix_metadata_day_do_nothing (self ):
90+ """Test data fix."""
91+ self .var_info_mock .frequency = 'day'
92+ fix = Sit (self .var_info_mock )
93+ cube = fix .fix_metadata ((self .cube ,))[0 ]
94+ time = cube .coord ('time' )
95+ self .assertEqual (time .bounds [0 , 0 ], 1e8 )
96+ self .assertEqual (time .bounds [0 , 1 ], 1.1e8 )
97+ self .assertEqual (time .bounds [1 , 0 ], 1.1e8 )
98+ self .assertEqual (time .bounds [1 , 1 ], 1.2e8 )
99+
100+ def test_fix_metadata (self ):
101+ """Test data fix."""
102+ fix = Sit (self .var_info_mock )
103+ cube = fix .fix_metadata ((self .cube ,))[0 ]
104+ time = cube .coord ('time' )
105+ self .assertEqual (time .bounds [0 , 0 ], 44984 )
106+ self .assertEqual (time .bounds [0 , 1 ], 45015 )
107+ self .assertEqual (time .bounds [1 , 0 ], 45015 )
108+ self .assertEqual (time .bounds [1 , 1 ], 45045 )
109+
110+ def test_fix_metadata_not_needed (self ):
111+ """Test data fix."""
112+ fix = Sit (self .var_info_mock )
113+ cube = fix .fix_metadata ((self .cube ,))[0 ]
114+ time = cube .coord ('time' )
115+ new_bounds = [[44985. , 45014. ], [45016. , 45044. ]]
116+ time .bounds = new_bounds
117+ self .assertEqual (time .bounds [0 , 0 ], 44985 )
118+ self .assertEqual (time .bounds [0 , 1 ], 45014 )
119+ self .assertEqual (time .bounds [1 , 0 ], 45016 )
120+ self .assertEqual (time .bounds [1 , 1 ], 45044 )
0 commit comments