code: def test_tlstretch(rndstate, centered_data, metric, sample_weight):
      """Test pipeline for stretching data"""
      # check if the dispersion of the dataset indeed decreases to 1
      tlstr = TLStretch(
          target_domain="target_domain",
          final_dispersion=1.0,
          centered_data=centered_data,
          metric=metric,
      )
      X, y_enc = make_classification_transfer(
          n_matrices=25, class_disp=2.0, random_state=rndstate
      )
  
      if sample_weight:
          sample_weight_ = rndstate.rand(len(y_enc))
      else:
          sample_weight_ = None
      if (
          centered_data
      ):  # ensure that data is indeed centered on each domain
          tlrct = TLCenter(target_domain="target_domain", metric=metric)
          X = tlrct.fit_transform(
              X, y_enc, sample_weight=sample_weight_
          )
  
      X_str = tlstr.fit_transform(
          X, y_enc, sample_weight=sample_weight_
      )
  
      _, _, domain = decode_domains(X_str, y_enc)
      for d in np.unique(domain):
          idx = domain == d
          Xd = X_str[idx]
          if sample_weight:
              sample_weight_d = check_weights(
                  sample_weight_[idx], np.sum(idx)
              )
              Md = mean_riemann(Xd, sample_weight=sample_weight_d)
              dist = distance(Xd, Md, metric=metric, squared=True)
              disp = np.sum(sample_weight_d * np.squeeze(dist))
          else:
              Md = mean_riemann(Xd)
              disp = np.mean(
                  distance(Xd, Md, metric=metric, squared=True)
              )
          assert np.isclose(disp, 1.0)
  
imports: import pytest
  from pytest import approx
  import numpy
  from numpy.testing import assert_array_equal
  from sklearn.model_selection import KFold, StratifiedShuffleSplit
  from sklearn.pipeline import make_pipeline, Pipeline
  from pyriemann.datasets.simulated import make_classification_transfer, make_matrices
  from pyriemann.classification import MDM, FgMDM, KNearestNeighbor, TSclassifier, SVC, MeanField
  from pyriemann.regression import KNearestNeighborRegressor, SVR
  from pyriemann.transfer import decode_domains, encode_domains, TLCenter, TLStretch, TLRotate, TLSplitter, TLClassifier, TLRegressor, MDWM
  from pyriemann.utils.distance import distance, distance_riemann
  from pyriemann.utils.mean import mean_covariance, mean_riemann
  from pyriemann.utils.utils import check_weights
label_desc: Use image node_id 3 for calling a global function with example usage: test_tlstretch(rndstate, centered_data, metric, sample_weight) without return types