code: def testSortByMetric(self):
      trials = []
      for i in range(5):
          t = Mock()
          if i < 3:
              t.status = "TERMINATED"
          elif i == 3:
              t.status = "PENDING"
          else:
              t.status = "RUNNING"
          t.trial_id = "%05d" % i
          t.local_experiment_path = "/foo"
          t.temporary_state = Mock()
          t.temporary_state.location = "here"
          t.run_metadata = Mock()
          t.config = {"a": i}
          t.evaluated_params = {"a": i}
          t.last_result = {"config": {"a": i}}
          t.__str__ = lambda self: self.trial_id
          trials.append(t)
      # Set `metric_1` for terminated trails
      trials[0].last_result["metric_1"] = 0.3
      trials[0].last_result["nested"] = {"metric_2": 0.3}
      trials[1].last_result["metric_1"] = 0.2
      trials[1].last_result["nested"] = {"metric_2": 0.2}
      trials[2].last_result["metric_1"] = 0.4
      trials[2].last_result["nested"] = {"metric_2": 0.4}
  
      class TestReporter(CLIReporter):
          def __init__(self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              self._max_report_freqency = 0
              self._output = ""
  
          def report(self, *args, **kwargs):
              progress_str = self._progress_str(*args, **kwargs)
              self._output = progress_str
  
      # Default reporter
      reporter1 = TestReporter(
          max_progress_rows=4, mode="max", metric="metric_1"
      )
      reporter1.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_UNSORTED in reporter1._output
  
      # Sort by metric (asc)
      reporter2 = TestReporter(
          max_progress_rows=4,
          mode="min",
          metric="metric_1",
          sort_by_metric=True,
      )
      reporter2.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_ASC in reporter2._output
  
      # Sort by metric (desc)
      reporter3 = TestReporter(
          max_progress_rows=4,
          mode="max",
          metric="metric_1",
          sort_by_metric=True,
      )
      reporter3.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_DESC in reporter3._output
  
      # Sort by metric when mode is None
      reporter4 = TestReporter(
          max_progress_rows=4, metric="metric_1", sort_by_metric=True
      )
      reporter4.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_UNSORTED in reporter4._output
  
      # Sort by metric when metric is None
      reporter5 = TestReporter(
          max_progress_rows=4, mode="max", sort_by_metric=True
      )
      reporter5.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_UNSORTED in reporter5._output
  
      # Sort by metric when metric is passed using
      # reporter.setup (called from tune.run)
      # calling repoter.set_search_properties
      reporter6 = TestReporter(max_progress_rows=4, sort_by_metric=True)
      reporter6.set_search_properties(metric="metric_1", mode="max")
      reporter6.report(trials, done=False)
      assert EXPECTED_SORT_RESULT_DESC in reporter6._output
  
      # Sort by nested metric (asc)
      reporter7 = TestReporter(
          max_progress_rows=4,
          mode="min",
          metric="nested/metric_2",
          sort_by_metric=True,
          metric_columns=["nested/metric_2"],
      )
      reporter7.report(trials, done=False)
      assert EXPECTED_NESTED_SORT_RESULT in reporter7._output
  
imports: import collections
  import os
  import regex
  import unittest
  from unittest.mock import MagicMock, Mock, patch
  import pytest
  import numpy
  from ray import train, tune
  from ray._private.test_utils import run_string_as_driver
  from ray.tune.progress_reporter import CLIReporter, JupyterNotebookReporter, ProgressReporter, _fair_filter_trials, _best_trial_str, _detect_reporter, _time_passed_str, _trial_progress_str, TuneReporterBase, _max_len
  from ray.tune.result import AUTO_RESULT_KEYS
  from ray.tune.experiment.trial import Trial
label_desc: Use image node_id 12 for calling the ProgressReporterTest obj's underlying member method code with example usage: obj.testSortByMetric() without return types