def test_with_interval(self): cell_method_str = 'time: variance (interval: 1 hr)' expected = (CellMethod(method='variance', coords='time', intervals='1 hr'), ) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_comment(self): cell_method_str = 'time: maximum (interval: 1 hr comment: first bit) ' \ 'time: mean (interval: 1 day comment: second bit)' expected = (CellMethod(method='maximum', coords='time', intervals='1 hr', comments='first bit'), CellMethod(method='mean', coords='time', intervals='1 day', comments='second bit')) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_multiple(self): cell_method_str = 'time: maximum (interval: 1 hr) ' \ 'time: mean (interval: 1 day)' expected = (CellMethod(method='maximum', coords='time', intervals='1 hr'), CellMethod(method='mean', coords='time', intervals='1 day')) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_simple(self): cell_method_strings = [ 'time: mean', 'time : mean', ] expected = (CellMethod(method='mean', coords='time'),) for cell_method_str in cell_method_strings: res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_climatology_with_unknown_method(self): cell_method_str = 'time: min within days time: mean over days' expected = (CellMethod(method='min within days', coords='time'), CellMethod(method='mean over days', coords='time')) with mock.patch('warnings.warn') as warn: res = _parse_cell_methods('test_var', cell_method_str) self.assertIn("NetCDF variable 'test_var' contains unknown " "cell method 'min'", warn.call_args[0][0]) self.assertEqual(res, expected)
def test_portions_of_cells(self): cell_method_strings = [ 'area: mean where sea_ice over sea', 'area : mean where sea_ice over sea', ] expected = (CellMethod(method='mean where sea_ice over sea', coords='area'),) for cell_method_str in cell_method_strings: res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_with_interval(self): cell_method_strings = [ 'time: variance (interval: 1 hr)', 'time : variance (interval: 1 hr)', ] expected = (CellMethod(method='variance', coords='time', intervals='1 hr'),) for cell_method_str in cell_method_strings: res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_climatology_with_unknown_method(self): cell_method_str = 'time: min within days time: mean over days' expected = (CellMethod(method='min within days', coords='time'), CellMethod(method='mean over days', coords='time')) with mock.patch('warnings.warn') as warn: res = _parse_cell_methods('test_var', cell_method_str) self.assertIn( "NetCDF variable 'test_var' contains unknown " "cell method 'min'", warn.call_args[0][0]) self.assertEqual(res, expected)
def test_climatology(self): cell_method_strings = [ 'time: minimum within days time: mean over days', 'time : minimum within days time: mean over days', 'time: minimum within days time : mean over days', 'time : minimum within days time : mean over days', ] expected = (CellMethod(method='minimum within days', coords='time'), CellMethod(method='mean over days', coords='time')) for cell_method_str in cell_method_strings: res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_climatology(self): cell_method_str = 'time: minimum within days time: mean over days' expected = (CellMethod(method='minimum within days', coords='time'), CellMethod(method='mean over days', coords='time')) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_portions_of_cells(self): cell_method_str = 'area: mean where sea_ice over sea' expected = (CellMethod(method='mean where sea_ice over sea', coords='area'), ) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)
def test_simple(self): cell_method_str = 'time: mean' expected = (CellMethod(method='mean', coords='time'), ) res = _parse_cell_methods('test_var', cell_method_str) self.assertEqual(res, expected)