code: def call_link_with_samples(self, samples, func):
      # Call the link with given `samples` array.
      # `func` is a function in which the link is called.
  
      # mock sampler that returns the saved samples
      def mock_sample(shape):
          assert samples.shape == shape
          return samples.copy()
  
      # Wrap F.negative_sampling to replace sampler with the mock
      orig_negative_sampling = chainer.functions.negative_sampling
  
      def wrap_negative_sampling(*args, **kwargs):
          args = args[:3] + (mock_sample,) + args[4:]
          return orig_negative_sampling(*args, **kwargs)
  
      with testing.patch(
          "chainer.functions.loss.negative_sampling.negative_sampling",
          wraps=wrap_negative_sampling,
      ) as m:
          ret = func()
          assert m.call_count == 1
  
      return ret
  
file_path: chainer/tests/chainer_tests/links_tests/loss_tests/test_negative_sampling.py
imports: import unittest
  import numpy
  import chainer
  from chainer import backend
  from chainer.backend import CpuDevice
  from chainer import links
  from chainer import testing
label_desc: Use image node_id 4 for calling the TestNegativeSampling obj's underlying member method code with example usage: obj.call_link_with_samples(samples, func) and returns: ret, samples, orig_negative_sampling