Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pycobertura/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pycobertura.reporters import (
HtmlReporter,
TextReporter,
TextDirectorySummaryReporter,
HtmlReporterDelta,
TextReporterDelta,
)
Expand All @@ -16,6 +17,7 @@
reporters = {
"html": HtmlReporter,
"text": TextReporter,
"textdir": TextDirectorySummaryReporter
}


Expand Down
79 changes: 78 additions & 1 deletion pycobertura/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from pycobertura.utils import green, rangify, red
from pycobertura.templates import filters
from tabulate import tabulate

from pathlib import Path
import yaml

env = Environment(loader=PackageLoader("pycobertura", "templates"))
env.filters["line_status"] = filters.line_status
Expand Down Expand Up @@ -83,6 +84,82 @@ def generate(self):

return report

class TextDirectorySummaryReporter(Reporter):
def format_row(self, last_path, dir_total_lines, dir_total_missed):
formatted_missed_lines = ""
percent = 0
if (dir_total_lines != 0 and dir_total_missed != 0):
percent = (dir_total_lines - dir_total_missed) / dir_total_lines * 100

row = file_row_missed(
last_path,
dir_total_lines,
dir_total_missed,
percent,
formatted_missed_lines,
)

return row

def generate(self):
fileset = {}
reverseset = {}
resultgroup = {}
lines = self.get_report_lines()
with open("pycobertura/groups.yml") as fileh:
fileset = yaml.load(fileh, Loader=yaml.Loader)
for key in fileset.keys():
for directory in fileset[key].split(' '):
reverseset[directory] = key
dir_total_lines = 0
dir_total_missed = 0

lines = self.get_report_lines()
last_path = Path()
formatted_lines = []
for row in lines:
filename, total_lines, total_misses, line_rate, missed_lines = row
path = Path(filename).parents[0]
if last_path == Path():
last_path = path
dir_total_lines = total_lines
dir_total_missed = total_misses
elif last_path != path:
formatted_row = self.format_row(last_path, dir_total_lines, dir_total_missed)
formatted_lines.append(formatted_row)
strpath = str(last_path)
if strpath in reverseset:
k = reverseset[strpath]
if k in resultgroup:
resultgroup[k]['dir_total_lines'] += dir_total_lines
resultgroup[k]['dir_total_missed'] += dir_total_missed
else:
resultgroup[k] = {
'dir_total_lines': dir_total_lines,
'dir_total_missed': dir_total_missed
}
else:
print('path not covered in config: ' + strpath)
last_path = path
dir_total_lines = total_lines
dir_total_missed = total_misses
else:
dir_total_lines += total_lines
dir_total_missed += total_misses

report = tabulate(
formatted_lines, headers=["Directories", "Stmts", "Miss", "Cover", "Missing"]
)

for key in fileset.keys():
res = resultgroup[key]
percent = 0
if (res['dir_total_lines'] != 0 and res['dir_total_missed'] != 0):
percent = (res['dir_total_lines'] - res['dir_total_missed']) / res['dir_total_lines'] * 100

print(key + " - %+.2f%%" %(percent) + " %")

return report

class HtmlReporter(TextReporter):
def __init__(self, *args, **kwargs):
Expand Down