Ejemplo n.º 1
0
    def _run_flake8(self, py_num: float,
                    lint_files: List[Path]) -> Tuple[int, str]:
        """ Runs flake8 in pack dir

        Args:
            py_num(float): The python version in use
            lint_files(List[Path]): file to perform lint

        Returns:
           int:  0 on successful else 1, errors
           str: Bandit errors
        """
        log_prompt = f"{self._pack_name} - Flake8"
        logger.info(f"{log_prompt} - Start")
        stdout, stderr, exit_code = run_command_os(
            command=build_flake8_command(lint_files, py_num),
            cwd=self._content_repo)
        logger.debug(f"{log_prompt} - Finished exit-code: {exit_code}")
        logger.debug(
            f"{log_prompt} - Finished stdout: {RL if stdout else ''}{stdout}")
        logger.debug(
            f"{log_prompt} - Finished stderr: {RL if stderr else ''}{stderr}")
        if stderr or exit_code:
            logger.info(f"{log_prompt}- Finished errors found")
            if stderr:
                return FAIL, stderr
            else:
                return FAIL, stdout

        logger.info(f"{log_prompt} - Successfully finished")

        return SUCCESS, ""
def test_build_flak8_command(files):
    """Build flake8 command"""
    from demisto_sdk.commands.lint.commands_builder import build_flake8_command
    output = build_flake8_command(files, '3.8')
    files = [str(file) for file in files]
    expected = f"python3 -m flake8 {' '.join(files)}"
    assert output == expected