Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Make module simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
tthijm committed Jun 11, 2024
1 parent 5755efd commit 90a8062
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 66 deletions.
2 changes: 1 addition & 1 deletion cov/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .utils import *
from .cov import *
4 changes: 2 additions & 2 deletions cov/__main__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import sys
import pytest
import cov.utils
import cov.cov


def main() -> None:
arguments = sys.argv

pytest.main(arguments[1:])
cov.utils.print_results()
cov.cov.print_table()


if __name__ == "__main__":
Expand Down
20 changes: 0 additions & 20 deletions cov/benchmark.py

This file was deleted.

46 changes: 46 additions & 0 deletions cov/cov.py
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))
43 changes: 0 additions & 43 deletions cov/utils.py

This file was deleted.

0 comments on commit 90a8062

Please sign in to comment.