code: def test_heartbeat_reset(progress_reporter_cls):
      """Test heartbeat functionality in train and tune.
  
      Tune prints a table every `heartbeat_freq` seconds.
      Train prints a heartbeat every `heartbeat_freq` seconds, but a result
      also resets the counter.
      """
      # Train heartbeats are only reporter in VERBOSE
      reporter = progress_reporter_cls(verbosity=AirVerbosity.VERBOSE)
      reporter._print_heartbeat = mock.MagicMock()
  
      with freeze_time() as frozen:
          reporter.print_heartbeat([])
          assert reporter._print_heartbeat.call_count == 1
  
          # Tick until heartbeat freq. Next call to print_heartbeat should trigger
          frozen.tick(reporter._heartbeat_freq)
          reporter.print_heartbeat([])
          assert reporter._print_heartbeat.call_count == 2
  
          # Not quite there, yet. This should not trigger a heartbeat.
          frozen.tick(reporter._heartbeat_freq // 2)
          reporter.print_heartbeat([])
          assert reporter._print_heartbeat.call_count == 2
  
          # Let's report a result. This will reset the heartbeat timer
          reporter.on_trial_result(
              0, [], Trial("__fake", stub=True), {TRAINING_ITERATION: 1}
          )
  
          # Progress another half heartbeat. In Tune this triggers a heartbeat,
          # but in train the heartbeat is reset on trial result.
          frozen.tick(reporter._heartbeat_freq // 2 + 1)
          reporter.print_heartbeat([])
  
          if progress_reporter_cls == TrainReporter:
              # Thus, train shouldn't have reported
              assert reporter._print_heartbeat.call_count == 2
          elif progress_reporter_cls == TuneTerminalReporter:
              # But Tune should have.
              assert reporter._print_heartbeat.call_count == 3
          else:
              raise RuntimeError("Test faulty.")
  
imports: import argparse
  from unittest import mock
  import pytest
  import sys
  from freezegun import freeze_time
  from ray import tune
  from ray.air.constants import TRAINING_ITERATION
  from ray.tune.experimental.output import _get_time_str, _get_trials_by_state, _get_trial_info, _infer_user_metrics, _max_len, _current_best_trial, _best_trial_str, _get_trial_table_data, _get_dict_as_table_data, _infer_params, AirVerbosity, TrainReporter, TuneTerminalReporter
  from ray.tune.experiment.trial import Trial
label_desc: Use image node_id 15 for calling a global function with example usage: test_heartbeat_reset(progress_reporter_cls) without return types