code: def test_writes_event_and_stats_logs():
      class TestEventsWriter(LogEventsWriter):
          """Test event writer for checking logged events."""
  
          def __init__(self):
              self.step_count = 0
              self.reward_events_count = 0
  
          def write(self, episode_record: EpisodeEventLog):
              """Check that we have some reward events as well as env-specific events."""
  
              self.step_count += len(episode_record.step_event_logs)
              self.reward_events_count += len(
                  list(
                      episode_record.query_events(BaseEnvEvents.reward)
                  )
              )
  
      class TestStatsWriter(LogStatsWriter):
          """Test stats writer for checking if stats get calculated."""
  
          def __init__(self):
              self.collected_stats_count = 0
  
          def write(
              self, path: str, step: int, stats: LogStats
          ) -> None:
              """Count number of stats items received"""
              self.collected_stats_count += len(stats)
              pass
  
      step_count = 10
  
      # Event logging
      events_writer = TestEventsWriter()
      LogEventsWriterRegistry.writers = (
          []
      )  # Ensure there is no other writer
      LogEventsWriterRegistry.register_writer(events_writer)
  
      # Stats logging
      stats_writer = TestStatsWriter()
      register_log_stats_writer(stats_writer)
  
      agent_deployment = AgentDeployment(
          policy=DummyGreedyPolicy(),
          env=build_dummy_maze_env(),
          wrappers={LogStatsWrapper: {"logging_prefix": "test"}},
      )
  
      # Step the environment manually here and query the agent integration wrapper for maze_actions
      test_core_env = build_dummy_maze_env().core_env
      maze_state = test_core_env.reset()
      reward, done, info = None, None, None
      for i in range(step_count):
          maze_action = agent_deployment.act(
              maze_state,
              reward,
              done,
              info,
              events=list(test_core_env.get_step_events()),
          )
          state, reward, done, info = test_core_env.step(maze_action)
          test_core_env.context.increment_env_step()  # Done by maze env ordinarily
  
      # Rollout needs to be finished to notify the wrappers
      agent_deployment.close(
          maze_state,
          reward,
          done,
          info,
          events=list(test_core_env.get_step_events()),
      )
  
      # Event logging
      assert events_writer.step_count == step_count
      assert events_writer.reward_events_count == step_count
  
      # Stats logging
      assert stats_writer.collected_stats_count > 0
  
imports: from typing import Tuple, Sequence, Optional
  import gym
  import numpy
  import pytest
  from maze.core.agent.random_policy import RandomPolicy
  from maze.core.agent_deployment.agent_deployment import AgentDeployment
  from maze.core.env.action_conversion import ActionType
  from maze.core.env.base_env import BaseEnv
  from maze.core.env.base_env_events import BaseEnvEvents
  from maze.core.env.maze_state import MazeStateType
  from maze.core.env.observation_conversion import ObservationType
  from maze.core.env.structured_env import ActorID
  from maze.core.log_events.episode_event_log import EpisodeEventLog
  from maze.core.log_events.log_events_writer import LogEventsWriter
  from maze.core.log_events.log_events_writer_registry import LogEventsWriterRegistry
  from maze.core.log_events.monitoring_events import RewardEvents
  from maze.core.log_stats.log_stats import LogStatsWriter, LogStats, LogStatsLevel
  from maze.core.log_stats.log_stats import register_log_stats_writer
  from maze.core.trajectory_recording.records.trajectory_record import StateTrajectoryRecord
  from maze.core.trajectory_recording.writers.trajectory_writer import TrajectoryWriter
  from maze.core.trajectory_recording.writers.trajectory_writer_registry import TrajectoryWriterRegistry
  from maze.core.utils.config_utils import EnvFactory, read_hydra_config
  from maze.core.wrappers.log_stats_wrapper import LogStatsWrapper
  from maze.core.wrappers.maze_gym_env_wrapper import GymMazeEnv
  from maze.core.wrappers.trajectory_recording_wrapper import TrajectoryRecordingWrapper
  from maze.test.shared_test_utils.dummy_wrappers.step_skip_in_step_wrapper import StepSkipInStepWrapper
  from maze.test.shared_test_utils.dummy_env.agents.dummy_policy import DummyGreedyPolicy
  from maze.test.shared_test_utils.helper_functions import build_dummy_maze_env, build_dummy_structured_env
label_desc: Use image node_id 6 for calling a global function with example usage: test_writes_event_and_stats_logs() without return types