Skip to content
Snippets Groups Projects
Commit fcc33250 authored by Florian Bruhin's avatar Florian Bruhin
Browse files

Move percentage dict to Outcomes

parent 1ae36d80
No related branches found
No related tags found
No related merge requests found
......@@ -31,11 +31,22 @@ class Outcomes:
def add_report(self, outcome: str, report: pytest.TestReport) -> None:
getattr(self, outcome).append(report)
def total_count(self) -> int:
return sum(len(e) for e in dataclasses.astuple(self))
def _perc(self, count: int, total: int) -> str:
perc = round(count / total * 100)
if perc == 0 and count > 0:
return "~0%"
elif perc == 100 and count < total:
return "~100%"
else:
return f"{perc}%"
def to_dict(self) -> dict[str, list[pytest.TestReport]]:
return dataclasses.asdict(self)
def to_perc_dict(self) -> dict[str, str]:
total = sum(len(e) for e in dataclasses.astuple(self))
return {
outcome: self._perc(len(tests), total)
for outcome, tests in dataclasses.asdict(self).items()
if tests
}
class VeiledResultPlugin:
......@@ -95,31 +106,17 @@ class VeiledResultPlugin:
self.reports[self._exercise_name(report)].add_report(result, report)
def _perc(self, count: int, total: int) -> str:
perc = round(count / total * 100)
if perc == 0 and count > 0:
return "~0%"
elif perc == 100 and count < total:
return "~100%"
else:
return f"{perc}%"
def result(self) -> dict[str, Any]:
# exercise -> outcome -> percentage
result: dict[str, dict[str, str]] = collections.defaultdict(dict)
for exercise, outcomes in sorted(self.reports.items()):
total = outcomes.total_count()
for outcome, tests in outcomes.to_dict().items():
count = len(tests)
if count == 0:
continue
# FIXME report.when?
result[exercise][outcome] = self._perc(count, total)
result = {
exercise: outcomes.to_perc_dict()
for exercise, outcomes in self.reports.items()
}
# FIXME celltag not found separately?
return {
"status": self.exitstatus,
"tests": dict(result),
"tests": result,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment