def test_historical_forecasts_with_scaler_errors(self, caplog):
        """Check that the appropriate exception is raised when providing incorrect parameters or the expected
        warning is display in the corner cases."""
        ocl = 2
        hf_args = {
            "start": -ocl - 1,
            "start_format": "position",
            "forecast_horizon": ocl,
            "verbose": False,
        }
        model = LinearRegressionModel(lags=5, output_chunk_length=ocl)
        model.fit(self.sine_univariate1)

        # retrain=False and unfitted data transformers
        with pytest.raises(ValueError) as err:
            model.historical_forecasts(
                **hf_args,
                series=self.sine_univariate1,
                data_transformers={"series": Scaler()},
                retrain=False,
            )
        assert str(err.value).startswith(
            "All the fittable entries in `data_transformers` must already be fitted when `retrain=False`, the "
        )

        # retrain=False, multiple series not matching the fitted data transformers dimensions
        with pytest.raises(ValueError) as err:
            model.historical_forecasts(
                **hf_args,
                series=[self.sine_univariate1] * 2,
                data_transformers={
                    "series": Scaler(global_fit=False).fit([self.sine_univariate1] * 3)
                },
                retrain=False,
            )
        assert str(err.value).startswith(
            "When multiple series are provided, their number should match the number of "
            "`TimeSeries` used to fit the data transformers `n=3`"
        )

        # retrain=True, multiple series and unfitted data transformers with global_fit=True
        expected_warning = (
            "When `retrain=True` and multiple series are provided, the fittable `data_transformers` "
            "are trained on each series independently (`global_fit=True` will be ignored)."
        )
        with caplog.at_level(logging.WARNING):
            model.historical_forecasts(
                **hf_args,
                series=[self.sine_univariate1, self.sine_univariate2],
                data_transformers={"series": Scaler(global_fit=True)},
                retrain=True,
            )
            assert expected_warning in caplog.text

        # data transformer (global_fit=False) prefitted on several series but only series is forecasted
        expected_warning = (
            "Provided only a single series, but at least one of the `data_transformers` "
            "that use `global_fit=False` was fitted on multiple `TimeSeries`."
        )
        with caplog.at_level(logging.WARNING):
            model.historical_forecasts(
                **hf_args,
                series=[self.sine_univariate2],
                data_transformers={
                    "series": Scaler(global_fit=False).fit([
                        self.sine_univariate1,
                        self.sine_univariate2,
                    ])
                },
                retrain=False,
            )
            assert expected_warning in caplog.text
Check that the appropriate exception is raised when providing incorrect parameters or the expected
        warning is display in the corner cases.
darts/tests/utils/historical_forecasts/test_historical_forecasts.py