• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

martineberlein / debugging-benchmark / 7872562145

12 Feb 2024 01:34PM UTC coverage: 0.0% (-82.6%) from 82.589%
7872562145

Pull #25

github

martineberlein
update coverage pipeline
Pull Request #25: Stable

0 of 32 new or added lines in 3 files covered. (0.0%)

0 of 1877 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/debugging_framework/benchmark.py
1
import importlib.util
×
2
import sys
×
3
import ast
×
4

NEW
5
from typing import Union, List, Callable, Dict, Sequence, Any
×
6
from pathlib import Path
×
7
from abc import ABC, abstractmethod
×
8
from fuzzingbook.Grammars import Grammar
×
9

10
from debugging_framework.oracle import OracleResult
×
11

12

13
class BenchmarkProgram(ABC):
×
14
    def __init__(
×
15
        self, name: str, grammar: Grammar, oracle: Callable, initial_inputs: List[str]
16
    ):
17
        self.name = name
×
18
        self.grammar = grammar
×
19
        self.oracle = oracle
×
20
        self.initial_inputs = initial_inputs
×
21

22
    @abstractmethod
×
23
    def get_name(self) -> str:
×
24
        raise NotImplementedError
×
25

26
    @abstractmethod
×
27
    def get_grammar(self):
×
28
        raise NotImplementedError
×
29

30
    @abstractmethod
×
31
    def get_initial_inputs(self):
×
32
        raise NotImplementedError
×
33

34
    @abstractmethod
×
35
    def get_oracle(self):
×
36
        raise NotImplementedError
×
37

38
    def to_dict(self):
×
39
        return {
×
40
            "grammar": self.get_grammar(),
41
            "oracle": self.get_oracle(),
42
            "initial_inputs": self.get_initial_inputs(),
43
        }
44

45

46
class BenchmarkRepository(ABC):
×
47

48
    name: str
×
49

50
    def __repr__(self):
×
51
        return f"BenchmarkRepository({self.name})"
×
52

53
    @abstractmethod
×
54
    def build(
×
55
            self,
56
            err_def: Dict[Exception, OracleResult] = None,
57
            default_oracle: OracleResult = None,
58
    ) -> List[BenchmarkProgram]:
59
        raise NotImplementedError
×
60

61
    @abstractmethod
×
62
    def get_all_test_programs(self) -> List[BenchmarkProgram]:
×
63
        raise NotImplementedError
×
64

65
    @staticmethod
×
66
    def get_grammar() -> Grammar:
×
67
        raise NotImplementedError
×
68

69
    @staticmethod
×
70
    def get_initial_inputs() -> List[str]:
×
71
        raise NotImplementedError
×
72

73
    @staticmethod
×
74
    def harness_function(input_str: str) -> Sequence[Any]:
×
75
        raise NotImplementedError
×
76

77

78
def load_module_dynamically(path: Union[str, Path]):
×
79
    # Step 1: Convert file path to module name
80
    file_path = ""
×
81
    if isinstance(path, Path):
×
82
        file_path = str(path.absolute())
×
83
    elif isinstance(path, str):
×
84
        file_path = str(path)
×
85
    else:
86
        raise TypeError("path should be from type Path or str")
×
87

88
    module_name = file_path.replace("/", ".").rstrip(".py")
×
89

90
    # Step 2: Load module dynamically
91
    spec = importlib.util.spec_from_file_location(module_name, file_path)
×
92
    module = importlib.util.module_from_spec(spec)
×
93
    sys.modules[module_name] = module
×
94
    spec.loader.exec_module(module)
×
95

96
    return module
×
97

98

99
def load_object_dynamically(path: Union[str, Path], object_name: str):
×
100
    module = load_module_dynamically(path)
×
101
    return getattr(module, object_name)
×
102

103

104
def load_function_from_class(path: Union[str, Path], function_name: str):
×
105
    class_name = get_class_name(path)
×
106
    class_ = load_object_dynamically(path, class_name)
×
107
    function = getattr(class_(), function_name)
×
108

109
    return function
×
110

111

112
def get_class_name(path: Union[str, Path]) -> str:
×
113
    # gets all class names in the file
114
    # TODO: encoding?
115
    data = Path(path).read_text()
×
116
    tree = ast.parse(data)
×
117
    classes = [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
×
118

119
    # returns only the first class
120
    return classes[0]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc