class_docstr: Test ParlaiParser.
class_docstr_tok: ["Test","ParlaiParser","."]
docstr: Tests whether opt presets bundled with parlai work as expected.
docstr_tok: ["Tests","whether","opt","presets","bundled","with","parlai","work","as","expected","."]
code: def test_opt_presets(self):
      """
      Tests whether opt presets bundled with parlai work as expected.
      """
      pp = ParlaiParser(True, False)
      pp.add_argument("-m", "--model")
      # hardcoded example
      opt = pp.parse_args(
          ["--model", "transformer/generator", "-o", "gen/meena"]
      )
      assert opt["beam_size"] == 20
      assert opt["inference"] == "topk"
      assert opt["topk"] == 40
      # and preference for command line over opt presets
      pp = ParlaiParser(True, False)
      pp.add_argument("-m", "--model")
      opt = pp.parse_args(
          [
              "--model",
              "transformer/generator",
              "-o",
              "gen/meena",
              "--topk",
              "7",
          ]
      )
      assert opt["beam_size"] == 20
      assert opt["inference"] == "topk"
      assert opt["topk"] == 7
      # double check ordering doesn't matter
      pp = ParlaiParser(True, False)
      pp.add_argument("-m", "--model")
      opt = pp.parse_args(
          [
              "--model",
              "transformer/generator",
              "--topk",
              "8",
              "-o",
              "gen/meena",
          ]
      )
      assert opt["beam_size"] == 20
      assert opt["inference"] == "topk"
      assert opt["topk"] == 8
      # check composability
      pp = ParlaiParser(True, False)
      pp.add_argument("-m", "--model")
      opt = pp.parse_args(["-o", "arch/blenderbot_3B,gen/meena"])
      assert opt["beam_size"] == 20
      assert opt["inference"] == "topk"
      assert opt["model"] == "transformer/generator"
      assert opt["n_encoder_layers"] == 2
  
imports: import os
  import json
  import unittest
  from parlai.core.params import ParlaiParser
  import parlai.core.agents
  import parlai.utils.testing
label_desc: Use image node_id 2 for calling the TestParlaiParser obj's underlying member method code with example usage: obj.test_opt_presets() without return types