code: def custom_measurement_process(device, spy):
      assert (
          len(spy.call_args_list) > 0
      )  # make sure method is mocked properly
  
      samples = device._samples  # pylint:disable=protected-access
      call_args_list = list(spy.call_args_list)
      for call_args in call_args_list:
          if not call_args.kwargs.get("counts", False):
              continue
          meas = call_args.args[1]
          shot_range, bin_size = (
              call_args.kwargs["shot_range"],
              call_args.kwargs["bin_size"],
          )
          if isinstance(meas, Operator):
              all_outcomes = call_args.kwargs["all_outcomes"]
              meas = qml.counts(op=meas, all_outcomes=all_outcomes)
          old_res = device.sample(call_args.args[1], **call_args.kwargs)
          new_res = meas.process_samples(
              samples=samples,
              wire_order=device.wires,
              shot_range=shot_range,
              bin_size=bin_size,
          )
          if isinstance(old_res, dict):
              old_res = [old_res]
              new_res = [new_res]
          for old, new in zip(old_res, new_res):
              assert old.keys() == new.keys()
              assert qml.math.allequal(
                  list(old.values()), list(new.values())
              )
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane.measurements import Counts
  from pennylane.operation import Operator
label_desc: Use image node_id 1 for calling a global function with example usage: custom_measurement_process(device, spy) without return types