Ejemplo n.º 1
0
class TestGetCube(unittest.TestCase):
    """Test get cube by var_name method"""

    def setUp(self):
        """Prepare for testing"""
        self.cube_1 = mock.Mock()
        self.cube_1.var_name = 'cube1'
        self.cube_2 = mock.Mock()
        self.cube_2.var_name = 'cube2'
        self.cubes = [self.cube_1, self.cube_2]
        self.fix = Fix()

    def test_get_first_cube(self):
        """Test selecting first cube"""
        self.assertIs(self.cube_1,
                      self.fix.get_cube_from_list(self.cubes, "cube1"))

    def test_get_second_cube(self):
        """Test selecting second cube."""
        self.assertIs(self.cube_2,
                      self.fix.get_cube_from_list(self.cubes, "cube2"))

    def test_get_default_raises(self):
        """Check that the default raises (Fix is not a cube)."""
        with self.assertRaises(Exception):
            self.fix.get_cube_from_list(self.cubes)

    def test_get_default(self):
        """Check that the default raises (Fix is a cube)."""
        self.cube_1.var_name = 'Fix'
        self.assertIs(self.cube_1, self.fix.get_cube_from_list(self.cubes))
Ejemplo n.º 2
0
 def setUp(self):
     """Prepare for testing"""
     self.cube_1 = mock.Mock()
     self.cube_1.var_name = 'cube1'
     self.cube_2 = mock.Mock()
     self.cube_2.var_name = 'cube2'
     self.cubes = [self.cube_1, self.cube_2]
     self.fix = Fix()
Ejemplo n.º 3
0
 def setUp(self):
     """Prepare for testing."""
     self.cube_1 = Mock()
     self.cube_1.var_name = 'cube1'
     self.cube_2 = Mock()
     self.cube_2.var_name = 'cube2'
     self.cubes = [self.cube_1, self.cube_2]
     vardef = Mock()
     vardef.short_name = 'fix'
     self.fix = Fix(vardef)
Ejemplo n.º 4
0
def test_get_allvars_fix():
    fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Amon',
                        'arbitrary_var_name_and_wrong_lon_bnds')
    assert fix == [AllVars(None)]
Ejemplo n.º 5
0
 def test_fixed_filenam(self):
     filepath = os.path.join(self.temp_folder, 'file.nc')
     output_dir = os.path.join(self.temp_folder, 'fixed')
     os.makedirs(output_dir)
     fixed_filepath = Fix(None).get_fixed_filepath(output_dir, filepath)
     self.assertTrue(fixed_filepath, os.path.join(output_dir, 'file.nc'))
Ejemplo n.º 6
0
    def test_fix_data(self):
        cube = Cube([0])
        reference = Cube([0])

        self.assertEqual(Fix(None).fix_data(cube), reference)
Ejemplo n.º 7
0
 def test_get_fix_only_mip_case_insensitive(self):
     self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'omOn', 'thetao'),
                          [Omon(None)])
Ejemplo n.º 8
0
 def test_get_fix_no_var(self):
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'BNU-ESM', 'Amon', 'BAD_VAR'), [])
Ejemplo n.º 9
0
 def test_get_fix_no_project(self):
     with pytest.raises(KeyError):
         Fix.get_fixes('BAD_PROJECT', 'BNU-ESM', 'Amon', 'ch4')
Ejemplo n.º 10
0
 def test_get(self):
     """Test fix get"""
     self.assertListEqual(Fix.get_fixes('CMIP5', 'MIROC5', 'tas'), [Tas()])
Ejemplo n.º 11
0
 def test_get(self):
     """Test fix get"""
     self.assertListEqual(Fix.get_fixes('CMIP5', 'MIROC5', 'sftof'),
                          [Sftof()])
Ejemplo n.º 12
0
def test_get_thetao_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Omon', 'thetao')
    assert fix == [Omon(None), AllVars(None)]
Ejemplo n.º 13
0
def test_get_cl_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP5', 'HadGEM2-ES', 'Amon', 'cl')
    assert fix == [Cl(None), AllVars(None)]
Ejemplo n.º 14
0
 def test_get(self):
     """Test fix get."""
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'HADGEM2-ES', 'Amon', 'o2'),
         [O2(None), AllVars(None)])
Ejemplo n.º 15
0
def test_get_tas_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'CESM2', 'Amon', 'tas')
    assert fix == [Tas(None)]
Ejemplo n.º 16
0
 def test_get_fixes_with_replace(self):
     self.assertListEqual(Fix.get_fixes('CMIP5', 'BNU-ESM', 'Amon', 'ch4'),
                          [Ch4(None)])
Ejemplo n.º 17
0
 def test_get_fixes_with_generic(self):
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'CESM1-BGC', 'Amon', 'gpp'), [Gpp(None)])
Ejemplo n.º 18
0
def test_get_cl_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP5', 'inmcm4', 'Amon', 'cl')
    assert fix == [Cl(None)]
Ejemplo n.º 19
0
 def test_get_fix_no_model(self):
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'BAD_MODEL', 'Amon', 'ch4'), [])
Ejemplo n.º 20
0
 def test_get(self):
     """Test fix get."""
     self.assertListEqual(Fix.get_fixes('CMIP5', 'INMCM4', 'Amon', 'nbp'),
                          [Nbp(None)])
Ejemplo n.º 21
0
 def test_get_fix_only_mip(self):
     self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'Omon', 'thetao'),
                          [Omon(None)])
Ejemplo n.º 22
0
def test_get_cl_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'GFDL-CM4', 'Amon', 'cl')
    assert fix == [Cl(None)]
Ejemplo n.º 23
0
 def test_get_fix_mip_and_var(self):
     self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'Omon', 'tos'),
                          [Tos(None), Omon(None)])
Ejemplo n.º 24
0
def test_get_siconc_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'NorESM2-LM', 'SImon', 'siconc')
    assert fix == [Siconc(None)]
Ejemplo n.º 25
0
 def test_fix_file(self):
     filepath = 'sample_filepath'
     self.assertEqual(Fix(None).fix_file(filepath, 'preproc'), filepath)
Ejemplo n.º 26
0
 def test_get(self):
     """Test fix get"""
     self.assertListEqual(Fix.get_fixes('CMIP5', 'CANESM2', 'fgco2'),
                          [FgCo2()])
Ejemplo n.º 27
0
def test_get_cl_fix():
    """Test getting of fix."""
    fix = Fix.get_fixes('CMIP6', 'MPI-ESM1-2-LR', 'Amon', 'cl')
    assert fix == [Cl(None)]
Ejemplo n.º 28
0
 def test_get_fix(self):
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'CanESM2', 'Amon', 'fgco2'), [FgCo2(None)])
Ejemplo n.º 29
0
def test_get_tas_fix():
    fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Amon', 'tas')
    assert fix == [Tas(None), AllVars(None)]
Ejemplo n.º 30
0
 def test_get_fix_case_insensitive(self):
     self.assertListEqual(
         Fix.get_fixes('CMIP5', 'CanESM2', 'Amon', 'fgCo2'), [FgCo2(None)])