def testGetCommandMetaData(self):
   command_group = self.my_cli.top_element
   command = command_group.LoadSubElement('test-command')
   meta_data = render_document.CommandMetaData(flags=['--bool-flag',
                                                      '--non-bool-flag'])
   for flag in meta_data.flags:
     self.assertIn(flag, calliope_actions.GetCommandMetaData(command).flags)
Exemple #2
0
  def testIgnoreNoEqualsInBoolFlag(self):
    markdown = textwrap.dedent("""\
      # NAME
      gcloud fake command - this is a brief summary

      # EXAMPLES
      To run the fake command, run:

        $ link:gcloud/fake/command/[gcloud fake command] positional \
          --non-bool value --bool positional

    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # EXAMPLE_PRESENT_CHECK SUCCESS
      # EXAMPLES_PRONOUN_CHECK SUCCESS
      # EXAMPLE_FLAG_EQUALS_CHECK FAILED: There should be an `=` between the """
                               """flag name and the value for the following """
                               """flags: --non-bool
      # EXAMPLE_NONEXISTENT_FLAG_CHECK SUCCESS
    """)
    meta_data = render_document.CommandMetaData(flags=['--bool', '--non-bool'],
                                                bool_flags=['--bool'],
                                                is_group=False)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #3
0
  def testMultilineCommandNameExampleCheck(self):
    markdown = textwrap.dedent("""\
      # NAME

      gcloud long fake command with-subcommands subcommand-one subcommand-2 -
      fake command to test throwing examples error

      # EXAMPLES

      Example where the name of the command does not fit in one line and is
      thus broken down into many lines:

          $ gcloud long fake command with-subcommands subcommand-one \\
            subcommand-2 \\
                command-arg --command-flag=flag-value
    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # EXAMPLE_PRESENT_CHECK SUCCESS
      # EXAMPLES_PRONOUN_CHECK SUCCESS
      # EXAMPLE_FLAG_EQUALS_CHECK SUCCESS
      # EXAMPLE_NONEXISTENT_FLAG_CHECK SUCCESS
      There are no errors for the EXAMPLES section.
    """)
    meta_data = render_document.CommandMetaData(is_group=False)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #4
0
  def testGoodCommand(self):
    markdown = textwrap.dedent("""\
      # NAME
      gcloud fake command - this is a brief summary with no personal pronouns.

      # DESCRIPTION

      gcloud fake command is a filler command that does not exist. There are no
      personal pronouns in this description.

      # EXAMPLES

      To run the fake command, run:

        $ link:gcloud/fake/command/[gcloud fake command] positional

      This also has no personal pronouns and the example command starts with the
      command name.
    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # DESCRIPTION_PRONOUN_CHECK SUCCESS
      There are no errors for the DESCRIPTION section.
      # EXAMPLE_PRESENT_CHECK SUCCESS
      # EXAMPLES_PRONOUN_CHECK SUCCESS
      # EXAMPLE_FLAG_EQUALS_CHECK SUCCESS
      # EXAMPLE_NONEXISTENT_FLAG_CHECK SUCCESS
      There are no errors for the EXAMPLES section.
    """)
    meta_data = render_document.CommandMetaData(is_group=False)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #5
0
  def testNotValidFlagForCommandEmptyFlag(self):
    markdown = textwrap.dedent("""\
      # NAME

      gcloud fake command - this is a brief summary

      # EXAMPLES
      To run the fake command, run:

        $ link:gcloud/fake/command/[gcloud fake command] \
        positional -- other things for command args

    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # EXAMPLE_PRESENT_CHECK SUCCESS
      # EXAMPLES_PRONOUN_CHECK SUCCESS
      # EXAMPLE_FLAG_EQUALS_CHECK SUCCESS
      # EXAMPLE_NONEXISTENT_FLAG_CHECK SUCCESS
      There are no errors for the EXAMPLES section.
    """)
    meta_data = render_document.CommandMetaData(flags=['--good-flag-name'],
                                                is_group=False)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #6
0
def GetCommandMetaData(command):
    command_metadata = render_document.CommandMetaData()
    for arg in command.GetAllAvailableFlags():
        for arg_name in arg.option_strings:
            command_metadata.flags.append(arg_name)
            if isinstance(arg, argparse._StoreConstAction):
                command_metadata.bool_flags.append(arg_name)
    command_metadata.is_group = command.is_group
    return command_metadata
Exemple #7
0
  def testNotHeadingToLint(self):
    markdown = textwrap.dedent("""\
      # NAME
      gcloud fake command - this is a brief summary

      # NOT A HEADING TO KEEP

      this is the filler text for the section not being kept
    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
    """)
    meta_data = render_document.CommandMetaData(is_group=True)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #8
0
  def testPersonalPronoun(self, help_text, pronouns):
    markdown = textwrap.dedent("""\
      # NAME
      gcloud fake command group - this is a brief summary

      # DESCRIPTION
      this is the description section that has personal pronouns..."""
                               + help_text + '\n')
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # DESCRIPTION_PRONOUN_CHECK FAILED: Please remove the following """
                               """personal pronouns in the DESCRIPTION section:
      """)
    expected += pronouns + '\n'
    meta_data = render_document.CommandMetaData(is_group=True)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #9
0
  def testLongCommandWithDescription(self):
    markdown = textwrap.dedent("""\
      # NAME
      gcloud fake command that is very long and takes up the whole line blah -
      this is a brief summary with no personal pronouns.

      # DESCRIPTION

      gcloud fake command is a filler command that does not exist. There are no
      personal pronouns in this description.
    """)
    expected = textwrap.dedent("""\
      # NAME_PRONOUN_CHECK SUCCESS
      # NAME_DESCRIPTION_CHECK SUCCESS
      # NAME_LENGTH_CHECK SUCCESS
      There are no errors for the NAME section.
      # DESCRIPTION_PRONOUN_CHECK SUCCESS
      There are no errors for the DESCRIPTION section.
    """)
    meta_data = render_document.CommandMetaData(is_group=True)
    self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #10
0
 def testNoExamples(self, markdown, expected, is_group):
   meta_data = render_document.CommandMetaData(is_group=is_group)
   self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)
Exemple #11
0
 def testNameSection(self, markdown, expected):
   meta_data = render_document.CommandMetaData(is_group=True)
   self.Run('linter', markdown, expected, notes='', command_metadata=meta_data)