code: def insertmanyvalues_fixture(
      connection, randomize_rows=False, warn_on_downgraded=False
  ):
      dialect = connection.dialect
      orig_dialect = dialect._deliver_insertmanyvalues_batches
      orig_conn = connection._exec_insertmany_context
  
      class RandomCursor:
          __slots__ = ("cursor",)
  
          def __init__(self, cursor):
              self.cursor = cursor
  
          # only this method is called by the deliver method.
          # by not having the other methods we assert that those aren't being
          # used
  
          def fetchall(self):
              rows = self.cursor.fetchall()
              rows = list(rows)
              random.shuffle(rows)
              return rows
  
      def _deliver_insertmanyvalues_batches(
          cursor, statement, parameters, generic_setinputsizes, context
      ):
          if randomize_rows:
              cursor = RandomCursor(cursor)
          for batch in orig_dialect(
              cursor,
              statement,
              parameters,
              generic_setinputsizes,
              context,
          ):
              if warn_on_downgraded and batch.is_downgraded:
                  util.warn("Batches were downgraded for sorted INSERT")
  
              yield batch
  
      def _exec_insertmany_context(
          dialect,
          context,
      ):
          with mock.patch.object(
              dialect,
              "_deliver_insertmanyvalues_batches",
              new=_deliver_insertmanyvalues_batches,
          ):
              return orig_conn(dialect, context)
  
      connection._exec_insertmany_context = _exec_insertmany_context
  
imports: from __future__ import annotations
  import itertools
  import random
  import re
  import sys
  import sqlalchemy
  from .base import TestBase
  from ..None import config
  from ..None import mock
  from ..assertions import eq_
  from ..assertions import ne_
  from ..util import adict
  from ..util import drop_all_tables_from_metadata
  from ...None import event
  from ...None import util
  from ...schema import sort_tables_and_constraints
  from ...sql import visitors
  from ...sql.elements import ClauseElement
label_desc: Use image node_id 1 for calling a global function with example usage: insertmanyvalues_fixture(connection, randomize_rows, warn_on_downgraded) and returns: rows, orig_conn