Ejemplo n.º 1
0
 def testPossiblyGetResultCommandGroupSubCommands(self):
     """Test command groups don't match if term is only present in subcommand."""
     # A term that would match for a command in a group should not match
     # the command group (except the command's name)
     # 'eureka' is a positional arg for one of the commands in the subgroup.
     searcher = search.Searcher({}, ['eureka'])
     result = searcher._PossiblyGetResult(self.subgroup)  # pylint: disable=protected-access
     self.assertIsNone(result)
Ejemplo n.º 2
0
 def testPossiblyGetResultMultipleTermsOnePresent(self):
     """Test we get a result where one term is present and one term is not."""
     searcher = search.Searcher({}, ['phoebe', 'tarantula'])
     expected_result = copy.deepcopy(self.xyzzy)
     expected_result.update({
         lookup.RESULTS: {
             'phoebe': 'flags.--three-choices.choices'
         },
         lookup.COMMANDS: []
     })
     self.assertEqual(expected_result,
                      searcher._PossiblyGetResult(self.xyzzy))  # pylint: disable=protected-access
Ejemplo n.º 3
0
 def testPossiblyGetResultSingleTermPositional(self):
     """Test _PossiblyGetResult with a single term that matches a positional."""
     searcher = search.Searcher({}, ['pdq'])
     result = searcher._PossiblyGetResult(self.xyzzy)  # pylint: disable=protected-access
     expected_result = copy.deepcopy(self.xyzzy)
     expected_result.update({
         lookup.RESULTS: {
             'pdq': 'positionals.pdq.name'
         },
         lookup.COMMANDS: []
     })
     self.assertEqual(expected_result, result)
Ejemplo n.º 4
0
 def testPossiblyGetResultSingleTerm(self):
     """Test _PossiblyGetResult with a single term that does match."""
     searcher = search.Searcher({}, ['phoebe'])
     result = searcher._PossiblyGetResult(self.xyzzy)  # pylint: disable=protected-access
     expected_result = copy.deepcopy(self.xyzzy)
     expected_result.update({
         lookup.RESULTS: {
             'phoebe': 'flags.--three-choices.choices'
         },
         lookup.COMMANDS: []
     })
     self.assertEqual(expected_result, result)
Ejemplo n.º 5
0
 def testPossiblyGetResultMultipleTermsBothFound(self):
     """Test _PossiblyGetResult with multiple terms."""
     searcher = search.Searcher({}, ['phoebe', 'components'])
     result = searcher._PossiblyGetResult(self.xyzzy)  # pylint: disable=protected-access
     expected_result = copy.deepcopy(self.xyzzy)
     expected_result.update({
         lookup.RESULTS: {
             'phoebe': 'flags.--three-choices.choices',
             'components': 'sections.EXAMPLES'
         },
         lookup.COMMANDS: []
     })
     self.assertEqual(expected_result, result)
Ejemplo n.º 6
0
 def testPossiblyGetResultSingleTermFlagDefault(self):
     """Test _PossiblyGetResult with a single term that matches a flag default.
 """
     searcher = search.Searcher({}, ['moe'])
     result = searcher._PossiblyGetResult(self.xyzzy)  # pylint: disable=protected-access
     expected_result = copy.deepcopy(self.xyzzy)
     expected_result.update({
         lookup.RESULTS: {
             'moe': 'flags.--exactly-three.default'
         },
         lookup.COMMANDS: []
     })
     self.assertEqual(expected_result, result)
Ejemplo n.º 7
0
 def testPossiblyGetResultCommandGroup(self):
     """Test _PossiblyGetResult works with a command group."""
     searcher = search.Searcher({}, ['xyzzy', 'second'])
     result = searcher._PossiblyGetResult(self.sdk)  # pylint: disable=protected-access
     expected_result = copy.deepcopy(self.sdk)
     expected_result.update({
         lookup.RESULTS: {
             'xyzzy': 'commands',
             'second': 'capsule'
         },
         lookup.COMMANDS: [
             'long-help', 'second-level-command-1',
             'second-level-command-b', 'subgroup', 'xyzzy'
         ]
     })
     self.assertEqual(expected_result, result)
Ejemplo n.º 8
0
    def testRunSearchWalksAllCommands(self):
        """Test that all commands are hit by Search."""
        def FakeSearch(command):
            return ' '.join(command[lookup.PATH])

        self.StartObjectPatch(search.Searcher,
                              '_PossiblyGetResult',
                              side_effect=FakeSearch)
        searcher = search.Searcher(parent=cli_tree.Load(cli=self.test_cli,
                                                        one_time_use_ok=True),
                                   terms=['term'])
        self.assertEqual([
            'gcloud',
            'gcloud alpha',
            'gcloud alpha internal',
            'gcloud alpha internal internal-command',
            'gcloud alpha sdk',
            'gcloud alpha sdk alphagroup',
            'gcloud alpha sdk alphagroup alpha-command',
            'gcloud alpha sdk hidden-command',
            'gcloud alpha sdk hiddengroup',
            'gcloud alpha sdk hiddengroup hidden-command-2',
            'gcloud alpha sdk hiddengroup hidden-command-a',
            'gcloud alpha sdk long-help',
            'gcloud alpha sdk second-level-command-1',
            'gcloud alpha sdk second-level-command-b',
            'gcloud alpha sdk subgroup',
            'gcloud alpha sdk subgroup subgroup-command-2',
            'gcloud alpha sdk subgroup subgroup-command-a',
            'gcloud alpha sdk xyzzy',
            'gcloud alpha version',
            'gcloud beta',
            'gcloud beta internal',
            'gcloud beta internal internal-command',
            'gcloud beta sdk',
            'gcloud beta sdk betagroup',
            'gcloud beta sdk betagroup beta-command',
            'gcloud beta sdk betagroup sub-command-2',
            'gcloud beta sdk betagroup sub-command-a',
            'gcloud beta sdk hidden-command',
            'gcloud beta sdk hiddengroup',
            'gcloud beta sdk hiddengroup hidden-command-2',
            'gcloud beta sdk hiddengroup hidden-command-a',
            'gcloud beta sdk long-help',
            'gcloud beta sdk second-level-command-1',
            'gcloud beta sdk second-level-command-b',
            'gcloud beta sdk subgroup',
            'gcloud beta sdk subgroup subgroup-command-2',
            'gcloud beta sdk subgroup subgroup-command-a',
            'gcloud beta sdk xyzzy',
            'gcloud beta version',
            'gcloud internal',
            'gcloud internal internal-command',
            'gcloud sdk',
            'gcloud sdk hidden-command',
            'gcloud sdk hiddengroup',
            'gcloud sdk hiddengroup hidden-command-2',
            'gcloud sdk hiddengroup hidden-command-a',
            'gcloud sdk long-help',
            'gcloud sdk second-level-command-1',
            'gcloud sdk second-level-command-b',
            'gcloud sdk subgroup',
            'gcloud sdk subgroup subgroup-command-2',
            'gcloud sdk subgroup subgroup-command-a',
            'gcloud sdk xyzzy',
            'gcloud version',
        ], sorted(searcher._WalkTree(searcher.parent, [])))
Ejemplo n.º 9
0
 def testPossiblyGetResultNotResult(self):
     """Test _PossiblyGetResult returns None when no match is found."""
     searcher = search.Searcher({}, ['tarantula'])
     self.assertIsNone(searcher._PossiblyGetResult(self.xyzzy))  # pylint: disable=protected-access
     searcher = search.Searcher({}, ['phoebe'])
     self.assertIsNone(searcher._PossiblyGetResult(self.long_help))  # pylint: disable=protected-access