code: def test_grads_scalar_handler(dummy_model_factory, norm_mock):
      model = dummy_model_factory(
          with_grads=True, with_frozen_layer=False
      )
  
      # define test wrapper to test with and without optional tag
      def _test(tag=None):
          wrapper = GradsScalarHandler(
              model, reduction=norm_mock, tag=tag
          )
          mock_logger = MagicMock(spec=VisdomLogger)
          mock_logger.vis = MagicMock()
          mock_logger.executor = _DummyExecutor()
  
          mock_engine = MagicMock()
          mock_engine.state = State()
          mock_engine.state.epoch = 5
  
          wrapper(mock_engine, mock_logger, Events.EPOCH_STARTED)
  
          tag_prefix = f"{tag}/" if tag else ""
  
          assert mock_logger.vis.line.call_count == 4
          mock_logger.vis.line.assert_has_calls(
              [
                  call(
                      X=[5],
                      Y=ANY,
                      env=mock_logger.vis.env,
                      win=None,
                      update=None,
                      opts=wrapper.windows[
                          tag_prefix + "grads_norm/fc1/weight"
                      ]["opts"],
                      name=tag_prefix + "grads_norm/fc1/weight",
                  ),
                  call(
                      X=[5],
                      Y=ANY,
                      env=mock_logger.vis.env,
                      win=None,
                      update=None,
                      opts=wrapper.windows[
                          tag_prefix + "grads_norm/fc1/bias"
                      ]["opts"],
                      name=tag_prefix + "grads_norm/fc1/bias",
                  ),
                  call(
                      X=[5],
                      Y=ANY,
                      env=mock_logger.vis.env,
                      win=None,
                      update=None,
                      opts=wrapper.windows[
                          tag_prefix + "grads_norm/fc2/weight"
                      ]["opts"],
                      name=tag_prefix + "grads_norm/fc2/weight",
                  ),
                  call(
                      X=[5],
                      Y=ANY,
                      env=mock_logger.vis.env,
                      win=None,
                      update=None,
                      opts=wrapper.windows[
                          tag_prefix + "grads_norm/fc2/bias"
                      ]["opts"],
                      name=tag_prefix + "grads_norm/fc2/bias",
                  ),
              ],
              any_order=True,
          )
  
      _test()
      _test(tag="tag")
  
imports: import sys
  from unittest.mock import ANY, call, MagicMock, patch
  import pytest
  import torch
  from ignite.contrib.handlers.visdom_logger import _DummyExecutor, global_step_from_engine, GradsScalarHandler, OptimizerParamsHandler, OutputHandler, VisdomLogger, WeightsScalarHandler
  from ignite.engine import Engine, Events, State
label_desc: Use image node_id 15 for calling a global function with example usage: test_grads_scalar_handler(dummy_model_factory, norm_mock) without return types