コード例 #1
0
    def testUpdateTableHappensOnFirstRun(self):
        """Test that Search updates table if it doesn't exist, not every time."""
        # Mock that CLI tree path import fails.
        import_module_mock = self.StartObjectPatch(module_util, 'ImportModule')
        import_module_mock.side_effect = module_util.ImportModuleError
        table_update_mock = self.StartObjectPatch(cli_tree, 'Dump')

        # The table update should happen when the table doesn't exist, but SetUp()
        # already created it, so we don't expect any more updates.
        search.RunSearch(['term'], self.test_cli)
        table_update_mock.assert_not_called()

        # The table update shouldn't happen again.
        import_module_mock.side_effect = None
        search.RunSearch(['otherterm'], self.test_cli)
        table_update_mock.assert_not_called()
コード例 #2
0
 def testRunSearchMultipleTerms(self):
     """Overall test of search with three search terms."""
     sdk = copy.deepcopy(self.sdk)
     sdk.update({
         lookup.COMMANDS: [
             'long-help', 'second-level-command-1',
             'second-level-command-b', 'subgroup', 'xyzzy'
         ],
         lookup.RESULTS: {
             'second': 'capsule',
             'xyzzy': 'commands',
             'long': 'commands'
         },
         lookup.RELEVANCE:
         0.25**3
     })
     xyzzy = copy.deepcopy(self.xyzzy)
     xyzzy.update({
         lookup.COMMANDS: [],
         lookup.RESULTS: {
             'xyzzy': lookup.NAME
         },
         lookup.RELEVANCE: 1.0 * (0.1**2)
     })
     result = search.RunSearch(['second', 'xyzzy', 'long'], self.test_cli)
     self.assertIn(sdk, result)
     self.assertIn(xyzzy, result)
     self.assertEqual(
         {
             'xyzzy', 'sdk', 'long-help', 'second-level-command-b',
             'second-level-command-1'
         }, set([command[lookup.NAME] for command in result]))
コード例 #3
0
 def testSdkRootError(self):
     """Test that Search runs with cli if help index not available."""
     # Mock that there is an error getting the SDK root.
     self.StartObjectPatch(cli_tree,
                           'CliTreePath',
                           side_effect=cli_tree.SdkRootNotFoundError)
     table_update_mock = self.StartObjectPatch(cli_tree, 'Dump')
     results = search.RunSearch(['long-help'], self.test_cli)
     # The table update should not happen in this case.
     table_update_mock.assert_not_called()
     self.AssertErrContains(
         'Generating the gcloud CLI for one-time use (no SDK root)')
     # Assert that results are found.
     self.assertEqual({'gcloud sdk long-help', 'gcloud sdk'},
                      set([' '.join(c[lookup.PATH]) for c in results]))
コード例 #4
0
ファイル: help.py プロジェクト: Akiho-Yasuda/wip
    def Run(self, args):
        if not args.search_terms:
            try:
                # --document=style=help to signal the metrics.Help() 'help' label in
                # actions.RenderDocumentAction().Action().
                self.ExecuteCommandDoNotUse(args.command +
                                            ['--document=style=help'])
                return None
            except Exception:  # pylint: disable=broad-except
                # In this case, we will treat the arguments as search terms.
                pass

        results = search.RunSearch(args.command + (args.search_terms or []),
                                   self._cli_power_users_only)
        self._resources_found = len(results)
        self._resources_displayed = min(len(results), args.limit)
        return results
コード例 #5
0
ファイル: help.py プロジェクト: Guliux10/bchacks_deepbreath
  def Run(self, args):
    if not args.search_terms:
      try:
        # --document=style=help to signal the metrics.Help() 'help' label in
        # actions.RenderDocumentAction().Action().
        self.ExecuteCommandDoNotUse(args.command + ['--document=style=help'])
        return None
      except Exception:  # pylint: disable=broad-except
        # In this case, we will treat the arguments as search terms.
        pass

    results = search.RunSearch(
        args.command + (args.search_terms or []),
        self._cli_power_users_only)

    def _filter(a, b, filtered_list):
      """Recognize duplicates and list only the highest track GA>BETA>ALPHA.

      Args:
        a: line to compare
        b: line to compare
        filtered_list: filtered_list: copy of the list to filter

      Returns: None

      """

      if a['results'] == b['results'] and a['release'] > b['release']:
        try:
          filtered_list.remove(b)
        except ValueError:
          pass
      elif a['results'] == b['results'] and a['release'] < b['release']:
        try:
          filtered_list.remove(a)
        except ValueError:
          pass

    filtered_results = copy.deepcopy(results)
    for a, b in itertools.combinations(results, 2):
      _filter(a, b, filtered_results)

    self._resources_found = len(filtered_results)
    self._resources_displayed = min(len(filtered_results), args.limit)
    return filtered_results
コード例 #6
0
    def testRunSearchSingleTerm(self):
        """Overall test of search with one term."""
        long_help = copy.deepcopy(self.long_help)
        long_help.update({
            lookup.RESULTS: {
                'castle': 'sections.DESCRIPTION'
            },
            lookup.COMMANDS: [],
            lookup.RELEVANCE: 0.25
        })
        alpha = copy.deepcopy(
            self.parent.get(lookup.COMMANDS, {}).get('alpha', {}).get(
                lookup.COMMANDS, {}).get('sdk',
                                         {}).get(lookup.COMMANDS,
                                                 {}).get('long-help', {}))
        alpha.update({
            lookup.RESULTS: {
                'castle': 'sections.DESCRIPTION'
            },
            lookup.COMMANDS: [],
            lookup.RELEVANCE: 0.25 * (0.1**2)
        })

        beta = copy.deepcopy(
            self.parent.get(lookup.COMMANDS, {}).get('beta', {}).get(
                lookup.COMMANDS, {}).get('sdk',
                                         {}).get(lookup.COMMANDS,
                                                 {}).get('long-help', {}))
        beta.update({
            lookup.RESULTS: {
                'castle': 'sections.DESCRIPTION'
            },
            lookup.COMMANDS: [],
            lookup.RELEVANCE: 0.25 * 0.1
        })

        result = search.RunSearch(['castle'], self.test_cli)
        self.assertIn(long_help, result)
        self.assertEqual(1, len(result))
コード例 #7
0
 def Run(self, args):
   return search.RunSearch([args.term], self._cli_power_users_only)