code: def test_gen_moving_timeseries_forecast():
      """Basic test for `gen_moving_timeseries_forecast`"""
      data = generate_df_for_tests(freq="1H", periods=1000)
      df = data["df"]
  
      # A simple train-forecast function which always uses last available
      # value as the forecasted value
      def train_forecast_func(
          df, value_col, time_col=None, forecast_horizon=1
      ):
          # Simply get last observed value and offer as forecast
          value = df[value_col].values[df.shape[0] - 1]
          forecasted_values = np.repeat(
              a=value, repeats=forecast_horizon
          )
          fut_df = pd.DataFrame({value_col: forecasted_values})
          return {"fut_df": fut_df}
  
      compare_df = gen_moving_timeseries_forecast(
          df=df,
          time_col="ts",
          value_col="y",
          train_forecast_func=train_forecast_func,
          train_move_ahead=10,
          forecast_horizon=7,
          min_training_end_point=100,
      )["compare_df"]
  
      assert (
          list(compare_df.head(5)["y_hat"].round(1).values)
          == [-0.6] * 5
      )
  
      # Input start and end times
      compare_df = gen_moving_timeseries_forecast(
          df=df,
          time_col="ts",
          value_col="y",
          train_forecast_func=train_forecast_func,
          train_move_ahead=10,
          forecast_horizon=7,
          min_training_end_point=None,
          min_training_end_timestamp="2018-07-15",
          max_forecast_end_point=None,
          max_forecast_end_timestamp="2018-08-01",
      )["compare_df"]
  
      assert (
          list(compare_df.head(5)["y_hat"].round(1).values)
          == [-3.5] * 5
      )
  
      expected_match = (
          "No reasonble train test period is found for validation"
      )
      with pytest.raises(ValueError, match=expected_match):
          gen_moving_timeseries_forecast(
              df=df,
              time_col="ts",
              value_col="y",
              train_forecast_func=train_forecast_func,
              train_move_ahead=10,
              forecast_horizon=700,
              min_training_end_point=1000,
          )["compare_df"]
  
imports: import numpy
  import pandas
  import pytest
  from greykite.common.gen_moving_timeseries_forecast import gen_moving_timeseries_forecast
  from greykite.common.testing_utils import generate_df_for_tests
label_desc: Use image node_id 1 for calling a global function with example usage: test_gen_moving_timeseries_forecast() and returns: dict