This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
forked from Rapptz/discord.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .utils import * | ||
from .cov import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import List, Dict, Callable | ||
from tabulate import tabulate | ||
import inspect | ||
|
||
__all__ = ["test", "mark"] | ||
|
||
|
||
class Coverage: | ||
def __init__(self, n_branches: int) -> None: | ||
self.n_branches: int = n_branches | ||
self.covered_branches: List[bool] = n_branches * [False] | ||
|
||
def get_coverage(self) -> int: | ||
return self.covered_branches.count(True) * 100 // self.n_branches | ||
|
||
def get_missing(self) -> str: | ||
missing = [str(branch_id) for branch_id, covered in enumerate(self.covered_branches) if covered is False] | ||
return " ".join(missing) | ||
|
||
|
||
coverages: Dict[str, Coverage] = dict() | ||
|
||
|
||
def test(n_branches: int) -> Callable: | ||
def decorator(func: Callable) -> Callable: | ||
coverages[func.__name__] = Coverage(n_branches) | ||
return func | ||
|
||
return decorator | ||
|
||
|
||
def mark(branch_id: int) -> None: | ||
func_name = inspect.stack()[1].function | ||
coverage = coverages[func_name] | ||
|
||
coverage.covered_branches[branch_id] = True | ||
|
||
|
||
def print_table() -> None: | ||
header = ["Function", "Branch %", "Branches", "Missing"] | ||
rows = [ | ||
(func_name, coverage.get_coverage(), coverage.n_branches, coverage.get_missing()) | ||
for func_name, coverage in coverages.items() | ||
] | ||
|
||
print(tabulate(rows, header)) |
This file was deleted.
Oops, something went wrong.