2, 0, 2, "K") check_cf_grib2("land_area_fraction", None, 2, 0, 0, '1') check_cf_grib2("land_binary_mask", None, 2, 0, 0, '1') check_cf_grib2("atmosphere_mass_content_of_water_vapor", None, 0, 1, 64, "kg m-2") check_cf_grib2("surface_altitude", None, 2, 0, 7, "m") # These should fail check_cf_grib2("air_temperature", "user_long_UNRECOGNISED", 0, 0, 0, 'K') check_cf_grib2("air_temperature_UNRECOGNISED", None, 0, 0, 0, 'K', expect_none=True) check_cf_grib2(None, "user_long_UNRECOGNISED", 0, 0, 0, 'K', expect_none=True) check_cf_grib2(None, "precipitable_water", 0, 1, 3, 'kg m-2') check_cf_grib2("invalid_unknown", "precipitable_water", 0, 1, 3, 'kg m-2', expect_none=True) check_cf_grib2(None, None, 0, 0, 0, '', expect_none=True) if __name__ == '__main__': itests.main()
list(range(1, 4))), 'noleap': np.array(list(range(359, 366)) + list(range(1, 4))), 'julian': np.array(list(range(360, 367)) + list(range(1, 4))), 'all_leap': np.array(list(range(360, 367)) + list(range(1, 4))), '365_day': np.array(list(range(359, 366)) + list(range(1, 4))), '366_day': np.array(list(range(360, 367)) + list(range(1, 4))), '360_day': np.array(list(range(355, 361)) + list(range(1, 5)))} def make_cube(self, calendar): n_times = 10 cube = Cube(np.arange(n_times)) time_coord = DimCoord(np.arange(n_times), standard_name='time', units=Unit('days since 1980-12-25', calendar=calendar)) cube.add_dim_coord(time_coord, 0) return cube def test_calendars(self): for calendar in calendars: cube = self.make_cube(calendar) add_day_of_year(cube, 'time') points = cube.coord('day_of_year').points expected_points = self.expected[calendar] msg = 'Test failed for the following calendar: {}.' self.assertArrayEqual(points, expected_points, err_msg=msg.format(calendar)) if __name__ == '__main__': tests.main()
mock_return = self.expected_result_axis1.data.copy() with patch.object(self.TEST, 'call_func', return_value=mock_return) as mock_method: result = self.TEST.aggregate(self.array, axis, mdtol=.45) self.assertMaskedArrayEqual(result, self.expected_result_axis1) mock_method.assert_called_once_with(self.array, axis=axis) class Test_update_metadata(tests.IrisTest): def test_no_units_change(self): # If the Aggregator has no units_func then the units should be # left unchanged. aggregator = Aggregator('', None) cube = Mock(units=sentinel.units) aggregator.update_metadata(cube, []) self.assertIs(cube.units, sentinel.units) def test_units_change(self): # If the Aggregator has a units_func then the new units should # be defined by its return value. units_func = Mock(return_value=sentinel.new_units) aggregator = Aggregator('', None, units_func) cube = Mock(units=sentinel.units) aggregator.update_metadata(cube, []) units_func.assert_called_once_with(sentinel.units) self.assertEqual(cube.units, sentinel.new_units) if __name__ == "__main__": tests.main()