code: def test_custom_events_with_event_to_attr():
      class CustomEvents(EventEnum):
          TEST_EVENT = "test_event"
  
      custom_event_to_attr = {CustomEvents.TEST_EVENT: "test_event"}
  
      # Dummy engine
      engine = Engine(lambda engine, batch: 0)
      engine.register_events(
          *CustomEvents, event_to_attr=custom_event_to_attr
      )
  
      # Handle is never called
      handle = MagicMock()
      engine.add_event_handler(CustomEvents.TEST_EVENT, handle)
      engine.run(range(1))
      assert hasattr(engine.state, "test_event")
      assert engine.state.test_event == 0
  
      # Advanced engine
      def process_func(engine, batch):
          engine.fire_event(CustomEvents.TEST_EVENT)
  
      engine = Engine(process_func)
      engine.register_events(
          *CustomEvents, event_to_attr=custom_event_to_attr
      )
  
      def handle(engine):
          engine.state.test_event += 1
  
      engine.add_event_handler(CustomEvents.TEST_EVENT, handle)
      engine.run(range(25))
      assert engine.state.test_event == 25
  
      custom_event_to_attr = "a"
      engine = Engine(lambda engine, batch: 0)
      with pytest.raises(ValueError):
          engine.register_events(
              *CustomEvents, event_to_attr=custom_event_to_attr
          )
  
imports: from enum import Enum
  from unittest.mock import MagicMock
  import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.engine.events import CallableEventWithFilter, EventEnum, EventsList
label_desc: Use image node_id 3 for calling a global function with example usage: test_custom_events_with_event_to_attr() without return types