code: def test_tuner_dataframe(has_training_job_definition_name):
      training_job_definition_name = "training_def_1"
  
      def mock_summary(name="job-name", value=0.9):
          summary = {
              "TrainingJobName": name,
              "TrainingJobStatus": "Completed",
              "FinalHyperParameterTuningJobObjectiveMetric": {
                  "Name": "awesomeness",
                  "Value": value,
              },
              "TrainingStartTime": datetime.datetime(
                  2018, 5, 16, 1, 2, 3
              ),
              "TrainingEndTime": datetime.datetime(
                  2018, 5, 16, 5, 6, 7
              ),
              "TunedHyperParameters": {
                  "learning_rate": 0.1,
                  "layers": 137,
              },
          }
  
          if has_training_job_definition_name:
              summary[
                  "TrainingJobDefinitionName"
              ] = training_job_definition_name
          return summary
  
      session = create_sagemaker_session(
          list_training_results={
              "TrainingJobSummaries": [
                  mock_summary(),
                  mock_summary(),
                  mock_summary(),
                  mock_summary(),
                  mock_summary(),
              ]
          }
      )
  
      tuner = HyperparameterTuningJobAnalytics(
          "my-tuning-job", sagemaker_session=session
      )
      df = tuner.dataframe()
      assert df is not None
      assert len(df) == 5
      assert (
          len(
              session.sagemaker_client.list_training_jobs_for_hyper_parameter_tuning_job.mock_calls
          )
          == 1
      )
  
      # Clear the cache, check that it calls the service again.
      tuner.clear_cache()
      df = tuner.dataframe()
      assert (
          len(
              session.sagemaker_client.list_training_jobs_for_hyper_parameter_tuning_job.mock_calls
          )
          == 2
      )
      df = tuner.dataframe(force_refresh=True)
      assert (
          len(
              session.sagemaker_client.list_training_jobs_for_hyper_parameter_tuning_job.mock_calls
          )
          == 3
      )
  
      # check that the hyperparameter is in the dataframe
      assert len(df["layers"]) == 5
      assert min(df["layers"]) == 137
  
      # Check that the training time calculation is returning something sane.
      assert min(df["TrainingElapsedTimeSeconds"]) > 5
      assert max(df["TrainingElapsedTimeSeconds"]) < 86400
  
      if has_training_job_definition_name:
          for index in range(0, 5):
              assert (
                  df["TrainingJobDefinitionName"][index]
                  == training_job_definition_name
              )
      else:
          assert "TrainingJobDefinitionName" not in df
  
      # Export to CSV and check that file exists
      tmp_name = "/tmp/unit-test-%s.csv" % uuid.uuid4()
      assert not os.path.isfile(tmp_name)
      tuner.export_csv(tmp_name)
      assert os.path.isfile(tmp_name)
      os.unlink(tmp_name)
  
imports: from __future__ import absolute_import
  import datetime
  import os
  import uuid
  import pytest
  from mock import Mock
  from sagemaker.analytics import AnalyticsMetricsBase, HyperparameterTuningJobAnalytics, TrainingJobAnalytics
  from sagemaker.session_settings import SessionSettings
label_desc: Use image node_id 8 for calling a global function with example usage: test_tuner_dataframe(has_training_job_definition_name) and returns: summary