code: def test_pipeline_consistency(
      estimator, build_dataset, with_preprocessor
  ):
      # Adapted from scikit learn
      # check that make_pipeline(est) gives same score as est
  
      input_data, y, preprocessor, _ = build_dataset(with_preprocessor)
  
      def make_random_state(estimator, in_pipeline):
          rs = {}
          name_estimator = estimator.__class__.__name__
          if name_estimator[-11:] == "_Supervised":
              name_param = "random_state"
              if in_pipeline:
                  name_param = (
                      name_estimator.lower() + "__" + name_param
                  )
              rs[name_param] = check_random_state(0)
          return rs
  
      estimator = clone(estimator)
      estimator.set_params(
          preprocessor=preprocessor,
          **make_random_state(estimator, False),
      )
      pipeline = make_pipeline(estimator)
      estimator.fit(input_data, y)
      estimator.set_params(preprocessor=preprocessor)
      pipeline.set_params(**make_random_state(estimator, True))
      pipeline.fit(input_data, y)
  
      if hasattr(estimator, "score"):
          result = estimator.score(input_data, y)
          result_pipe = pipeline.score(input_data, y)
          assert_allclose_dense_sparse(result, result_pipe)
  
      if hasattr(estimator, "predict"):
          result = estimator.predict(input_data)
          result_pipe = pipeline.predict(input_data)
          assert_allclose_dense_sparse(result, result_pipe)
  
      if issubclass(estimator.__class__, TransformerMixin):
          if hasattr(estimator, "transform"):
              result = estimator.transform(input_data)
              result_pipe = pipeline.transform(input_data)
              assert_allclose_dense_sparse(result, result_pipe)
  
imports: import pytest
  import unittest
  from sklearn.utils.estimator_checks import check_estimator
  from sklearn.base import TransformerMixin
  from sklearn.pipeline import make_pipeline
  from sklearn.utils import check_random_state
  from metric_learn.sklearn_shims import assert_allclose_dense_sparse, set_random_state, _get_args, is_public_parameter, get_scorer
  from metric_learn import Covariance, LFDA, LMNN, MLKR, NCA, ITML_Supervised, LSML_Supervised, MMC_Supervised, RCA_Supervised, SDML_Supervised, SCML_Supervised
  from sklearn import clone
  import numpy
  from sklearn.model_selection import cross_val_score, cross_val_predict, train_test_split, KFold
  from test.test_utils import metric_learners, ids_metric_learners, mock_preprocessor, tuples_learners, ids_tuples_learners, pairs_learners, ids_pairs_learners, remove_y, metric_learners_pipeline, ids_metric_learners_pipeline
label_desc: Use image node_id 12 for calling a global function with example usage: test_pipeline_consistency(estimator, build_dataset, with_preprocessor) and returns: rs