-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy path__init__.py
More file actions
100 lines (79 loc) · 2.44 KB
/
__init__.py
File metadata and controls
100 lines (79 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from __future__ import annotations
from abc import ABCMeta, abstractmethod
from enum import Enum
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Awaitable
from typing import Any, Callable, ClassVar, TypeVar
import pytest
from typing_extensions import ParamSpec
from pytest_codspeed.config import BenchmarkMarkerOptions, PedanticOptions
from pytest_codspeed.plugin import CodSpeedConfig
T = TypeVar("T")
P = ParamSpec("P")
class Instrument(metaclass=ABCMeta):
instrument: ClassVar[str]
@abstractmethod
def __init__(self, config: CodSpeedConfig): ...
@abstractmethod
def get_instrument_config_str_and_warns(self) -> tuple[str, list[str]]: ...
@abstractmethod
def measure(
self,
marker_options: BenchmarkMarkerOptions,
name: str,
uri: str,
fn: Callable[P, T],
*args: P.args,
**kwargs: P.kwargs,
) -> T: ...
@abstractmethod
async def measure_async(
self,
marker_options: BenchmarkMarkerOptions,
name: str,
uri: str,
fn: Callable[P, Awaitable[T]],
*args: P.args,
**kwargs: P.kwargs,
) -> T: ...
@abstractmethod
def measure_pedantic(
self,
marker_options: BenchmarkMarkerOptions,
pedantic_options: PedanticOptions[T],
name: str,
uri: str,
) -> T: ...
@abstractmethod
async def measure_pedantic_async(
self,
marker_options: BenchmarkMarkerOptions,
pedantic_options: PedanticOptions[Awaitable[T]],
name: str,
uri: str,
) -> T: ...
@abstractmethod
def report(self, session: pytest.Session) -> None: ...
@abstractmethod
def get_result_dict(
self,
) -> dict[str, Any]: ...
class MeasurementMode(str, Enum):
Simulation = "simulation"
WallTime = "walltime"
@classmethod
def _missing_(cls, value: object):
# Accept "instrumentation" as deprecated alias for "simulation"
if value == "instrumentation":
return cls.Simulation
return None
def get_instrument_from_mode(mode: MeasurementMode) -> type[Instrument]:
from pytest_codspeed.instruments.valgrind import (
ValgrindInstrument,
)
from pytest_codspeed.instruments.walltime import WallTimeInstrument
if mode == MeasurementMode.Simulation:
return ValgrindInstrument
else:
return WallTimeInstrument