Exemplo n.º 1
0
 def fn(c, e, un):
   try:
     # With shell=True, it needs a string.
     subprocess2.communicate(' '.join(self.exe), timeout=0.01, shell=True)
     self.fail()
   except TypeError:
     pass
Exemplo n.º 2
0
 def fn(c, e, un):
   try:
     # With shell=True, it needs a string.
     subprocess2.communicate(' '.join(self.exe), timeout=0.01, shell=True)
     self.fail()
   except TypeError:
     pass
Exemplo n.º 3
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=VOID,
       stderr=STDOUT,
       universal_newlines=un)
   self._check_res(res, None, None, 0)
Exemplo n.º 4
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=VOID,
       stderr=PIPE,
       universal_newlines=un)
   self._check_res(res, None, c('a\nbb\nccc\n'), 0)
Exemplo n.º 5
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=PIPE,
       stderr=VOID,
       universal_newlines=un)
   self._check_res(res, c('A\nBB\nCCC\n'), None, 0)
Exemplo n.º 6
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=VOID,
       stderr=STDOUT,
       universal_newlines=un)
   self._check_res(res, None, None, 0)
Exemplo n.º 7
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=VOID,
       stderr=PIPE,
       universal_newlines=un)
   self._check_res(res, None, c('a\nbb\nccc\n'), 0)
Exemplo n.º 8
0
 def fn(c, e, un):
   stdin = ''
   res = subprocess2.communicate(
       e + ['--read'],
       stdin=stdin,
       universal_newlines=un)
   self._check_res(res, None, None, 0)
Exemplo n.º 9
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       self.exe + ['--sleep_first', '--stdout'],
       timeout=0.01,
       stdout=PIPE,
       shell=False)
   self._check_res(res, '', None, TIMED_OUT)
Exemplo n.º 10
0
 def fn(c, e, un):
   stdin = ''
   res = subprocess2.communicate(
       e + ['--read'],
       stdin=stdin,
       universal_newlines=un)
   self._check_res(res, None, None, 0)
Exemplo n.º 11
0
 def test_tee_large_stdin(self):
   stdout = []
   # Write 128kb.
   stdin = '0123456789abcdef' * (8*1024)
   res = subprocess2.communicate(
       self.exe + ['--large', '--read'], stdin=stdin, stdout=stdout.append)
   self.assertEquals(128*1024, len(''.join(stdout)))
   self._check_res(res, None, None, 0)
Exemplo n.º 12
0
 def test_tee_large_stdin(self):
   stdout = []
   # Write 128kb.
   stdin = '0123456789abcdef' * (8*1024)
   res = subprocess2.communicate(
       self.exe + ['--large', '--read'], stdin=stdin, stdout=stdout.append)
   self.assertEquals(128*1024, len(''.join(stdout)))
   self._check_res(res, None, None, 0)
Exemplo n.º 13
0
 def test_timeout(self):
   # It'd be better to not discard stdout.
   out, returncode = subprocess2.communicate(
       self.exe + ['--sleep', '--stdout'],
       timeout=0.01,
       stdout=subprocess2.PIPE)
   self.assertEquals(subprocess2.TIMED_OUT, returncode)
   self.assertEquals(['', None], out)
Exemplo n.º 14
0
 def test_stdout_void(self):
   (out, err), code = subprocess2.communicate(
        self.exe + ['--stdout', '--stderr'],
        stdout=subprocess2.VOID,
        stderr=subprocess2.PIPE)
   self.assertEquals(None, out)
   self.assertEquals('a\nbb\nccc\n', err)
   self.assertEquals(0, code)
Exemplo n.º 15
0
 def test_communicate_defaults(self):
   results = self._fake_Popen()
   self.assertEquals(
       ((None, None), -8), subprocess2.communicate(['foo'], a=True))
   expected = {
       'args': ['foo'],
       'a': True,
   }
   self.assertEquals(expected, results)
Exemplo n.º 16
0
 def test_stderr_void(self):
   (out, err), code = subprocess2.communicate(
        self.exe + ['--stdout', '--stderr'],
        universal_newlines=True,
        stdout=subprocess2.PIPE,
        stderr=subprocess2.VOID)
   self.assertEquals('A\nBB\nCCC\n', out)
   self.assertEquals(None, err)
   self.assertEquals(0, code)
Exemplo n.º 17
0
 def fn(c, e, un):
   res = subprocess2.communicate(
       e + ['--stdout', '--read'],
       stdin=VOID,
       stdout=PIPE,
       timeout=10,
       universal_newlines=un,
       shell=False)
   self._check_res(res, c('A\nBB\nCCC\n'), None, 0)
Exemplo n.º 18
0
 def test_tee_large_stdin(self):
   stdout = []
   # Write 128kb.
   stdin = '0123456789abcdef' * (8*1024)
   res = subprocess2.communicate(
       self.exe + ['--large', '--read'], stdin=stdin, stdout=stdout.append)
   self.assertEquals(128*1024, len(''.join(stdout)))
   # Windows return code is > 8 bits.
   returncode = len(stdin) if sys.platform == 'win32' else 0
   self._check_res(res, None, None, returncode)
Exemplo n.º 19
0
 def fn(c, e, un):
   stdout = []
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr', '--fail'],
       stdout=stdout.append,
       stderr=VOID,
       shell=False,
       timeout=10,
       universal_newlines=un)
   self._check_res(res, None, None, 64)
   self.assertEquals(c('A\nBB\nCCC\n'), ''.join(stdout))
Exemplo n.º 20
0
 def fn(c, e, un):
   # Mix of stdin input and stdout callback.
   stdout = []
   stdin = '0123456789'
   res = subprocess2.communicate(
       e + ['--stdout', '--read'],
       stdin=stdin,
       stdout=stdout.append,
       universal_newlines=un)
   self.assertEquals(c('A\nBB\nCCC\n'), ''.join(stdout))
   self._check_res(res, None, None, 10)
Exemplo n.º 21
0
def CallCommand(cmd_data):
  # multiprocessing needs a top level function with a single argument.
  cmd_data.kwargs['stdout'] = subprocess.PIPE
  cmd_data.kwargs['stderr'] = subprocess.STDOUT
  try:
    (out, _), code = subprocess.communicate(cmd_data.cmd, **cmd_data.kwargs)
    if code != 0:
      return cmd_data.message('%s failed\n%s' % (cmd_data.name, out))
  except OSError as e:
    return cmd_data.message(
        '%s exec failure\n   %s' % (cmd_data.name, e))
Exemplo n.º 22
0
 def fn(c, e, un):
   stdout = []
   stderr = []
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr'],
       stdout=stdout.append,
       stderr=stderr.append,
       universal_newlines=un)
   self.assertEquals(c('A\nBB\nCCC\n'), ''.join(stdout))
   self.assertEquals(c('a\nbb\nccc\n'), ''.join(stderr))
   self._check_res(res, None, None, 0)
Exemplo n.º 23
0
 def fn(c, e, un):
   stdout = []
   res = subprocess2.communicate(
       e + ['--stdout', '--stderr', '--fail'],
       stdout=stdout.append,
       stderr=STDOUT,
       shell=False,
       timeout=10,
       universal_newlines=un)
   self._check_res(res, None, None, 64)
   # Ordering is random due to buffering.
   self.assertEquals(
       set(c('a\nbb\nccc\nA\nBB\nCCC\n').splitlines(True)),
       set(''.join(stdout).splitlines(True)))
    def check_call(self, *args):
        ((out, err), code) = subprocess2.communicate(
            (sys.executable, self.path) + args,
            stdout=subprocess2.PIPE,
            stderr=subprocess2.PIPE,
            env=self.get_sub_env(),
            timeout=self.timeout,
        )

        # Parse output.
        status_code_match = re.search("status=([0-9]+)", err)
        if status_code_match:
            return (int(status_code_match.group(1)), out, err)
        if "You are attempting to access protected data with " "no configured credentials." in err:
            return (403, out, err)
        if "No such object" in err:
            return (404, out, err)
        return (code, out, err)
  def check_call(self, *args):
    ((out, err), code) = subprocess2.communicate(
        (sys.executable, self.path) + args,
        stdout=subprocess2.PIPE,
        stderr=subprocess2.PIPE,
        env=self.get_sub_env(),
        timeout=self.timeout)

    # Parse output.
    status_code_match = re.search('status=([0-9]+)', err)
    if status_code_match:
      return (int(status_code_match.group(1)), out, err)
    if ('You are attempting to access protected data with '
          'no configured credentials.' in err):
      return (403, out, err)
    if 'No such object' in err:
      return (404, out, err)
    return (code, out, err)
  def check_call(self, *args):
    cmd = [sys.executable, self.path, '--force-version', self.version]
    cmd.extend(args)
    ((out, err), code) = subprocess2.communicate(
        cmd,
        stdout=subprocess2.PIPE,
        stderr=subprocess2.PIPE,
        env=self.get_sub_env(),
        timeout=self.timeout)

    # Parse output.
    status_code_match = re.search('status=([0-9]+)', err)
    if status_code_match:
      return (int(status_code_match.group(1)), out, err)
    if ('You are attempting to access protected data with '
          'no configured credentials.' in err):
      return (403, out, err)
    if 'matched no objects' in err:
      return (404, out, err)
    return (code, out, err)
  def check_call(self, *args):
    env = os.environ.copy()
    if self.boto_path:
      env['AWS_CREDENTIAL_FILE'] = self.boto_path
    ((out, err), code) = subprocess2.communicate(
        (sys.executable, self.path) + args,
        stdout=subprocess2.PIPE,
        stderr=subprocess2.PIPE,
        env=env,
        timeout=self.timeout)

    # Parse output.
    status_code_match = re.search('status=([0-9]+)', err)
    if status_code_match:
      return (int(status_code_match.group(1)), out, err)
    if ('You are attempting to access protected data with '
          'no configured credentials.' in err):
      return (403, out, err)
    if 'No such object' in err:
      return (404, out, err)
    return (code, out, err)
Exemplo n.º 28
0
 def test_tee_large(self):
   stdout = []
   # Read 128kb. On my workstation it takes >2s. Welcome to 2011.
   res = subprocess2.communicate(self.exe + ['--large'], stdout=stdout.append)
   self.assertEquals(128*1024, len(''.join(stdout)))
   self._check_res(res, None, None, 0)
Exemplo n.º 29
0
 def test_stdin_void(self):
   res = subprocess2.communicate(self.exe + ['--read'], stdin=VOID)
   self._check_res(res, None, None, 0)
Exemplo n.º 30
0
def RunGitWithCode(args):
  """Returns return code and stdout."""
  out, code = subprocess2.communicate(['git'] + args, stdout=subprocess2.PIPE)
  return code, out[0]