code: def test_output_handler_metric_names():
      wrapper = OutputHandler("tag", metric_names=["a", "b"])
      mock_logger = MagicMock(spec=TensorboardLogger)
      mock_logger.writer = 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)
  
      assert mock_logger.writer.add_scalar.call_count == 2
      mock_logger.writer.add_scalar.assert_has_calls(
          [call("tag/a", 12.23, 5), call("tag/b", 23.45, 5)],
          any_order=True,
      )
  
      wrapper = OutputHandler("tag", metric_names=["a"])
  
      mock_engine = MagicMock()
      mock_engine.state = State(
          metrics={"a": torch.tensor([0.0, 1.0, 2.0, 3.0])}
      )
      mock_engine.state.iteration = 5
  
      mock_logger = MagicMock(spec=TensorboardLogger)
      mock_logger.writer = MagicMock()
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
  
      assert mock_logger.writer.add_scalar.call_count == 4
      mock_logger.writer.add_scalar.assert_has_calls(
          [
              call("tag/a/0", 0.0, 5),
              call("tag/a/1", 1.0, 5),
              call("tag/a/2", 2.0, 5),
              call("tag/a/3", 3.0, 5),
          ],
          any_order=True,
      )
  
      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=TensorboardLogger)
      mock_logger.writer = MagicMock()
  
      with pytest.warns(UserWarning):
          wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
  
      assert mock_logger.writer.add_scalar.call_count == 1
      mock_logger.writer.add_scalar.assert_has_calls(
          [call("tag/a", 55.56, 7)], any_order=True
      )
  
      # all metrics
      wrapper = OutputHandler("tag", metric_names="all")
      mock_logger = MagicMock(spec=TensorboardLogger)
      mock_logger.writer = 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)
  
      assert mock_logger.writer.add_scalar.call_count == 2
      mock_logger.writer.add_scalar.assert_has_calls(
          [call("tag/a", 12.23, 5), call("tag/b", 23.45, 5)],
          any_order=True,
      )
  
      # log a torch tensor (ndimension = 0)
      wrapper = OutputHandler("tag", metric_names="all")
      mock_logger = MagicMock(spec=TensorboardLogger)
      mock_logger.writer = MagicMock()
  
      mock_engine = MagicMock()
      mock_engine.state = State(
          metrics={"a": torch.tensor(12.23), "b": torch.tensor(23.45)}
      )
      mock_engine.state.iteration = 5
  
      wrapper(mock_engine, mock_logger, Events.ITERATION_STARTED)
  
      assert mock_logger.writer.add_scalar.call_count == 2
      mock_logger.writer.add_scalar.assert_has_calls(
          [
              call("tag/a", torch.tensor(12.23).item(), 5),
              call("tag/b", torch.tensor(23.45).item(), 5),
          ],
          any_order=True,
      )
  
imports: import math
  import os
  from unittest.mock import ANY, call, MagicMock, patch
  import pytest
  import torch
  from ignite.contrib.handlers.tensorboard_logger import global_step_from_engine, GradsHistHandler, GradsScalarHandler, OptimizerParamsHandler, OutputHandler, TensorboardLogger, WeightsHistHandler, WeightsScalarHandler
  from ignite.engine import Engine, 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