2017-03-08 09:47:21 +01:00
|
|
|
"""Classes for storing and processing test results."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
import datetime
|
2019-08-28 23:34:12 +02:00
|
|
|
import re
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from . import types as t
|
2019-07-20 01:34:16 +02:00
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from .util import (
|
2017-03-08 09:47:21 +01:00
|
|
|
display,
|
2019-08-28 23:34:12 +02:00
|
|
|
get_ansible_version,
|
2017-03-08 09:47:21 +01:00
|
|
|
)
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
from .util_common import (
|
|
|
|
write_text_test_results,
|
|
|
|
write_json_test_results,
|
|
|
|
ResultType,
|
2017-03-15 20:17:42 +01:00
|
|
|
)
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
from .config import (
|
|
|
|
TestConfig,
|
2019-08-14 01:28:04 +02:00
|
|
|
)
|
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
|
|
|
|
def calculate_best_confidence(choices, metadata):
|
|
|
|
"""
|
|
|
|
:type choices: tuple[tuple[str, int]]
|
|
|
|
:type metadata: Metadata
|
|
|
|
:rtype: int
|
|
|
|
"""
|
|
|
|
best_confidence = 0
|
|
|
|
|
|
|
|
for path, line in choices:
|
|
|
|
confidence = calculate_confidence(path, line, metadata)
|
|
|
|
best_confidence = max(confidence, best_confidence)
|
|
|
|
|
|
|
|
return best_confidence
|
|
|
|
|
|
|
|
|
|
|
|
def calculate_confidence(path, line, metadata):
|
|
|
|
"""
|
|
|
|
:type path: str
|
|
|
|
:type line: int
|
|
|
|
:type metadata: Metadata
|
|
|
|
:rtype: int
|
|
|
|
"""
|
|
|
|
ranges = metadata.changes.get(path)
|
|
|
|
|
|
|
|
# no changes were made to the file
|
|
|
|
if not ranges:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
# changes were made to the same file and line
|
|
|
|
if any(r[0] <= line <= r[1] in r for r in ranges):
|
|
|
|
return 100
|
|
|
|
|
|
|
|
# changes were made to the same file and the line number is unknown
|
|
|
|
if line == 0:
|
|
|
|
return 75
|
|
|
|
|
|
|
|
# changes were made to the same file and the line number is different
|
|
|
|
return 50
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-07-12 22:17:20 +02:00
|
|
|
class TestResult:
|
2017-03-08 09:47:21 +01:00
|
|
|
"""Base class for test results."""
|
2019-03-07 04:46:41 +01:00
|
|
|
def __init__(self, command, test, python_version=None):
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
|
|
|
:type command: str
|
|
|
|
:type test: str
|
|
|
|
:type python_version: str
|
|
|
|
"""
|
|
|
|
self.command = command
|
|
|
|
self.test = test
|
|
|
|
self.python_version = python_version
|
|
|
|
self.name = self.test or self.command
|
|
|
|
|
|
|
|
if self.python_version:
|
|
|
|
self.name += '-python-%s' % self.python_version
|
|
|
|
|
|
|
|
try:
|
|
|
|
import junit_xml
|
|
|
|
except ImportError:
|
|
|
|
junit_xml = None
|
|
|
|
|
|
|
|
self.junit = junit_xml
|
|
|
|
|
|
|
|
def write(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
self.write_console()
|
|
|
|
self.write_bot(args)
|
|
|
|
|
|
|
|
if args.lint:
|
|
|
|
self.write_lint()
|
|
|
|
|
2019-03-07 04:46:41 +01:00
|
|
|
if args.junit:
|
2017-03-08 09:47:21 +01:00
|
|
|
if self.junit:
|
|
|
|
self.write_junit(args)
|
|
|
|
else:
|
|
|
|
display.warning('Skipping junit xml output because the `junit-xml` python package was not found.', unique=True)
|
|
|
|
|
|
|
|
def write_console(self):
|
|
|
|
"""Write results to console."""
|
|
|
|
|
|
|
|
def write_lint(self):
|
|
|
|
"""Write lint results to stdout."""
|
|
|
|
|
|
|
|
def write_bot(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
|
|
|
|
def write_junit(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
def create_result_name(self, extension):
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
|
|
|
:type extension: str
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2019-08-28 08:40:06 +02:00
|
|
|
name = 'ansible-test-%s' % self.command
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
if self.test:
|
2019-08-28 08:40:06 +02:00
|
|
|
name += '-%s' % self.test
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
if self.python_version:
|
2019-08-28 08:40:06 +02:00
|
|
|
name += '-python-%s' % self.python_version
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
name += extension
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
return name
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
def save_junit(self, args, test_case, properties=None):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
:type test_case: junit_xml.TestCase
|
|
|
|
:type properties: dict[str, str] | None
|
|
|
|
:rtype: str | None
|
|
|
|
"""
|
|
|
|
test_suites = [
|
|
|
|
self.junit.TestSuite(
|
|
|
|
name='ansible-test',
|
|
|
|
test_cases=[test_case],
|
|
|
|
timestamp=datetime.datetime.utcnow().replace(microsecond=0).isoformat(),
|
|
|
|
properties=properties,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
report = self.junit.TestSuite.to_xml_string(test_suites=test_suites, prettyprint=True, encoding='utf-8')
|
|
|
|
|
|
|
|
if args.explain:
|
|
|
|
return
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
write_text_test_results(ResultType.JUNIT, self.create_result_name('.xml'), report)
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
|
2019-03-05 20:58:13 +01:00
|
|
|
class TestTimeout(TestResult):
|
|
|
|
"""Test timeout."""
|
|
|
|
def __init__(self, timeout_duration):
|
|
|
|
"""
|
|
|
|
:type timeout_duration: int
|
|
|
|
"""
|
2019-03-07 04:46:41 +01:00
|
|
|
super(TestTimeout, self).__init__(command='timeout', test='')
|
2019-03-05 20:58:13 +01:00
|
|
|
|
|
|
|
self.timeout_duration = timeout_duration
|
|
|
|
|
2019-03-07 04:46:41 +01:00
|
|
|
def write(self, args):
|
2019-03-05 20:58:13 +01:00
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
message = 'Tests were aborted after exceeding the %d minute time limit.' % self.timeout_duration
|
2019-03-09 05:39:17 +01:00
|
|
|
|
|
|
|
# Include a leading newline to improve readability on Shippable "Tests" tab.
|
|
|
|
# Without this, the first line becomes indented.
|
|
|
|
output = '''
|
|
|
|
One or more of the following situations may be responsible:
|
2019-03-05 20:58:13 +01:00
|
|
|
|
|
|
|
- Code changes have resulted in tests that hang or run for an excessive amount of time.
|
|
|
|
- Tests have been added which exceed the time limit when combined with existing tests.
|
|
|
|
- Test infrastructure and/or external dependencies are operating slower than normal.'''
|
|
|
|
|
|
|
|
if args.coverage:
|
|
|
|
output += '\n- Additional overhead from collecting code coverage has resulted in tests exceeding the time limit.'
|
|
|
|
|
|
|
|
output += '\n\nConsult the console log for additional details on where the timeout occurred.'
|
|
|
|
|
2019-03-07 04:46:41 +01:00
|
|
|
timestamp = datetime.datetime.utcnow().replace(microsecond=0).isoformat()
|
|
|
|
|
2020-04-26 03:55:39 +02:00
|
|
|
# hack to avoid requiring junit-xml, which may not be pre-installed outside our test containers
|
2019-03-07 04:46:41 +01:00
|
|
|
xml = '''
|
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
|
|
|
<testsuites disabled="0" errors="1" failures="0" tests="1" time="0.0">
|
|
|
|
\t<testsuite disabled="0" errors="1" failures="0" file="None" log="None" name="ansible-test" skipped="0" tests="1" time="0" timestamp="%s" url="None">
|
|
|
|
\t\t<testcase classname="timeout" name="timeout">
|
|
|
|
\t\t\t<error message="%s" type="error">%s</error>
|
|
|
|
\t\t</testcase>
|
|
|
|
\t</testsuite>
|
|
|
|
</testsuites>
|
|
|
|
''' % (timestamp, message, output)
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
write_text_test_results(ResultType.JUNIT, self.create_result_name('.xml'), xml.lstrip())
|
2019-03-05 20:58:13 +01:00
|
|
|
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
class TestSuccess(TestResult):
|
|
|
|
"""Test success."""
|
|
|
|
def write_junit(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
test_case = self.junit.TestCase(classname=self.command, name=self.name)
|
|
|
|
|
|
|
|
self.save_junit(args, test_case)
|
|
|
|
|
|
|
|
|
|
|
|
class TestSkipped(TestResult):
|
|
|
|
"""Test skipped."""
|
|
|
|
def write_console(self):
|
|
|
|
"""Write results to console."""
|
|
|
|
display.info('No tests applicable.', verbosity=1)
|
|
|
|
|
|
|
|
def write_junit(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
test_case = self.junit.TestCase(classname=self.command, name=self.name)
|
|
|
|
test_case.add_skipped_info('No tests applicable.')
|
|
|
|
|
|
|
|
self.save_junit(args, test_case)
|
|
|
|
|
|
|
|
|
|
|
|
class TestFailure(TestResult):
|
|
|
|
"""Test failure."""
|
|
|
|
def __init__(self, command, test, python_version=None, messages=None, summary=None):
|
|
|
|
"""
|
|
|
|
:type command: str
|
|
|
|
:type test: str
|
2017-03-14 04:45:10 +01:00
|
|
|
:type python_version: str | None
|
|
|
|
:type messages: list[TestMessage] | None
|
2017-09-12 01:39:34 +02:00
|
|
|
:type summary: unicode | None
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
|
|
|
super(TestFailure, self).__init__(command, test, python_version)
|
|
|
|
|
2017-03-14 04:45:10 +01:00
|
|
|
if messages:
|
2019-07-20 01:34:16 +02:00
|
|
|
messages = sorted(messages)
|
2017-08-18 20:21:53 +02:00
|
|
|
else:
|
|
|
|
messages = []
|
2017-03-14 04:45:10 +01:00
|
|
|
|
2017-08-18 20:21:53 +02:00
|
|
|
self.messages = messages
|
2017-03-08 09:47:21 +01:00
|
|
|
self.summary = summary
|
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
def write(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
if args.metadata.changes:
|
|
|
|
self.populate_confidence(args.metadata)
|
|
|
|
|
|
|
|
super(TestFailure, self).write(args)
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
def write_console(self):
|
|
|
|
"""Write results to console."""
|
|
|
|
if self.summary:
|
|
|
|
display.error(self.summary)
|
|
|
|
else:
|
|
|
|
if self.python_version:
|
|
|
|
specifier = ' on python %s' % self.python_version
|
|
|
|
else:
|
|
|
|
specifier = ''
|
|
|
|
|
|
|
|
display.error('Found %d %s issue(s)%s which need to be resolved:' % (len(self.messages), self.test or self.command, specifier))
|
|
|
|
|
|
|
|
for message in self.messages:
|
2017-03-15 20:17:42 +01:00
|
|
|
display.error(message.format(show_confidence=True))
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-08-28 23:34:12 +02:00
|
|
|
doc_url = self.find_docs()
|
|
|
|
if doc_url:
|
|
|
|
display.info('See documentation for help: %s' % doc_url)
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
def write_lint(self):
|
|
|
|
"""Write lint results to stdout."""
|
|
|
|
if self.summary:
|
|
|
|
command = self.format_command()
|
|
|
|
message = 'The test `%s` failed. See stderr output for details.' % command
|
2019-08-06 01:38:21 +02:00
|
|
|
path = ''
|
2017-03-08 09:47:21 +01:00
|
|
|
message = TestMessage(message, path)
|
|
|
|
print(message)
|
|
|
|
else:
|
|
|
|
for message in self.messages:
|
|
|
|
print(message)
|
|
|
|
|
|
|
|
def write_junit(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
|
|
|
title = self.format_title()
|
|
|
|
output = self.format_block()
|
|
|
|
|
|
|
|
test_case = self.junit.TestCase(classname=self.command, name=self.name)
|
|
|
|
|
|
|
|
# Include a leading newline to improve readability on Shippable "Tests" tab.
|
|
|
|
# Without this, the first line becomes indented.
|
|
|
|
test_case.add_failure_info(message=title, output='\n%s' % output)
|
|
|
|
|
|
|
|
self.save_junit(args, test_case)
|
|
|
|
|
|
|
|
def write_bot(self, args):
|
|
|
|
"""
|
|
|
|
:type args: TestConfig
|
|
|
|
"""
|
2017-07-15 01:52:11 +02:00
|
|
|
docs = self.find_docs()
|
2017-09-01 01:39:37 +02:00
|
|
|
message = self.format_title(help_link=docs)
|
|
|
|
output = self.format_block()
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
if self.messages:
|
|
|
|
verified = all((m.confidence or 0) >= 50 for m in self.messages)
|
|
|
|
else:
|
|
|
|
verified = False
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
bot_data = dict(
|
2017-03-15 20:17:42 +01:00
|
|
|
verified=verified,
|
2017-07-15 01:52:11 +02:00
|
|
|
docs=docs,
|
2017-03-08 09:47:21 +01:00
|
|
|
results=[
|
|
|
|
dict(
|
|
|
|
message=message,
|
|
|
|
output=output,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
if args.explain:
|
|
|
|
return
|
|
|
|
|
2019-08-28 08:40:06 +02:00
|
|
|
write_json_test_results(ResultType.BOT, self.create_result_name('.json'), bot_data)
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
def populate_confidence(self, metadata):
|
|
|
|
"""
|
|
|
|
:type metadata: Metadata
|
|
|
|
"""
|
|
|
|
for message in self.messages:
|
|
|
|
if message.confidence is None:
|
|
|
|
message.confidence = calculate_confidence(message.path, message.line, metadata)
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
def format_command(self):
|
|
|
|
"""
|
|
|
|
:rtype: str
|
|
|
|
"""
|
|
|
|
command = 'ansible-test %s' % self.command
|
|
|
|
|
|
|
|
if self.test:
|
|
|
|
command += ' --test %s' % self.test
|
|
|
|
|
|
|
|
if self.python_version:
|
|
|
|
command += ' --python %s' % self.python_version
|
|
|
|
|
|
|
|
return command
|
|
|
|
|
2017-07-15 01:52:11 +02:00
|
|
|
def find_docs(self):
|
|
|
|
"""
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2019-09-14 04:21:54 +02:00
|
|
|
if self.command != 'sanity':
|
|
|
|
return None # only sanity tests have docs links
|
2019-08-28 23:34:12 +02:00
|
|
|
|
|
|
|
# Use the major.minor version for the URL only if this a release that
|
|
|
|
# matches the pattern 2.4.0, otherwise, use 'devel'
|
|
|
|
ansible_version = get_ansible_version()
|
|
|
|
url_version = 'devel'
|
|
|
|
if re.search(r'^[0-9.]+$', ansible_version):
|
|
|
|
url_version = '.'.join(ansible_version.split('.')[:2])
|
|
|
|
|
|
|
|
testing_docs_url = 'https://docs.ansible.com/ansible/%s/dev_guide/testing' % url_version
|
2017-07-15 01:52:11 +02:00
|
|
|
|
|
|
|
url = '%s/%s/' % (testing_docs_url, self.command)
|
|
|
|
|
|
|
|
if self.test:
|
|
|
|
url += '%s.html' % self.test
|
|
|
|
|
2019-09-14 04:21:54 +02:00
|
|
|
return url
|
2017-07-15 01:52:11 +02:00
|
|
|
|
2017-09-01 01:39:37 +02:00
|
|
|
def format_title(self, help_link=None):
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
2017-09-01 01:39:37 +02:00
|
|
|
:type help_link: str | None
|
2017-03-08 09:47:21 +01:00
|
|
|
:rtype: str
|
|
|
|
"""
|
|
|
|
command = self.format_command()
|
|
|
|
|
|
|
|
if self.summary:
|
2018-02-08 07:44:33 +01:00
|
|
|
reason = 'the error'
|
2017-03-08 09:47:21 +01:00
|
|
|
else:
|
2018-02-08 07:44:33 +01:00
|
|
|
reason = '1 error' if len(self.messages) == 1 else '%d errors' % len(self.messages)
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2017-09-01 01:39:37 +02:00
|
|
|
if help_link:
|
2018-02-08 07:44:33 +01:00
|
|
|
help_link_markup = ' [[explain](%s)]' % help_link
|
2017-09-01 01:39:37 +02:00
|
|
|
else:
|
|
|
|
help_link_markup = ''
|
|
|
|
|
2018-02-08 07:44:33 +01:00
|
|
|
title = 'The test `%s`%s failed with %s:' % (command, help_link_markup, reason)
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
return title
|
|
|
|
|
|
|
|
def format_block(self):
|
|
|
|
"""
|
|
|
|
:rtype: str
|
|
|
|
"""
|
|
|
|
if self.summary:
|
|
|
|
block = self.summary
|
|
|
|
else:
|
2017-09-09 17:59:09 +02:00
|
|
|
block = '\n'.join(m.format() for m in self.messages)
|
2017-03-08 09:47:21 +01:00
|
|
|
|
|
|
|
message = block.strip()
|
|
|
|
|
|
|
|
# Hack to remove ANSI color reset code from SubprocessError messages.
|
|
|
|
message = message.replace(display.clear, '')
|
|
|
|
|
|
|
|
return message
|
|
|
|
|
|
|
|
|
2019-07-12 22:17:20 +02:00
|
|
|
class TestMessage:
|
2017-03-08 09:47:21 +01:00
|
|
|
"""Single test message for one file."""
|
2017-03-15 20:17:42 +01:00
|
|
|
def __init__(self, message, path, line=0, column=0, level='error', code=None, confidence=None):
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
|
|
|
:type message: str
|
|
|
|
:type path: str
|
|
|
|
:type line: int
|
|
|
|
:type column: int
|
|
|
|
:type level: str
|
|
|
|
:type code: str | None
|
2017-03-15 20:17:42 +01:00
|
|
|
:type confidence: int | None
|
2017-03-08 09:47:21 +01:00
|
|
|
"""
|
2019-07-20 01:34:16 +02:00
|
|
|
self.__path = path
|
|
|
|
self.__line = line
|
|
|
|
self.__column = column
|
|
|
|
self.__level = level
|
|
|
|
self.__code = code
|
|
|
|
self.__message = message
|
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
self.confidence = confidence
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2019-07-20 01:34:16 +02:00
|
|
|
@property
|
|
|
|
def path(self): # type: () -> str
|
|
|
|
"""Return the path."""
|
|
|
|
return self.__path
|
|
|
|
|
|
|
|
@property
|
|
|
|
def line(self): # type: () -> int
|
|
|
|
"""Return the line number, or 0 if none is available."""
|
|
|
|
return self.__line
|
|
|
|
|
|
|
|
@property
|
|
|
|
def column(self): # type: () -> int
|
|
|
|
"""Return the column number, or 0 if none is available."""
|
|
|
|
return self.__column
|
|
|
|
|
|
|
|
@property
|
|
|
|
def level(self): # type: () -> str
|
|
|
|
"""Return the level."""
|
|
|
|
return self.__level
|
|
|
|
|
|
|
|
@property
|
|
|
|
def code(self): # type: () -> t.Optional[str]
|
|
|
|
"""Return the code, if any."""
|
|
|
|
return self.__code
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self): # type: () -> str
|
|
|
|
"""Return the message."""
|
|
|
|
return self.__message
|
|
|
|
|
|
|
|
@property
|
|
|
|
def tuple(self): # type: () -> t.Tuple[str, int, int, str, t.Optional[str], str]
|
|
|
|
"""Return a tuple with all the immutable values of this test message."""
|
|
|
|
return self.__path, self.__line, self.__column, self.__level, self.__code, self.__message
|
|
|
|
|
|
|
|
def __lt__(self, other):
|
|
|
|
return self.tuple < other.tuple
|
|
|
|
|
|
|
|
def __le__(self, other):
|
|
|
|
return self.tuple <= other.tuple
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
return self.tuple == other.tuple
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return self.tuple != other.tuple
|
|
|
|
|
|
|
|
def __gt__(self, other):
|
|
|
|
return self.tuple > other.tuple
|
|
|
|
|
|
|
|
def __ge__(self, other):
|
|
|
|
return self.tuple >= other.tuple
|
|
|
|
|
|
|
|
def __hash__(self):
|
|
|
|
return hash(self.tuple)
|
|
|
|
|
2017-03-08 09:47:21 +01:00
|
|
|
def __str__(self):
|
2017-03-15 20:17:42 +01:00
|
|
|
return self.format()
|
|
|
|
|
|
|
|
def format(self, show_confidence=False):
|
|
|
|
"""
|
|
|
|
:type show_confidence: bool
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2019-07-20 01:34:16 +02:00
|
|
|
if self.__code:
|
2019-08-28 23:12:56 +02:00
|
|
|
msg = '%s: %s' % (self.__code, self.__message)
|
2017-03-08 09:47:21 +01:00
|
|
|
else:
|
2019-07-20 01:34:16 +02:00
|
|
|
msg = self.__message
|
2017-03-08 09:47:21 +01:00
|
|
|
|
2017-03-15 20:17:42 +01:00
|
|
|
if show_confidence and self.confidence is not None:
|
|
|
|
msg += ' (%d%%)' % self.confidence
|
|
|
|
|
2019-07-20 01:34:16 +02:00
|
|
|
return '%s:%s:%s: %s' % (self.__path, self.__line, self.__column, msg)
|