def test_run_command_process_error_no_output(self):
        with self.assertRaises(
                subprocess.CalledProcessError) as error_cm, self.assertLogs(
                    level='ERROR') as logging_cm:
            subprocess_utils.run_command(['false'])

        self.assertEqual(1, error_cm.exception.returncode)
        self.assertEqual(1, len(logging_cm.output))
        self.assertRegex(logging_cm.output[0],
                         _COMMAND_PROCESS_ERROR_LOG_REGEX)
    def test_run_command_process_error_with_stdout_output(self):
        expected_stdout_regex = r'usage: git.+'

        with self.assertRaises(
                subprocess.CalledProcessError) as error_cm, self.assertLogs(
                    level='ERROR') as logging_cm:
            subprocess_utils.run_command(['git'])

        self.assertEqual(1, error_cm.exception.returncode)
        self.assertEqual('', error_cm.exception.stderr)
        self.assertRegex(error_cm.exception.stdout, expected_stdout_regex)
        self.assertEqual(1, len(logging_cm.output))
        self.assertRegex(logging_cm.output[0],
                         _COMMAND_PROCESS_ERROR_LOG_REGEX)
def _run_gn_desc_list_dependencies(build_output_dir: str, target: str,
                                   gn_path: str) -> str:
    """Runs gn desc to list all jars that a target depends on.

    This includes direct and indirect dependencies."""
    return subprocess_utils.run_command(
        [gn_path, 'desc', '--all', build_output_dir, target, 'deps'])
    def test_run_command_exitcode_only_returns_zero_on_success(self):
        expected_output = 0

        command_output = subprocess_utils.run_command(
            ['echo', '\t Hello, world! \n'], exitcode_only=True)

        self.assertEqual(expected_output, command_output)
    def test_run_command_exitcode_only_returns_exitcode_on_failure(self):
        expected_output = 1

        command_output = subprocess_utils.run_command(['git', 'foo'],
                                                      exitcode_only=True)

        self.assertEqual(expected_output, command_output)
    def test_run_command_strips_output_whitespace(self):
        expected_output = 'Hello, world!'

        command_output = subprocess_utils.run_command(
            ['echo', '\t Hello, world! \n'])

        self.assertEqual(expected_output, command_output)
    def test_run_command_multiple_args(self):
        expected_output = 'some sample output'

        command_output = subprocess_utils.run_command(
            ['echo', 'some', 'sample', 'output'])

        self.assertEqual(expected_output, command_output)
Ejemplo n.º 8
0
def _get_last_commit_with_format(format: str) -> str:
    output_str: str = subprocess_utils.run_command(
        ['git', 'show', '--no-patch', f'--pretty=format:{format}'])
    return output_str.strip('\n')
def _run_jdeps(jdeps_path: str, filepath: pathlib.Path) -> str:
    """Runs jdeps on the given filepath and returns the output."""
    print(f'Running jdeps and parsing output for {filepath}')
    return subprocess_utils.run_command(
        [jdeps_path, '-R', '-verbose:class', filepath])
Ejemplo n.º 10
0
def read_raw_dir_metadata(chromium_root: str, dirmd_path: str) -> Dict:
  '''Runs all DIR_METADATA files with dirmd and returns a dict of raw data.'''
  raw_str: str = subprocess_utils.run_command(
      [dirmd_path, 'export', '--root', chromium_root])
  raw_dict: Dict = json.loads(raw_str)
  return raw_dict['dirs']
    def test_run_command_custom_cwd(self):
        expected_cwd = '/usr/local/bin'

        pwd_output = subprocess_utils.run_command(['pwd'], cwd=expected_cwd)

        self.assertEqual(expected_cwd, pwd_output)
    def test_run_command_no_args(self):
        expected_cwd: str = os.getcwd()

        pwd_output = subprocess_utils.run_command(['pwd'])

        self.assertEqual(expected_cwd, pwd_output)
    def test_run_command_not_found(self):
        with self.assertRaises(FileNotFoundError) as error_cm:
            subprocess_utils.run_command(['foo_cmd'])

        self.assertEqual(2, error_cm.exception.errno)
        self.assertEqual('foo_cmd', error_cm.exception.filename)