class_docstr: Test class for output tests.
code: def check_grid_search_cv_results(self, task, do_grid_search):
      learners = ["LogisticRegression", "SVC"]
      expected_path = other_dir / "cv_results"
  
      def time_field(x):
          return x.endswith("_time")
  
      train_path = train_dir / "f0.jsonlines"
  
      exp_name = (
          f"test_grid_search_cv_results_{task}_"
          f'{"gs" if do_grid_search else "nogs"}'
      )
  
      # make a simple config file for cross-validation
      values_to_fill_dict = {
          "experiment_name": exp_name,
          "train_file": str(train_path),
          "task": task,
          "grid_search": json.dumps(do_grid_search),
          "grid_search_folds": "3",
          "objectives": "['f1_score_micro']",
          "featureset_names": "['f0']",
          "learners": json.dumps(learners),
          "logs": str(output_dir),
          "results": str(output_dir),
      }
      if task == "train":
          values_to_fill_dict["models"] = str(output_dir)
      elif task == "cross_validate":
          values_to_fill_dict["predictions"] = str(output_dir)
      elif task in ["evaluate", "predict"]:
          values_to_fill_dict["predictions"] = str(output_dir)
          values_to_fill_dict["test_file"] = values_to_fill_dict[
              "train_file"
          ]
  
      # In the case where grid search is on and the task is
      # learning curve, grid search will automatically be turned
      # off, so simply turn it off here as well since it should
      # result in the same situation
      elif task == "learning_curve":
          values_to_fill_dict["metrics"] = values_to_fill_dict.pop(
              "objectives"
          )
          if do_grid_search:
              do_grid_search = False
  
      config_template_path = config_dir / "test_cv_results.template.cfg"
  
      config_path = fill_in_config_options(
          config_template_path, values_to_fill_dict, task
      )
  
      # run the experiment
      if task in ["train", "predict"]:
          if do_grid_search:
              run_configuration(config_path, quiet=True, local=True)
          else:
              self.assertRaises(
                  ValueError, run_configuration, config_path, quiet=True
              )
              # Short-circuit the test since a ValueError is expected and is fatal
              return
      else:
          run_configuration(config_path, quiet=True, local=True)
  
      # now make sure that the results json file was produced
      for learner in learners:
          results_file_name = f"{exp_name}_f0_{learner}.results.json"
          actual_results_file_path = output_dir / results_file_name
          expected_results_file_path = expected_path / results_file_name
          self.assertTrue(actual_results_file_path.exists())
          with open(expected_results_file_path) as expected, open(
              actual_results_file_path
          ) as actual:
              expected_lines = [json.loads(line) for line in expected][
                  0
              ]
              actual_lines = [json.loads(line) for line in actual][0]
              assert len(expected_lines) == len(actual_lines)
              if task == "cross_validate":
                  # All but the last line will have grid search-related
                  # results
                  for (
                      expected_gs_cv_results,
                      actual_gs_cv_results,
                  ) in zip(expected_lines[:-1], actual_lines[:-1]):
                      assert len(expected_gs_cv_results) == len(
                          actual_gs_cv_results
                      )
                      for field in [
                          "grid_score",
                          "grid_search_cv_results",
                      ]:
                          if do_grid_search:
                              assert set(
                                  expected_gs_cv_results
                              ).intersection(
                                  actual_gs_cv_results
                              ) == set(
                                  expected_gs_cv_results
                              )
                              if field == "grid_score":
                                  assert (
                                      expected_gs_cv_results[field]
                                      == actual_gs_cv_results[field]
                                  )
                              else:
                                  for (
                                      subfield
                                  ) in expected_gs_cv_results[field]:
                                      if time_field(subfield):
                                          continue
                                      assert (
                                          expected_gs_cv_results[field][
                                              subfield
                                          ]
                                          == actual_gs_cv_results[
                                              field
                                          ][subfield]
                                      )
                          else:
                              if field == "grid_score":
                                  assert (
                                      actual_gs_cv_results[field] == 0.0
                                  )
                              else:
                                  assert (
                                      actual_gs_cv_results[field]
                                      is None
                                  )
                  # The last line should be for the "average" and should
                  # not contain any grid search results
                  assert actual_lines[-1]["fold"] == "average"
                  for field in ["grid_score", "grid_search_cv_results"]:
                      assert field not in actual_lines[-1]
              elif task == "evaluate":
                  for (
                      expected_gs_cv_results,
                      actual_gs_cv_results,
                  ) in zip(expected_lines, actual_lines):
                      assert len(expected_gs_cv_results) == len(
                          actual_gs_cv_results
                      )
                      for field in [
                          "grid_score",
                          "grid_search_cv_results",
                      ]:
                          if do_grid_search:
                              assert set(
                                  expected_gs_cv_results
                              ).intersection(
                                  actual_gs_cv_results
                              ) == set(
                                  expected_gs_cv_results
                              )
                              if field == "grid_score":
                                  assert (
                                      expected_gs_cv_results[field]
                                      == actual_gs_cv_results[field]
                                  )
                              else:
                                  for (
                                      subfield
                                  ) in expected_gs_cv_results[field]:
                                      if time_field(subfield):
                                          continue
                                      assert (
                                          expected_gs_cv_results[field][
                                              subfield
                                          ]
                                          == actual_gs_cv_results[
                                              field
                                          ][subfield]
                                      )
                          else:
                              if field == "grid_score":
                                  assert (
                                      actual_gs_cv_results[field] == 0.0
                                  )
                              else:
                                  assert (
                                      actual_gs_cv_results[field]
                                      is None
                                  )
              elif task in ["train", "predict"]:
                  expected_gs_cv_results = expected_lines
                  actual_gs_cv_results = actual_lines
                  assert set(expected_gs_cv_results).intersection(
                      actual_gs_cv_results
                  ) == set(expected_gs_cv_results)
                  for field in ["grid_score", "grid_search_cv_results"]:
                      if field == "grid_score":
                          assert (
                              expected_gs_cv_results[field]
                              == actual_gs_cv_results[field]
                          )
                      else:
                          for subfield in expected_gs_cv_results[field]:
                              if time_field(subfield):
                                  continue
                              assert (
                                  expected_gs_cv_results[field][
                                      subfield
                                  ]
                                  == actual_gs_cv_results[field][
                                      subfield
                                  ]
                              )
              else:
                  for expected_line, actual_line in zip(
                      expected_lines, actual_lines
                  ):
                      expected_fields = set(list(expected_line))
                      actual_fields = set(list(actual_line))
                      assert (
                          expected_fields.intersection(actual_fields)
                          == expected_fields
                      )
                      assert all(
                          field not in actual_fields
                          for field in [
                              "grid_score",
                              "grid_search_cv_results",
                          ]
                      )
  
imports: import csv
  import json
  import re
  import unittest
  import warnings
  from ast import literal_eval
  from collections import defaultdict
  from itertools import chain, product
  from pathlib import Path
  from unittest.mock import Mock, patch
  import numpy
  import pandas
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal
  from sklearn.model_selection import ShuffleSplit, learning_curve
  from sklearn.naive_bayes import MultinomialNB
  from skll.data import FeatureSet, NDJReader, NDJWriter, Reader
  from skll.experiments import run_configuration
  from skll.experiments.output import _compute_ylimits_for_featureset
  from skll.learner import Learner
  from skll.utils.constants import VALID_TASKS
  from skll.utils.logging import close_and_remove_logger_handlers, get_skll_logger
  from skll.utils.testing import backward_compatibility_dir, config_dir, create_jsonlines_feature_files, fill_in_config_options, fill_in_config_paths, fill_in_config_paths_for_single_file, make_classification_data, make_digits_data, make_regression_data, other_dir, output_dir, remove_jsonlines_feature_files, test_dir, tests_dir, train_dir, unlink
label_desc: Use image node_id 9 for calling the TestOutput obj's underlying member method code with example usage: obj.check_grid_search_cv_results(task, do_grid_search) and returns: x