code: def _get_callback_expected_on_calls_when_training(
      self, params, logs, has_valid=True, steps=None, valid_steps=None
  ):
      # pylint: disable=too-many-arguments
      if steps is None:
          steps = params["steps"]
      if has_valid and valid_steps is None:
          valid_steps = params["valid_steps"]
  
      train_batch_dict = dict(
          zip(self.batch_metrics_names, self.batch_metrics_values),
          time=ANY,
          loss=ANY,
      )
      train_epochs_dict = dict(
          zip(self.epoch_metrics_names, self.epoch_metrics_values)
      )
      log_dict = {**train_batch_dict, **train_epochs_dict}
      if has_valid:
          val_batch_metrics_names = [
              "val_" + metric_name
              for metric_name in self.batch_metrics_names
          ]
          val_batch_dict = dict(
              zip(val_batch_metrics_names, self.batch_metrics_values),
              val_loss=ANY,
          )
          val_epoch_metrics_names = [
              "val_" + metric_name
              for metric_name in self.epoch_metrics_names
          ]
          val_epochs_dict = dict(
              zip(val_epoch_metrics_names, self.epoch_metrics_values)
          )
          log_dict.update({**val_batch_dict, **val_epochs_dict})
  
      for epoch, log in enumerate(logs, 1):
          self.assertEqual(log, dict(log_dict, epoch=epoch))
  
      call_list = []
      call_list.append(call.on_train_begin({}))
      for epoch in range(1, params["epochs"] + 1):
          call_list.append(call.on_epoch_begin(epoch, {}))
          for step in range(1, steps + 1):
              call_list.append(call.on_train_batch_begin(step, {}))
              call_list.append(call.on_backward_end(step))
              call_list.append(
                  call.on_train_batch_end(
                      step,
                      {"batch": step, "size": ANY, **train_batch_dict},
                  )
              )
          if has_valid:
              call_list.append(call.on_valid_begin({}))
              for step in range(1, valid_steps + 1):
                  call_list.append(call.on_valid_batch_begin(step, {}))
                  call_list.append(
                      call.on_valid_batch_end(
                          step,
                          {
                              "batch": step,
                              "size": ANY,
                              "time": ANY,
                              **val_batch_dict,
                          },
                      )
                  )
              call_list.append(
                  call.on_valid_end(
                      {"time": ANY, **val_batch_dict, **val_epochs_dict}
                  )
              )
          call_list.append(call.on_epoch_end(epoch, logs[epoch - 1]))
  
      call_list.append(call.on_train_end({}))
      return call_list
  
imports: import os
  from unittest.mock import ANY, MagicMock, call
  import numpy
  import torch
  import torch.nn
  from poutyne import Callback
  from tests.framework.base import CaptureOutputBase
label_desc: Use image node_id 2 for calling the ModelFittingTestCase obj's underlying member method code with example usage: obj._get_callback_expected_on_calls_when_training(params, logs, has_valid, steps, valid_steps) and returns: call_list