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

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tthijm committed Jun 10, 2024
1 parent 69710c9 commit e540817
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
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
from cov.utils import results
import cov.utils


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

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


if __name__ == "__main__":
Expand Down
13 changes: 13 additions & 0 deletions cov/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from typing import List


class Benchmark:
def __init__(self, amount_of_branches: int) -> None:
self.amount_of_branches: int = amount_of_branches
self.reached_branches: List[bool] = amount_of_branches * [False]

def mark(self, branch_id: int) -> None:
self.reached_branches[branch_id] = True

def is_valid(self, branch_id: int) -> bool:
return 0 <= branch_id < self.amount_of_branches
23 changes: 11 additions & 12 deletions cov/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
from typing import Set, Dict, Callable
from inspect import stack
from typing import Dict, Callable
from cov.benchmark import Benchmark
import inspect

__all__ = ["test", "mark"]


class Benchmark:
def __init__(self, amount_of_branches: int) -> None:
self.amount_of_branches: int = amount_of_branches
self.reached: Set[int] = set()


results: Dict[str, Benchmark] = {}


Expand All @@ -29,9 +23,14 @@ def wrapper(function: Callable) -> Callable:


def mark(branch_id: int) -> None:
function_name = stack()[1].function
function_name = inspect.stack()[1].function
benchmark = results.get(function_name)

if function_name not in results:
if benchmark is None or benchmark.is_valid(branch_id) is False:
raise KeyError()

results[function_name].reached.add(branch_id)
benchmark.mark(branch_id)


def print_results() -> None:
print(results)

0 comments on commit e540817

Please sign in to comment.