def test_should_execute_tool_on_source_dirs(self, affected, execute, read, log): project = Mock() project.expand_path.return_value = '/path/to/report' affected.return_value = ['/dir1', '/dir2'] execute_tool_on_source_files(project, 'name', 'foo --bar', include_dirs_only=True) execute.assert_called_with(['foo --bar', '/dir1', '/dir2'], '/path/to/report')
def test_should_give_verbose_output(self, affected, execute, read, log): project = Mock() project.get_property.return_value = True # flake8_verbose_output == True logger = Mock() read.return_value = ['error', 'warning'] execute_tool_on_source_files(project, 'flake8', 'foo --bar', logger) log.assert_called_with(logger, 'flake8', ['error', 'warning'])
def analyze(project, logger): logger.info("Executing pep8 on project sources") _, report_file = execute_tool_on_source_files(project, "pep8", ["pep8"]) reports = read_file(report_file) if len(reports) > 0: logger.warn("Found %d warning%s produced by pep8", len(reports), "" if len(reports) == 1 else "s")
def analyze(project, logger): logger.info("Executing pep8 on project sources") _, report_file = execute_tool_on_source_files(project, "pep8", ["pep8"]) reports = read_file(report_file) if len(reports) > 0: logger.warn("Found %d warning%s produced by pep8", len(reports), "" if len(reports) == 1 else "s")
def run_on_production_source_files(self, logger, include_test_sources=False, include_scripts=False): execution_result = execute_tool_on_source_files(project=self.project, name=self.command_name, command_and_arguments=self.parts, include_test_sources=include_test_sources, include_scripts=include_scripts, logger=logger) exit_code, report_file = execution_result report_lines = read_file(report_file) error_report_file = '{0}.err'.format(report_file) # TODO @mriehl not dry, execute_tool... should return this error_report_lines = read_file(error_report_file) return ExternalCommandResult(exit_code, report_file, report_lines, error_report_file, error_report_lines)
def analyze(project, logger): """ Applies the flake8 script to the sources of the given project. """ logger.info("Executing flake8 on project sources.") verbose = project.get_property("verbose") project.set_property_if_unset("flake8_verbose_output", verbose) command_and_arguments = ["flake8"] flake8_ignore = project.get_property("flake8_ignore") if flake8_ignore is not None: ignore_option = "--ignore={0}".format(flake8_ignore) command_and_arguments.append(ignore_option) max_line_length = project.get_property("flake8_max_line_length") command_and_arguments.append("--max-line-length={0}".format(max_line_length)) exclude_patterns = project.get_property("flake8_exclude_patterns") if exclude_patterns: command_and_arguments.append("--exclude={0}".format(exclude_patterns)) include_test_sources = project.get_property("flake8_include_test_sources") execution_result = execute_tool_on_source_files(project=project, name="flake8", command_and_arguments=command_and_arguments, logger=logger, include_test_sources=include_test_sources) report_file = execution_result[1] report_lines = read_file(report_file) count_of_warnings = len(report_lines) if count_of_warnings > 0: if project.get_property("flake8_break_build"): error_message = "flake8 found {0} warning(s)".format(count_of_warnings) raise BuildFailedException(error_message) else: logger.warn("flake8 found %d warning(s).", count_of_warnings)