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))
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 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)
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)]
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'))
def test_fix_data(self): cube = Cube([0]) reference = Cube([0]) self.assertEqual(Fix(None).fix_data(cube), reference)
def test_get_fix_only_mip_case_insensitive(self): self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'omOn', 'thetao'), [Omon(None)])
def test_get_fix_no_var(self): self.assertListEqual( Fix.get_fixes('CMIP5', 'BNU-ESM', 'Amon', 'BAD_VAR'), [])
def test_get_fix_no_project(self): with pytest.raises(KeyError): Fix.get_fixes('BAD_PROJECT', 'BNU-ESM', 'Amon', 'ch4')
def test_get(self): """Test fix get""" self.assertListEqual(Fix.get_fixes('CMIP5', 'MIROC5', 'tas'), [Tas()])
def test_get(self): """Test fix get""" self.assertListEqual(Fix.get_fixes('CMIP5', 'MIROC5', 'sftof'), [Sftof()])
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)]
def test_get_cl_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP5', 'HadGEM2-ES', 'Amon', 'cl') assert fix == [Cl(None), AllVars(None)]
def test_get(self): """Test fix get.""" self.assertListEqual( Fix.get_fixes('CMIP5', 'HADGEM2-ES', 'Amon', 'o2'), [O2(None), AllVars(None)])
def test_get_tas_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP6', 'CESM2', 'Amon', 'tas') assert fix == [Tas(None)]
def test_get_fixes_with_replace(self): self.assertListEqual(Fix.get_fixes('CMIP5', 'BNU-ESM', 'Amon', 'ch4'), [Ch4(None)])
def test_get_fixes_with_generic(self): self.assertListEqual( Fix.get_fixes('CMIP5', 'CESM1-BGC', 'Amon', 'gpp'), [Gpp(None)])
def test_get_cl_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP5', 'inmcm4', 'Amon', 'cl') assert fix == [Cl(None)]
def test_get_fix_no_model(self): self.assertListEqual( Fix.get_fixes('CMIP5', 'BAD_MODEL', 'Amon', 'ch4'), [])
def test_get(self): """Test fix get.""" self.assertListEqual(Fix.get_fixes('CMIP5', 'INMCM4', 'Amon', 'nbp'), [Nbp(None)])
def test_get_fix_only_mip(self): self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'Omon', 'thetao'), [Omon(None)])
def test_get_cl_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP6', 'GFDL-CM4', 'Amon', 'cl') assert fix == [Cl(None)]
def test_get_fix_mip_and_var(self): self.assertListEqual(Fix.get_fixes('CMIP6', 'CESM2', 'Omon', 'tos'), [Tos(None), Omon(None)])
def test_get_siconc_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP6', 'NorESM2-LM', 'SImon', 'siconc') assert fix == [Siconc(None)]
def test_fix_file(self): filepath = 'sample_filepath' self.assertEqual(Fix(None).fix_file(filepath, 'preproc'), filepath)
def test_get(self): """Test fix get""" self.assertListEqual(Fix.get_fixes('CMIP5', 'CANESM2', 'fgco2'), [FgCo2()])
def test_get_cl_fix(): """Test getting of fix.""" fix = Fix.get_fixes('CMIP6', 'MPI-ESM1-2-LR', 'Amon', 'cl') assert fix == [Cl(None)]
def test_get_fix(self): self.assertListEqual( Fix.get_fixes('CMIP5', 'CanESM2', 'Amon', 'fgco2'), [FgCo2(None)])
def test_get_tas_fix(): fix = Fix.get_fixes('CMIP6', 'MCM-UA-1-0', 'Amon', 'tas') assert fix == [Tas(None), AllVars(None)]
def test_get_fix_case_insensitive(self): self.assertListEqual( Fix.get_fixes('CMIP5', 'CanESM2', 'Amon', 'fgCo2'), [FgCo2(None)])