code: def test_output_handler_metric_names():
      wrapper = OutputHandler("tag", metric_names=["a", "b"])
      mock_logger = MagicMock(spec=WandBLogger)
      mock_logger.log = MagicMock()
  
      mock_engine = MagicMock()
      mock_engine.state = State(metrics={"a": 1, "b": 5})
      mock_engine.state.iteration = 5
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
      mock_logger.log.assert_called_once_with(
          {"tag/a": 1, "tag/b": 5}, step=5, sync=None
      )
  
      wrapper = OutputHandler("tag", metric_names=["a", "c"])
      mock_engine = MagicMock()
      mock_engine.state = State(metrics={"a": 55.56, "c": "Some text"})
      mock_engine.state.iteration = 7
  
      mock_logger = MagicMock(spec=WandBLogger)
      mock_logger.log = MagicMock()
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
      mock_logger.log.assert_called_once_with(
          {"tag/a": 55.56, "tag/c": "Some text"}, step=7, sync=None
      )
  
      # all metrics
      wrapper = OutputHandler("tag", metric_names="all")
      mock_logger = MagicMock(spec=WandBLogger)
      mock_logger.log = MagicMock()
  
      mock_engine = MagicMock()
      mock_engine.state = State(metrics={"a": 12.23, "b": 23.45})
      mock_engine.state.iteration = 5
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
      mock_logger.log.assert_called_once_with(
          {"tag/a": 12.23, "tag/b": 23.45}, step=5, sync=None
      )
  
      # log a torch vector
      wrapper = OutputHandler("tag", metric_names="all")
      mock_logger = MagicMock(spec=WandBLogger)
      mock_logger.log = MagicMock()
      vector = torch.tensor([0.1, 0.2, 0.1, 0.2, 0.33])
      mock_engine = MagicMock()
      mock_engine.state = State(metrics={"a": vector})
      mock_engine.state.iteration = 5
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
      mock_logger.log.assert_called_once_with(
          {f"tag/a/{i}": vector[i].item() for i in range(5)},
          step=5,
          sync=None,
      )
  
      # log warning
      wrapper = OutputHandler("tag", metric_names=["a"])
      mock_engine = MagicMock()
      mock_engine.state = State(metrics={"a": [1, 2, 3, 4]})
      mock_engine.state.iteration = 7
  
      mock_logger = MagicMock(spec=WandBLogger)
      mock_logger.log = MagicMock()
  
      with pytest.warns(
          UserWarning,
          match=r"Logger output_handler can not log metrics value type",
      ):
          wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
  
file_path: ignite/tests/ignite/contrib/handlers/test_wandb_logger.py
imports: from unittest.mock import call, MagicMock
  import pytest
  import torch
  from ignite.contrib.handlers.wandb_logger import global_step_from_engine, OptimizerParamsHandler, OutputHandler, WandBLogger
  from ignite.engine import Events, State
label_desc: Use image node_id 6 for calling a global function with example usage: test_output_handler_metric_names() without return types