Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, ui, get_id, stream, previous_run=None, filter_tags=None):
"""Construct a CLITestResult writing to stream.
:param filter_tags: Tags that should be used to filter tests out. When
a tag in this set is present on a test outcome, the test is not
counted towards the test run count. If the test errors, then it is
still counted and the error is still shown.
"""
super(CLITestResult, self).__init__(ui, get_id, previous_run)
self.stream = unicode_output_stream(stream)
self.sep1 = _u('=' * 70 + '\n')
self.sep2 = _u('-' * 70 + '\n')
self.filter_tags = filter_tags or frozenset()
self.filterable_states = set(['success', 'uxsuccess', 'xfail', 'skip'])
def _got_failure(deferred, failure):
deferred.addErrback(lambda _: None)
return Mismatch(
_u('Success result expected on %r, found failure result '
'instead: %r' % (deferred, failure)),
{'traceback': failure_content(failure)},
)
a("\n")
if successful:
a('PASSED')
else:
a('FAILED')
if values:
a(' (')
values_strings = []
for name, value, delta in values:
value_str = '%s=%s' % (name, value)
if delta:
value_str += ' (%+d)' % (delta,)
values_strings.append(value_str)
a(', '.join(values_strings))
a(')')
return _u('').join(summary)
def __init__(self, parser):
self.parser = parser
self._test_sym = (_b('test'), _b('testing'))
self._colon_sym = _b(':')
self._error_sym = (_b('error'),)
self._failure_sym = (_b('failure'),)
self._progress_sym = (_b('progress'),)
self._skip_sym = _b('skip')
self._success_sym = (_b('success'), _b('successful'))
self._tags_sym = (_b('tags'),)
self._time_sym = (_b('time'),)
self._xfail_sym = (_b('xfail'),)
self._uxsuccess_sym = (_b('uxsuccess'),)
self._start_simple = _u(" [")
self._start_multipart = _u(" [ multipart")
def RemoteError(description=_u("")):
return (_StringException, _StringException(description), None)
def _got_result(deferred, result):
return Mismatch(
_u('No result expected on %r, found %r instead'
% (deferred, result)))
def output_error(self, error_tuple):
if 'TESTR_PDB' in os.environ:
import traceback
self._stderr.write(_u('').join(traceback.format_tb(error_tuple[2])))
self._stderr.write(_u('\n'))
# This is terrible: it is because on Python2.x pdb writes bytes to
# its pipes, and the test suite uses io.StringIO that refuse bytes.
import pdb;
if sys.version_info[0]==2:
if isinstance(self._stdout, io.StringIO):
write = self._stdout.write
def _write(text):
return write(text.decode('utf8'))
self._stdout.write = _write
p = pdb.Pdb(stdin=self._stdin, stdout=self._stdout)
p.reset()
p.interaction(None, error_tuple[2])
error_type = str(error_tuple[1])
# XX: Python2.
if type(error_type) is bytes:
def __init__(self, get_id, stream, previous_run=None):
"""Construct a CLITestResult writing to stream.
:param get_id: A nullary callable that returns the id of the test run.
This expects a callable instead of the actual value
because in some repository backends the run_id is only
generated after stopTestRun() is called.
:param stream: The stream to use for result
:param previous_run: The CLITestResult for the previous run
"""
super(CLITestResult, self).__init__()
self._previous_run = previous_run
self._summary = SummarizingResult()
self.stream = testtools.compat.unicode_output_stream(stream)
self.sep1 = testtools.compat._u('=' * 70 + '\n')
self.sep2 = testtools.compat._u('-' * 70 + '\n')
self.filterable_states = set(['success', 'uxsuccess', 'xfail', 'skip'])
self.get_id = get_id
def _details_to_str(details):
"""Convert a details dict to a string."""
chars = []
# sorted is for testing, may want to remove that and use a dict
# subclass with defined order for items instead.
for key, content in sorted(details.items()):
if content.content_type.type != 'text':
chars.append('Binary content: %s\n' % key)
continue
chars.append('Text attachment: %s\n' % key)
chars.append('------------\n')
chars.extend(content.iter_text())
if not chars[-1].endswith('\n'):
chars.append('\n')
chars.append('------------\n')
return _u('').join(chars)
def output_error(self, error_tuple):
if 'TESTR_PDB' in os.environ:
import traceback
self._stderr.write(_u('').join(traceback.format_tb(error_tuple[2])))
self._stderr.write(_u('\n'))
# This is terrible: it is because on Python2.x pdb writes bytes to
# its pipes, and the test suite uses io.StringIO that refuse bytes.
import pdb;
if sys.version_info[0]==2:
if isinstance(self._stdout, io.StringIO):
write = self._stdout.write
def _write(text):
return write(text.decode('utf8'))
self._stdout.write = _write
p = pdb.Pdb(stdin=self._stdin, stdout=self._stdout)
p.reset()
p.interaction(None, error_tuple[2])
error_type = str(error_tuple[1])
# XX: Python2.
if type(error_type) is bytes:
error_type = error_type.decode('utf8')