def testArgsForGcloudNormal(self):
     self.StartEnvPatch({}, clear=True)
     self.StartObjectPatch(sys, 'executable', new='/path/to/python')
     gcloud_path_mock = self.StartObjectPatch(config, 'GcloudPath')
     gcloud_path_mock.return_value = '/abc/def/gcloud.py'
     self.assertEqual(execution_utils.ArgsForGcloud(),
                      ['/path/to/python', '/abc/def/gcloud.py'])
def _RunGcloud(args):
    """Runs a gcloud command.

  Args:
    args: command line arguments to pass to gcloud

  Returns:
    The contents of stdout if the return code is 0, stderr (or a fabricated
    error if stderr is empty) otherwise
  """
    cmd = execution_utils.ArgsForGcloud()
    cmd.extend(args)
    out = io.StringIO()
    err = io.StringIO()
    env = _GetEnvs()
    returncode = execution_utils.Exec(cmd,
                                      no_exit=True,
                                      out_func=out.write,
                                      err_func=err.write,
                                      in_str=None,
                                      env=env)

    if returncode != 0 and not err.getvalue():
        err.write('gcloud exited with return code {}'.format(returncode))
    return out.getvalue() if returncode == 0 else None, err.getvalue(
    ) if returncode != 0 else None
 def testArgsForGcloudHermeticPar(self):
     self.StartEnvPatch({}, clear=True)
     self.StartObjectPatch(sys, 'executable', new=None)
     self.StartObjectPatch(sys, 'argv', new=['/abc/def/gcloud.par', 'info'])
     self.assertEqual(execution_utils.ArgsForGcloud(),
                      ['/abc/def/gcloud.par'])