code: def run_evaluation_monitor(
      self,
      D_train: xgb.DMatrix,
      D_valid: xgb.DMatrix,
      rounds: int,
      verbose_eval: Union[bool, int],
  ):
      def check_output(output: str) -> None:
          if int(verbose_eval) == 1:
              # Should print each iteration info
              assert len(output.split("\n")) == rounds
          elif int(verbose_eval) > rounds:
              # Should print first and latest iteration info
              assert len(output.split("\n")) == 2
          else:
              # Should print info by each period additionaly to first and latest
              # iteration
              num_periods = rounds // int(verbose_eval)
              # Extra information is required for latest iteration
              is_extra_info_required = num_periods * int(
                  verbose_eval
              ) < (rounds - 1)
              assert len(output.split("\n")) == (
                  1 + num_periods + int(is_extra_info_required)
              )
  
      evals_result: xgb.callback.TrainingCallback.EvalsLog = {}
      params = {"objective": "binary:logistic", "eval_metric": "error"}
      with tm.captured_output() as (out, err):
          xgb.train(
              params,
              D_train,
              evals=[(D_train, "Train"), (D_valid, "Valid")],
              num_boost_round=rounds,
              evals_result=evals_result,
              verbose_eval=verbose_eval,
          )
          output: str = out.getvalue().strip()
          check_output(output)
  
      with tm.captured_output() as (out, err):
          xgb.cv(
              params,
              D_train,
              num_boost_round=rounds,
              verbose_eval=verbose_eval,
          )
          output = out.getvalue().strip()
          check_output(output)
  
imports: import json
  import os
  import tempfile
  from typing import Union
  import pytest
  import xgboost
  from xgboost import testing
label_desc: Use image node_id 2 for calling the TestCallbacks obj's underlying member method code with example usage: obj.run_evaluation_monitor(D_train, D_valid, rounds, verbose_eval) without return types