code: def test_single_encoders_general(self):
      ts = tg.linear_timeseries(length=24, freq="MS")
      covs = tg.linear_timeseries(length=24, freq="MS")
  
      input_chunk_length = 12
      output_chunk_length = 6
  
      for enc_cls in self.encoders_cls:
          if issubclass(enc_cls, CyclicTemporalEncoder):
              attr = "month"
              comps_expected = ["cyc_month_sin", "cyc_month_cos"]
              requires_fit = False
          elif issubclass(enc_cls, DatetimeAttributeEncoder):
              attr = "month"
              comps_expected = ["dta_month"]
              requires_fit = False
          elif issubclass(enc_cls, IntegerIndexEncoder):
              attr = "relative"
              comps_expected = ["pos_relative"]
              requires_fit = True
          elif issubclass(enc_cls, CallableIndexEncoder):
  
              def some_f(idx):
                  return idx.month
  
              attr = some_f
              comps_expected = ["cus_custom"]
              requires_fit = False
          else:
              attr, comps_expected, requires_fit = None, None, False
              raise_log(
                  ValueError("unknown encoder class"), logger=logger
              )
  
          enc = enc_cls(
              input_chunk_length=input_chunk_length,
              output_chunk_length=output_chunk_length,
              attribute=attr,
          )
          if isinstance(
              enc.index_generator, PastCovariatesIndexGenerator
          ):
              base_comp_name = "darts_enc_pc_"
          else:
              base_comp_name = "darts_enc_fc_"
          comps_expected = pd.Index(
              [
                  base_comp_name + comp_name
                  for comp_name in comps_expected
              ]
          )
  
          assert not enc.fit_called
          # initially, no components
          assert enc.components.empty
  
          # some encoders must be fit before encoding inference part
          assert requires_fit == enc.requires_fit
          if requires_fit:
              with pytest.raises(ValueError):
                  enc.encode_inference(n=1, target=ts, covariates=covs)
  
          def test_routine(
              encoder, merge_covs: bool, comps_expected: pd.Index
          ):
              """checks general behavior for `encode_train` and `encode_inference` with and without merging the
              output with original covariates"""
              n = 1
              covs_train = encoder.encode_train(
                  target=ts,
                  covariates=covs,
                  merge_covariates=merge_covs,
              )
              assert covs_train.end_time() == ts.end_time()
  
              # check the encoded component names
              assert encoder.components.equals(comps_expected)
              if not merge_covs:
                  assert covs_train.components.equals(comps_expected)
              else:
                  assert comps_expected.isin(
                      covs_train.components
                  ).all()
                  # check that original components are in output when merging
                  assert covs_train[list(covs.components)] == covs
  
              # check the same for inference
              covs_inf = encoder.encode_inference(
                  n=n,
                  target=ts,
                  covariates=covs,
                  merge_covariates=merge_covs,
              )
              # if we give input `covs` the encoder will use the same index as `covs`
              assert covs_inf.end_time() == covs.end_time()
              assert encoder.components.equals(comps_expected)
              if not merge_covs:
                  assert covs_inf.components.equals(comps_expected)
              else:
                  assert comps_expected.isin(covs_inf.components).all()
                  assert covs_inf[list(covs.components)] == covs
  
              # check that train_inference gives equal results
              covs_train_inf = encoder.encode_train_inference(
                  n=n,
                  target=ts,
                  covariates=covs,
                  merge_covariates=merge_covs,
              )
              assert (
                  covs_train_inf.start_time() == covs_train.start_time()
              )
              assert covs_train_inf.end_time() == covs_inf.end_time()
              assert covs_train_inf[covs_train.time_index] == covs_train
              assert covs_train_inf[covs_inf.time_index] == covs_inf
  
              # we can use the output of `encode_train()` as input for `encode_train()` and get the same
              # results (encoded components get overwritten)
              covs_train2 = encoder.encode_train(
                  target=ts,
                  covariates=covs_train,
                  merge_covariates=merge_covs,
              )
              if merge_covs:
                  assert covs_train2 == covs_train
              else:
                  overlap = covs_train.slice_intersect(covs_train2)
                  assert covs_train2 == overlap
  
              # we can use the output of `encode_train()` as input for `encode_inference()`. The encoded components
              # are dropped internally and appended again at the end
              covs_inf2 = encoder.encode_inference(
                  n=n,
                  target=ts,
                  covariates=covs_train,
                  merge_covariates=merge_covs,
              )
              # We get the same results with `merge_covariates=True` (as original covariates will still be in input)
              if merge_covs:
                  assert covs_inf2 == covs_inf
              # We get only the minimum required time spans with `merge_covariates=False` as input covariates will
              # are not in output of `encode_train()/inference()`
              else:
                  overlap = covs_inf.slice_intersect(covs_inf2)
                  if isinstance(
                      encoder.index_generator,
                      PastCovariatesIndexGenerator,
                  ):
                      assert len(covs_inf2) == input_chunk_length
                      assert covs_inf2.end_time() == ts.end_time()
                      assert covs_inf2 == overlap
                  else:
                      assert (
                          len(covs_inf2)
                          == input_chunk_length + output_chunk_length
                      )
                      assert (
                          covs_inf2.end_time()
                          == ts.end_time()
                          + ts.freq * output_chunk_length
                      )
                      overlap_inf = covs_inf2.slice_intersect(overlap)
                      assert overlap_inf == overlap
  
              # we can use the output of `encode_inference()` as input for `encode_inference()` and get the
              # same results (encoded components get overwritten)
              covs_inf3 = encoder.encode_inference(
                  n=1,
                  target=ts,
                  covariates=covs_inf2,
                  merge_covariates=merge_covs,
              )
              assert covs_inf3 == covs_inf2
  
          test_routine(
              copy.deepcopy(enc),
              merge_covs=False,
              comps_expected=comps_expected,
          )
          test_routine(
              copy.deepcopy(enc),
              merge_covs=True,
              comps_expected=comps_expected,
          )
  
imports: import copy
  from typing import Optional, Sequence
  import numpy
  import pandas
  import pytest
  from darts import TimeSeries
  from darts.dataprocessing.encoders import FutureCallableIndexEncoder, FutureCyclicEncoder, FutureDatetimeAttributeEncoder, FutureIntegerIndexEncoder, PastCallableIndexEncoder, PastCyclicEncoder, PastDatetimeAttributeEncoder, PastIntegerIndexEncoder, SequentialEncoder
  from darts.dataprocessing.encoders.encoder_base import PastCovariatesIndexGenerator, SingleEncoder
  from darts.dataprocessing.encoders.encoders import CallableIndexEncoder, CyclicTemporalEncoder, DatetimeAttributeEncoder, IntegerIndexEncoder
  from darts.dataprocessing.transformers import Scaler
  from darts.logging import get_logger, raise_log
  from darts.utils import timeseries_generation
label_desc: Use image node_id 6 for calling the TestEncoder obj's underlying member method code with example usage: obj.test_single_encoders_general() and returns: idx