def test_read_file_if_no_date_present(self):
     """Test raises if no date is present"""
     import iris
     from iris.cube import Cube
     from iris.coords import DimCoord
     cube = Cube([0, 0], var_name='var')
     time = DimCoord([0, 366], 'time', units='days since 1990-01-01')
     cube.add_dim_coord(time, 0)
     iris.save(cube, self.temp_file)
     start, end = get_start_end_year(self.temp_file)
     self.assertEqual(1990, start)
     self.assertEqual(1991, end)
Exemplo n.º 2
0
def test_read_time_from_cube(monkeypatch, tmp_path):
    """Try to get time from cube if no date in filename"""
    monkeypatch.chdir(tmp_path)
    temp_file = 'test.nc'
    cube = iris.cube.Cube([0, 0], var_name='var')
    time = iris.coords.DimCoord([0, 366],
                                'time',
                                units='days since 1990-01-01')
    cube.add_dim_coord(time, 0)
    iris.save(cube, temp_file)
    start, end = get_start_end_year(temp_file)
    assert start == 1990
    assert end == 1991
 def test_fails_if_no_date_present(self):
     """Test raises if no date is present"""
     with self.assertRaises(ValueError):
         get_start_end_year('var_whatever')
 def test_end_and_date_in_name(self):
     """Test parse one date at the end and one in experiment's name"""
     start, end = get_start_end_year(
         'var_control-1950_whatever_19800101.nc')
     self.assertEqual(1980, start)
     self.assertEqual(1980, end)
 def test_one_fulldate_at_the_start(self):
     """Test parse files with one date at the start"""
     start, end = get_start_end_year('19800101_var_whatever.nc')
     self.assertEqual(1980, start)
     self.assertEqual(1980, end)
 def test_full_dates_at_the_start(self):
     """Test parse files with two dates at the start"""
     start, end = get_start_end_year('19800101-19811231_var_whatever.nc')
     self.assertEqual(1980, start)
     self.assertEqual(1981, end)
 def test_one_year_at_the_end(self):
     """Test parse files with one year at the end"""
     start, end = get_start_end_year('var_whatever_1980.nc')
     self.assertEqual(1980, start)
     self.assertEqual(1980, end)
 def test_years_at_the_end(self):
     """Test parse files with two years at the end"""
     start, end = get_start_end_year('var_whatever_1980-1981')
     self.assertEqual(1980, start)
     self.assertEqual(1981, end)
Exemplo n.º 9
0
def test_fails_if_no_date_present():
    """Test raises if no date is present"""
    with pytest.raises((ValueError, OSError)):
        get_start_end_year('var_whatever')
Exemplo n.º 10
0
def test_get_start_end_year(case):
    """Tests for get_start_end_year function"""
    filename, case_start, case_end = case
    start, end = get_start_end_year(filename)
    assert case_start == start
    assert case_end == end