How to use include_tool_stdout method in prospector

Best Python code snippet using prospector_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...238 @property239 def max_line_length(self):240 return self.config.max_line_length241 @property242 def include_tool_stdout(self):243 return self.config.include_tool_stdout244 @property245 def direct_tool_stdout(self):246 return self.config.direct_tool_stdout247 @property248 def show_profile(self):...

Full Screen

Full Screen

run.py

Source:run.py Github

copy

Full Screen

1from __future__ import absolute_import2import os.path3import sys4from datetime import datetime5from prospector import blender, postfilter, tools6from prospector.config import ProspectorConfig7from prospector.config import configuration as cfg8from prospector.exceptions import FatalProspectorException9from prospector.finder import find_python10from prospector.formatters import FORMATTERS11from prospector.message import Location, Message12from prospector.tools.utils import capture_output13__all__ = (14 "Prospector",15 "main",16)17class Prospector(object):18 def __init__(self, config):19 self.config = config20 self.summary = None21 self.messages = config.messages22 def process_messages(self, found_files, messages):23 for message in messages:24 if self.config.absolute_paths:25 message.to_absolute_path(self.config.workdir)26 else:27 message.to_relative_path(self.config.workdir)28 if self.config.blending:29 messages = blender.blend(messages)30 filepaths = found_files.iter_module_paths(abspath=False)31 return postfilter.filter_messages(filepaths, self.config.workdir, messages)32 def execute(self):33 summary = {34 "started": datetime.now(),35 }36 summary.update(self.config.get_summary_information())37 found_files = find_python(38 self.config.ignores,39 self.config.paths,40 self.config.explicit_file_mode,41 self.config.workdir,42 )43 # Run the tools44 messages = []45 for tool in self.config.get_tools(found_files):46 for name, cls in tools.TOOLS.items():47 if cls == tool.__class__:48 toolname = name49 break50 else:51 toolname = "Unknown"52 try:53 # Tools can output to stdout/stderr in unexpected places, for example,54 # pep257 emits warnings about __all__ and as pyroma exec's the setup.py55 # file, it will execute any print statements in that, etc etc...56 with capture_output(hide=not self.config.direct_tool_stdout) as capture:57 messages += tool.run(found_files)58 if self.config.include_tool_stdout:59 loc = Location(self.config.workdir, None, None, None, None)60 if capture.get_hidden_stderr():61 msg = "stderr from %s:\n%s" % (62 toolname,63 capture.get_hidden_stderr(),64 )65 messages.append(Message(toolname, "hidden-output", loc, message=msg))66 if capture.get_hidden_stdout():67 msg = "stdout from %s:\n%s" % (68 toolname,69 capture.get_hidden_stdout(),70 )71 messages.append(Message(toolname, "hidden-output", loc, message=msg))72 except FatalProspectorException as fatal:73 sys.stderr.write(fatal.message)74 sys.exit(2)75 except Exception: # pylint: disable=broad-except76 if self.config.die_on_tool_error:77 raise78 else:79 loc = Location(self.config.workdir, None, None, None, None)80 msg = (81 "Tool %s failed to run (exception was raised, re-run prospector with -X to see the stacktrace)"82 % (toolname,)83 )84 message = Message(85 toolname,86 "failure",87 loc,88 message=msg,89 )90 messages.append(message)91 messages = self.process_messages(found_files, messages)92 summary["message_count"] = len(messages)93 summary["completed"] = datetime.now()94 # Timedelta.total_seconds() is not available95 # on Python<=2.6 so we calculate it ourselves96 # See issue #60 and http://stackoverflow.com/a/369489597 delta = summary["completed"] - summary["started"]98 total_seconds = (delta.microseconds + (delta.seconds + delta.days * 24 * 3600) * 1e6) / 1e699 summary["time_taken"] = "%0.2f" % total_seconds100 external_config = []101 for tool, configured_by in self.config.configured_by.items():102 if configured_by is not None:103 external_config.append((tool, configured_by))104 if len(external_config) > 0:105 summary["external_config"] = ", ".join(["%s: %s" % info for info in external_config])106 self.summary = summary107 self.messages = self.messages + messages108 def get_summary(self):109 return self.summary110 def get_messages(self):111 return self.messages112 def print_messages(self):113 output_reports = self.config.get_output_report()114 for report in output_reports:115 output_format, output_files = report116 self.summary["formatter"] = output_format117 formatter = FORMATTERS[output_format](self.summary, self.messages, self.config.profile)118 if not output_files:119 self.write_to(formatter, sys.stdout)120 for output_file in output_files:121 with open(output_file, "w+") as target:122 self.write_to(formatter, target)123 def write_to(self, formatter, target):124 # Produce the output125 target.write(126 formatter.render(127 summary=not self.config.messages_only,128 messages=not self.config.summary_only,129 profile=self.config.show_profile,130 )131 )132 target.write("\n")133def get_parser():134 """135 This is a helper method to return an argparse parser, to136 be used with the Sphinx argparse plugin for documentation.137 """138 manager = cfg.build_manager()139 source = cfg.build_command_line_source(prog="prospector", description=None)140 return source.build_parser(manager.settings, None)141def main():142 # Get our configuration143 config = ProspectorConfig()144 paths = config.paths145 if len(paths) > 1 and not all([os.path.isfile(path) for path in paths]):146 sys.stderr.write("\nIn multi-path mode, all inputs must be files, " "not directories.\n\n")147 get_parser().print_usage()148 sys.exit(2)149 # Make it so150 prospector = Prospector(config)151 prospector.execute()152 prospector.print_messages()153 if config.exit_with_zero_on_success():154 # if we ran successfully, and the user wants us to, then we'll155 # exit cleanly156 return 0157 # otherwise, finding messages is grounds for exiting with an error158 # code, to make it easier for bash scripts and similar situations159 # to know if there any errors have been found.160 if len(prospector.get_messages()) > 0:161 return 1162 return 0163if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful