code: def test_custom_event_filter_with_engine():
      special_events = [1, 2, 5, 7, 17, 20]
  
      def custom_event_filter(engine, event):
          if event in special_events:
              return True
          return False
  
      def _test(event_name, event_attr, true_num_calls):
          engine = Engine(lambda e, b: b)
  
          num_calls = [0]
  
          @engine.on(event_name(event_filter=custom_event_filter))
          def assert_on_special_event(engine):
              assert getattr(
                  engine.state, event_attr
              ) == special_events.pop(0)
              num_calls[0] += 1
  
          d = list(range(50))
          engine.run(d, max_epochs=25)
  
          assert num_calls[0] == true_num_calls
  
      _test(Events.ITERATION_STARTED, "iteration", len(special_events))
      _test(
          Events.ITERATION_COMPLETED, "iteration", len(special_events)
      )
      _test(Events.EPOCH_STARTED, "epoch", len(special_events))
      _test(Events.EPOCH_COMPLETED, "epoch", len(special_events))
  
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 17 for calling a global function with example usage: test_custom_event_filter_with_engine() and returns: False, True