Merge pull request #6782 from nicoddemus/code-highlight-followup

Assorted improvements following up #6658
This commit is contained in:
Bruno Oliveira 2020-03-27 08:58:50 -03:00 committed by GitHub
commit 429a28eca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View File

@ -1041,28 +1041,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:

View File

@ -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:

View File

@ -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