code: def test_terminate_on_nan_and_inf(state_output, should_terminate):
      torch.manual_seed(12)
  
      def update_fn(engine, batch):
          pass
  
      trainer = Engine(update_fn)
      trainer.state = State()
      h = TerminateOnNan()
  
      trainer.state.output = state_output
      if isinstance(state_output, np.ndarray):
          h._output_transform = lambda x: x.tolist()
      h(trainer)
      assert trainer.should_terminate == should_terminate
  
file_path: ignite/tests/ignite/handlers/test_terminate_on_nan.py
imports: import numpy
  import pytest
  import torch
  from ignite.engine import Engine, Events, State
  from ignite.handlers import TerminateOnNan
label_desc: Use image node_id 1 for calling a global function with example usage: test_terminate_on_nan_and_inf(state_output, should_terminate) without return types