code: def test_apply_history_best(tmpdir):
      tsk, target = get_sample_task()
      best = str(tsk.config_space.get(2))
  
      inputs_batch_1 = [
          MeasureInput(target, tsk, tsk.config_space.get(i))
          for i in range(3)
      ]
      results_batch_1 = [
          MeasureResult((i,), 0, 0, 0) for i in range(1, 3)
      ]
      results_batch_1.append(MeasureResult((0.5,), 0, 2.3, 0))
  
      # Write data out to file
      filepath_batch_1 = tmpdir / "batch_1.log"
      with open(filepath_batch_1, "w") as file:
          autotvm.callback.log_to_file(file)(
              None, inputs_batch_1, results_batch_1
          )
  
      # Load best results from Path
      assert isinstance(filepath_batch_1, PathLike)
      hist_best = ApplyHistoryBest(filepath_batch_1)
      assert str(hist_best.query(target, tsk.workload)) == best
  
      # Load best results from str(Path)
      hist_best = ApplyHistoryBest(str(filepath_batch_1))
      assert str(hist_best.query(target, tsk.workload)) == best
  
      # Write data into StringIO buffer
      stringio_batch_1 = StringIO()
      assert isinstance(filepath_batch_1, PathLike)
      callback = autotvm.callback.log_to_file(stringio_batch_1)
      callback(None, inputs_batch_1, results_batch_1)
      stringio_batch_1.seek(0)
  
      # Load best results from strIO
      hist_best = ApplyHistoryBest(stringio_batch_1)
      assert str(hist_best.query(target, tsk.workload)) == best
  
      # Load best result from list of tuples (MeasureInput, MeasureResult)
      hist_best = ApplyHistoryBest(
          list(zip(inputs_batch_1, results_batch_1))
      )
      assert str(hist_best.query(target, tsk.workload)) == best
  
      # Same thing, but iterable instead of list (i.e. no subscripting)
      hist_best = ApplyHistoryBest(zip(inputs_batch_1, results_batch_1))
      assert str(hist_best.query(target, tsk.workload)) == best
  
file_path: tvm/tests/python/autotvm/test_autotvm_record.py
imports: from io import StringIO
  from os import PathLike
  import time
  from tvm.contrib import utils
  from tvm import autotvm
  from tvm.autotvm.measure import MeasureInput, MeasureResult, MeasureErrorNo
  from tvm.autotvm.record import encode, decode, ApplyHistoryBest, measure_str_key
  from tvm.testing.autotvm import get_sample_task
label_desc: Use image node_id 3 for calling a global function with example usage: test_apply_history_best(tmpdir) without return types