示例#1
0
  def test_check_output(self):
    cmd = [sys.executable, '-u', '-c', 'print(\'.\')']
    self.assertEqual(
        '.\n',
        subprocess42.check_output(cmd, universal_newlines=True))

    cmd = [sys.executable, '-u', '-c', 'import sys; print(\'.\'); sys.exit(1)']
    try:
      subprocess42.check_output(cmd, universal_newlines=True)
      self.fail()
    except subprocess42.CalledProcessError as e:
      self.assertEqual('.\n', e.output)
  def test_check_output(self):
    cmd = [sys.executable, '-u', '-c', 'print(\'.\')']
    self.assertEqual(
        '.\n',
        subprocess42.check_output(cmd, universal_newlines=True))

    cmd = [sys.executable, '-u', '-c', 'import sys; print(\'.\'); sys.exit(1)']
    try:
      subprocess42.check_output(cmd, universal_newlines=True)
      self.fail()
    except subprocess42.CalledProcessError as e:
      self.assertEqual('.\n', e.output)
示例#3
0
  def test_attributes(self):
    actual = json.loads(subprocess42.check_output(
        [sys.executable, self._zip_file, 'attributes'],
        stderr=subprocess42.PIPE))
    # get_config() doesn't work when called outside of a zip, so patch the
    # server_version manually with the default value in config/config.json.
    expected = bot_main.get_attributes(None)
    self.assertEqual([u'N/A'], expected[u'dimensions'][u'server_version'])
    expected[u'dimensions'][u'server_version'] = [u'1']

    NON_DETERMINISTIC = (
      u'cwd', u'disks', u'nb_files_in_temp', u'pid', u'running_time',
      u'started_ts', u'uptime')
    for key in NON_DETERMINISTIC:
      del actual[u'state'][key]
      del expected[u'state'][key]
    actual[u'state'].pop('temp', None)
    expected[u'state'].pop('temp', None)
    del actual[u'version']
    del expected[u'version']
    self.assertAlmostEqual(
        actual[u'state'].pop(u'cost_usd_hour'),
        expected[u'state'].pop(u'cost_usd_hour'),
        places=5)
    self.assertEqual(expected, actual)
示例#4
0
 def test_version(self):
     version = subprocess42.check_output(
         [sys.executable, self._zip_file, 'version'],
         stderr=subprocess42.PIPE)
     lines = version.strip().split()
     self.assertEqual(1, len(lines), lines)
     self.assertTrue(re.match(r'^[0-9a-f]{40}$', lines[0]), lines[0])
 def isolate(self, isolate_path, isolated_path):
   cmd = [
     sys.executable, 'isolate.py', 'archive',
     '-I', self._isolate_server,
     '--namespace', 'default-gzip',
     '-i', isolate_path,
     '-s', isolated_path,
   ]
   isolated_hash = subprocess42.check_output(cmd, cwd=CLIENT_DIR).split()[0]
   logging.debug('%s = %s', isolated_path, isolated_hash)
   return isolated_hash
示例#6
0
 def isolate(self, isolate_path, isolated_path):
   cmd = [
     sys.executable, 'isolate.py', 'archive',
     '-I', self._isolate_server,
     '--namespace', 'default-gzip',
     '-i', isolate_path,
     '-s', isolated_path,
   ]
   isolated_hash = subprocess42.check_output(cmd, cwd=CLIENT_DIR).split()[0]
   logging.debug('%s = %s', isolated_path, isolated_hash)
   return isolated_hash
示例#7
0
 def test_attributes(self):
   actual = json.loads(subprocess42.check_output(
       [sys.executable, self._zip_file, 'attributes'],
       stderr=subprocess42.PIPE))
   expected = bot_main.get_attributes()
   for key in (
       u'cwd', u'disks', u'nb_files_in_temp', u'running_time', u'started_ts'):
     del actual[u'state'][key]
     del expected[u'state'][key]
   del actual[u'version']
   del expected[u'version']
   self.assertAlmostEqual(
       actual[u'state'].pop(u'cost_usd_hour'),
       expected[u'state'].pop(u'cost_usd_hour'),
       places=6)
   self.assertEqual(expected, actual)
示例#8
0
 def test_version(self):
   version = subprocess42.check_output(
       [sys.executable, self._zip_file, 'version'], stderr=subprocess42.PIPE)
   lines = version.strip().split()
   self.assertEqual(1, len(lines), lines)
   self.assertTrue(re.match(r'^[0-9a-f]{40}$', lines[0]), lines[0])
 def test_large_memory(self):
     # Just assert the process works normally.
     cmd = self._cmd_large_memory()
     self.assertEqual('hi', subprocess42.check_output(cmd).strip())