def _test(self, cube):
        grib = mock.Mock()
        mock_gribapi = mock.Mock(spec=gribapi)
        with mock.patch('iris.fileformats.grib._save_rules.gribapi',
                        mock_gribapi):
            reference_time(cube, grib)

        mock_gribapi.assert_has_calls(
            [mock.call.grib_set_long(grib, "significanceOfReferenceTime", 1),
             mock.call.grib_set_long(grib, "dataDate", '19980306'),
             mock.call.grib_set_long(grib, "dataTime", '0300')])
    def test_forecast_period(self):
        # The stock cube has a non-compliant forecast_period.
        iris.fileformats.grib.hindcast_workaround = True
        cube = stock.global_grib2()

        grib = mock.Mock()
        mock_gribapi = mock.Mock(spec=gribapi)
        with mock.patch(GRIB_API, mock_gribapi):
            reference_time(cube, grib)

        mock_gribapi.assert_has_calls(
            [mock.call.grib_set_long(grib, "significanceOfReferenceTime", 1),
             mock.call.grib_set_long(grib, "dataDate", '19980306'),
             mock.call.grib_set_long(grib, "dataTime", '0300')])
    def test_forecast_period(self):
        # The stock cube has a non-compliant forecast_period.
        iris.fileformats.grib.hindcast_workaround = True
        cube = stock.global_grib2()

        grib = mock.Mock()
        mock_gribapi = mock.Mock(spec=gribapi)
        with mock.patch(GRIB_API, mock_gribapi):
            reference_time(cube, grib)

        mock_gribapi.assert_has_calls(
            [mock.call.grib_set_long(grib, "significanceOfReferenceTime", 1),
             mock.call.grib_set_long(grib, "dataDate", '19980306'),
             mock.call.grib_set_long(grib, "dataTime", '0300')])
    def test_no_forecast_period(self):
        # The stock cube has a non-compliant forecast_period.
        iris.fileformats.grib.hindcast_workaround = True
        cube = stock.global_grib2()
        cube.remove_coord("forecast_period")
        frt_coords = cube.coords('forecast_reference_time')
        if frt_coords:
            cube.remove_coord(frt_coords[0])

        grib = mock.Mock()
        mock_gribapi = mock.Mock(spec=gribapi)
        with mock.patch(GRIB_API, mock_gribapi):
            reference_time(cube, grib)

        mock_gribapi.assert_has_calls(
            [mock.call.grib_set_long(grib, "significanceOfReferenceTime", 3),
             mock.call.grib_set_long(grib, "dataDate", '19941201'),
             mock.call.grib_set_long(grib, "dataTime", '0000')])
    def test_no_forecast_period(self):
        # The stock cube has a non-compliant forecast_period.
        iris.fileformats.grib.hindcast_workaround = True
        cube = stock.global_grib2()
        cube.remove_coord("forecast_period")
        frt_coords = cube.coords('forecast_reference_time')
        if frt_coords:
            cube.remove_coord(frt_coords[0])

        grib = mock.Mock()
        mock_gribapi = mock.Mock(spec=gribapi)
        with mock.patch(GRIB_API, mock_gribapi):
            reference_time(cube, grib)

        mock_gribapi.assert_has_calls([
            mock.call.grib_set_long(grib, "significanceOfReferenceTime", 3),
            mock.call.grib_set_long(grib, "dataDate", '19941201'),
            mock.call.grib_set_long(grib, "dataTime", '0000')
        ])