docstr: Test "final_extra_valid_opt_filepath". Happens to test that saving reports as
  json works too.
  
  We copy train_model from testing_utils to directly access train loop.
docstr_tok: ["Test","``","final_extra_valid_opt_filepath","''",".","Happens","to","test","that","saving","reports","as","json","works","too",".","We","copy","train_model","from","testing_utils","to","directly","access","train","loop","."]
code: def test_final_extra_eval_and_save_json(self):
      """
      Test "final_extra_valid_opt_filepath". Happens to test that saving reports as
      json works too.
  
      We copy train_model from testing_utils to directly access train loop.
      """
      import parlai.scripts.train_model as tms
  
      def get_tl(tmpdir):
          final_opt = Opt(
              {
                  "task": "integration_tests",
                  "datatype": "valid",
                  "validation_max_exs": 30,
                  "short_final_eval": True,
              }
          )
          final_opt.save(os.path.join(tmpdir, "final_opt.opt"))
  
          opt = Opt(
              {
                  "task": "integration_tests",
                  "validation_max_exs": 10,
                  "model": "repeat_label",
                  "model_file": os.path.join(tmpdir, "model"),
                  "short_final_eval": True,
                  "num_epochs": 1.0,
                  "final_extra_opt": str(
                      os.path.join(tmpdir, "final_opt.opt")
                  ),
              }
          )
          parser = tms.setup_args()
          parser.set_params(**opt)
          popt = parser.parse_args([])
          for k, v in opt.items():
              popt[k] = v
          return tms.TrainLoop(popt)
  
      with testing_utils.capture_output(), testing_utils.tempdir() as tmpdir:
          tl = get_tl(tmpdir)
          _, _ = tl.train()
  
          with open(os.path.join(tmpdir, "model.trainstats")) as f:
              data = json.load(f)
              print(data)
              self.assertEqual(
                  data["final_valid_report"]["exs"],
                  10,
                  "Validation exs saved incorrectly",
              )
  
              self.assertEqual(
                  data["final_extra_valid_report"]["exs"],
                  30,
                  "Final validation exs saved incorrectly",
              )
  
imports: import os
  import unittest
  import json
  import parlai.utils.logging
  import parlai.utils.testing
  from parlai.utils.io import PathManager
  from parlai.core.metrics import AverageMetric
  from parlai.core.worlds import create_task
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.core.agents import register_agent, Agent
  from parlai.scripts.eval_model import get_task_world_logs
label_desc: Use image node_id 1 for calling the TestTrainModel obj's underlying member method code with example usage: obj.test_final_extra_eval_and_save_json() and returns: tms