code: def test_build_df_using_interchange_protocol_mock(
      add_interchange_module_for_old_pandas, column_names_as_generator
  ):
      class InterchangeDataFrame:
          def __init__(self, columns):
              self._columns = columns
  
          if column_names_as_generator:
  
              def column_names(self):
                  for col in self._columns:
                      yield col
  
          else:
  
              def column_names(self):
                  return self._columns
  
      interchange_dataframe = InterchangeDataFrame(
          ["petal_width", "sepal_length", "sepal_width"]
      )
      interchange_dataframe_reduced = InterchangeDataFrame(
          ["petal_width", "sepal_length"]
      )
      interchange_dataframe.select_columns_by_name = mock.MagicMock(
          return_value=interchange_dataframe_reduced
      )
      interchange_dataframe_reduced.select_columns_by_name = (
          mock.MagicMock(return_value=interchange_dataframe_reduced)
      )
  
      class CustomDataFrame:
          def __dataframe__(self):
              return interchange_dataframe
  
      class CustomDataFrameReduced:
          def __dataframe__(self):
              return interchange_dataframe_reduced
  
      input_dataframe = CustomDataFrame()
      input_dataframe_reduced = CustomDataFrameReduced()
  
      iris_pandas = px.data.iris()
  
      with mock.patch("pandas.__version__", "2.0.2"):
          args = dict(
              data_frame=input_dataframe,
              x="petal_width",
              y="sepal_length",
          )
          with mock.patch(
              "pandas.api.interchange.from_dataframe",
              return_value=iris_pandas,
          ) as mock_from_dataframe:
              build_dataframe(args, go.Scatter)
          mock_from_dataframe.assert_called_once_with(
              interchange_dataframe_reduced
          )
          assert set(
              interchange_dataframe.select_columns_by_name.call_args[0][
                  0
              ]
          ) == {
              "petal_width",
              "sepal_length",
          }
  
          args = dict(data_frame=input_dataframe_reduced, color=None)
          with mock.patch(
              "pandas.api.interchange.from_dataframe",
              return_value=iris_pandas[["petal_width", "sepal_length"]],
          ) as mock_from_dataframe:
              build_dataframe(args, go.Scatter)
          mock_from_dataframe.assert_called_once_with(
              interchange_dataframe_reduced
          )
          interchange_dataframe_reduced.select_columns_by_name.assert_not_called()
  
imports: import plotly.express
  import plotly.graph_objects
  import numpy
  import pandas
  import pytest
  from packaging import version
  import unittest.mock
  from plotly.express._core import build_dataframe
  from pandas.testing import assert_frame_equal
label_desc: Use image node_id 18 for calling a global function with example usage: test_build_df_using_interchange_protocol_mock(add_interchange_module_for_old_pandas, column_names_as_generator) and returns: interchange_dataframe, interchange_dataframe_reduced, self