code: def _get_mocked_trainer(links, stop_trigger=(10, "iteration")):
      updater = mock.Mock()
      optimizer = mock.Mock()
      target = mock.Mock()
      target.namedlinks.return_value = [
          (str(i), link) for i, link in enumerate(links)
      ]
  
      optimizer.target = target
      updater.get_all_optimizers.return_value = {
          "optimizer_name": optimizer
      }
      updater.iteration = 0
      updater.epoch = 0
      updater.epoch_detail = 0
      updater.is_new_epoch = True
      iter_per_epoch = 10
  
      def update():
          time.sleep(0.001)
          updater.iteration += 1
          updater.epoch = updater.iteration // iter_per_epoch
          updater.epoch_detail = updater.iteration / iter_per_epoch
          updater.is_new_epoch = updater.epoch == updater.epoch_detail
  
      updater.update = update
  
      return training.Trainer(updater, stop_trigger)
  
imports: import re
  import time
  import unittest
  import mock
  import six
  import chainer
  from chainer import backend
  from chainer import testing
  from chainer import training
  from chainer.training import extensions
label_desc: Use image node_id 1 for calling a global function with example usage: _get_mocked_trainer(links, stop_trigger) and returns: training