Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_char_order(self):
locs = [
Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 7),
Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 2)
]
chars = [loc.character for loc in locs]
expected = sorted(chars)
self.assertEqual(expected, [loc.character for loc in sorted(locs)])
def test_sort_between_none_lines(self):
locs = [
Location('/tmp/path/module1.py', 'module1', 'somefunc', 15, 0),
Location('/tmp/path/module1.py', 'module1', 'somefunc', 10, 0),
Location('/tmp/path/module1.py', 'module1', 'somefunc', -1, 0)
]
lines = [(loc.line or -1) for loc in locs]
expected = [None if l == -1 else l for l in sorted(lines)]
self.assertEqual(expected, [loc.line for loc in sorted(locs)])
for name, cls in tools.TOOLS.items():
if cls == tool.__class__:
toolname = name
break
else:
toolname = 'Unknown'
try:
# Tools can output to stdout/stderr in unexpected places, for example,
# pep257 emits warnings about __all__ and as pyroma exec's the setup.py
# file, it will execute any print statements in that, etc etc...
with capture_output(hide=not self.config.direct_tool_stdout) as capture:
messages += tool.run(found_files)
if self.config.include_tool_stdout:
loc = Location(self.config.workdir, None, None, None, None)
if capture.get_hidden_stderr():
msg = 'stderr from %s:\n%s' % (toolname, capture.get_hidden_stderr())
messages.append(Message(toolname, 'hidden-output', loc, message=msg))
if capture.get_hidden_stdout():
msg = 'stdout from %s:\n%s' % (toolname, capture.get_hidden_stdout())
messages.append(Message(toolname, 'hidden-output', loc, message=msg))
except FatalProspectorException as fatal:
sys.stderr.write(fatal.message)
sys.exit(2)
except Exception: # pylint: disable=broad-except
if self.config.die_on_tool_error:
raise
else:
def _error_message(self, filepath, message):
location = Location(filepath, None, None, 0, 0)
return Message('prospector', 'config-problem', location, message)
def add_message(self, msg_id, location, msg):
# (* magic is acceptable here)
loc = Location(*location)
# At this point pylint will give us the code but we want the
# more user-friendly symbol
try:
if PYLINT_VERSION < (2, 0):
msg_data = self._message_store.check_message_id(msg_id)
else:
msg_data = self._message_store.get_message_definitions(msg_id)[0]
except UnknownMessageError:
# this shouldn't happen, as all pylint errors should be
# in the message store, but just in case we'll fall back
# to using the code.
msg_symbol = msg_id
else:
msg_symbol = msg_data.symbol
message = Message('pylint', msg_symbol, loc, msg)
def run(self, found_files):
messages = []
checker = PEP257Checker()
for code_file in found_files.iter_module_paths():
try:
for error in checker.check_source(
read_py_file(code_file),
code_file,
None
):
location = Location(
path=code_file,
module=None,
function='',
line=error.line,
character=0,
absolute_path=True,
)
message = Message(
source='pep257',
code=error.code,
location=location,
message=error.message.partition(':')[2].strip(),
)
messages.append(message)
except CouldNotHandleEncoding as err:
messages.append(make_tool_error_message(
def record_message(
self,
filename=None,
line=None,
character=None,
code=None,
message=None):
if code in self.ignore:
return
location = Location(
path=filename,
module=None,
function=None,
line=line,
character=character,
)
message = Message(
source='frosted',
code=code,
location=location,
message=message,
)
self._messages.append(message)
def record_message(
self,
filename=None,
line=None,
character=None,
code=None,
message=None):
code = code or 'F999'
if code in self.ignore:
return
location = Location(
path=filename,
module=None,
function=None,
line=line,
character=character,
)
message = Message(
source='pyflakes',
code=code,
location=location,
message=message,
)
self._messages.append(message)