code: def test_integration(dirname):
      n_epochs = 5
      data = list(range(50))
  
      losses = torch.rand(n_epochs * len(data))
      losses_iter = iter(losses)
  
      def update_fn(engine, batch):
          return next(losses_iter)
  
      trainer = Engine(update_fn)
  
      tb_logger = TensorboardLogger(log_dir=dirname)
  
      def dummy_handler(engine, logger, event_name):
          global_step = engine.state.get_event_attrib_value(event_name)
          logger.writer.add_scalar(
              "test_value", global_step, global_step
          )
  
      tb_logger.attach(
          trainer,
          log_handler=dummy_handler,
          event_name=Events.EPOCH_COMPLETED,
      )
  
      trainer.run(data, max_epochs=n_epochs)
      tb_logger.close()
  
      # Check if event files are present
      written_files = os.listdir(dirname)
      written_files = [f for f in written_files if "tfevents" in f]
      assert len(written_files) > 0
  
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 23 for calling a global function with example usage: test_integration(dirname) and returns: next