Assorted improvements following up #6658
This commit is contained in:
parent
d1b50526fa
commit
c91abe48ba
|
@ -1048,28 +1048,35 @@ class ReprEntry(TerminalRepr):
|
|||
character, as doing so might break line continuations.
|
||||
"""
|
||||
|
||||
indent_size = 4
|
||||
|
||||
def is_fail(line):
|
||||
return line.startswith("{} ".format(FormattedExcinfo.fail_marker))
|
||||
|
||||
if not self.lines:
|
||||
return
|
||||
|
||||
# separate indents and source lines that are not failures: we want to
|
||||
# highlight the code but not the indentation, which may contain markers
|
||||
# such as "> assert 0"
|
||||
fail_marker = "{} ".format(FormattedExcinfo.fail_marker)
|
||||
indent_size = len(fail_marker)
|
||||
indents = []
|
||||
source_lines = []
|
||||
failure_lines = []
|
||||
seeing_failures = False
|
||||
for line in self.lines:
|
||||
if not is_fail(line):
|
||||
is_source_line = not line.startswith(fail_marker)
|
||||
if is_source_line:
|
||||
assert not seeing_failures, (
|
||||
"Unexpected failure lines between source lines:\n"
|
||||
+ "\n".join(self.lines)
|
||||
)
|
||||
indents.append(line[:indent_size])
|
||||
source_lines.append(line[indent_size:])
|
||||
else:
|
||||
seeing_failures = True
|
||||
failure_lines.append(line)
|
||||
|
||||
tw._write_source(source_lines, indents)
|
||||
|
||||
# failure lines are always completely red and bold
|
||||
for line in (x for x in self.lines if is_fail(x)):
|
||||
for line in failure_lines:
|
||||
tw.line(line, bold=True, red=True)
|
||||
|
||||
def toterminal(self, tw: TerminalWriter) -> None:
|
||||
|
|
|
@ -26,7 +26,7 @@ class TerminalWriter(BaseTerminalWriter):
|
|||
self.line(indent + new_line)
|
||||
|
||||
def _highlight(self, source):
|
||||
"""Highlight the given source code according to the "code_highlight" option"""
|
||||
"""Highlight the given source code if we have markup support"""
|
||||
if not self.hasmarkup:
|
||||
return source
|
||||
try:
|
||||
|
|
|
@ -192,6 +192,8 @@ def color_mapping():
|
|||
output = result.stdout.str()
|
||||
assert "test session starts" in output
|
||||
assert "\x1b[1m" in output
|
||||
pytest.skip("doing limited testing because lacking ordered markup")
|
||||
pytest.skip(
|
||||
"doing limited testing because lacking ordered markup on py35"
|
||||
)
|
||||
|
||||
return ColorMapping
|
||||
|
|
Loading…
Reference in New Issue