Colorize the coverage report

This commit is contained in:
Andrew Hamilton 2015-12-23 18:21:58 +00:00
parent 05732fa20e
commit 9472c8bc10
2 changed files with 20 additions and 1 deletions

View file

@ -221,3 +221,15 @@ class TermStr(collections.UserString):
return CharStyle(style.fg_color, style.bg_color,
is_bold=style.is_bold, is_underlined=True)
return self.transform_style(make_underlined)
def fg_color(self, fg_color):
def set_fgcolor(style):
return CharStyle(fg_color, style.bg_color, is_bold=style.is_bold,
is_underlined=style.is_underlined)
return self.transform_style(set_fgcolor)
def bg_color(self, bg_color):
def set_bgcolor(style):
return CharStyle(style.fg_color, bg_color, is_bold=style.is_bold,
is_underlined=style.is_underlined)
return self.transform_style(set_bgcolor)

View file

@ -464,6 +464,13 @@ def flog(path): # Deps: "gem install flog"
# return status, source_widget
def _colorize_coverage_report(text):
line_color = {"> ": termstr.Color.green, "! ": termstr.Color.red,
" ": None}
return fill3.join("", [termstr.TermStr(line).fg_color(line_color[line[:2]])
for line in text.splitlines(keepends=True)])
def python3_coverage(path):
test_path = path[:-(len(".py"))] + "_test.py"
if os.path.exists(test_path):
@ -480,7 +487,7 @@ def python3_coverage(path):
os.path.normpath(path)], env=env)
with open(os.path.join(temp_dir, path + ",cover"), "r") as f:
stdout = f.read()
return Status.info, fill3.Text(stdout)
return Status.info, fill3.Text(_colorize_coverage_report(stdout))
else:
return Status.placeholder, fill3.Text("No corresponding test file: " +
os.path.normpath(test_path))