-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathconfig.py
More file actions
80 lines (69 loc) · 2.46 KB
/
Copy pathconfig.py
File metadata and controls
80 lines (69 loc) · 2.46 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
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import pytest
@dataclass(frozen=True)
class CodSpeedConfig:
"""
The configuration for the codspeed plugin.
Usually created from the command line arguments.
"""
warmup_time_ns: int | None = None
max_time_ns: int | None = None
max_rounds: int | None = None
@classmethod
def from_pytest_config(cls, config: pytest.Config) -> CodSpeedConfig:
warmup_time = config.getoption("--codspeed-warmup-time", None)
warmup_time_ns = (
int(warmup_time * 1_000_000_000) if warmup_time is not None else None
)
max_time = config.getoption("--codspeed-max-time", None)
max_time_ns = int(max_time * 1_000_000_000) if max_time is not None else None
return cls(
warmup_time_ns=warmup_time_ns,
max_rounds=config.getoption("--codspeed-max-rounds", None),
max_time_ns=max_time_ns,
)
@dataclass(frozen=True)
class BenchmarkMarkerOptions:
group: str | None = None
"""The group name to use for the benchmark."""
min_time: int | None = None
"""
The minimum time of a round (in seconds).
Only available in walltime mode.
"""
max_time: int | None = None
"""
The maximum time to run the benchmark for (in seconds).
Only available in walltime mode.
"""
max_rounds: int | None = None
"""
The maximum number of rounds to run the benchmark for.
Takes precedence over max_time. Only available in walltime mode.
"""
@classmethod
def from_pytest_item(cls, item: pytest.Item) -> BenchmarkMarkerOptions:
marker = item.get_closest_marker(
"codspeed_benchmark"
) or item.get_closest_marker("benchmark")
if marker is None:
return cls()
if len(marker.args) > 0:
raise ValueError(
"Positional arguments are not allowed in the benchmark marker"
)
options = cls(
group=marker.kwargs.pop("group", None),
min_time=marker.kwargs.pop("min_time", None),
max_time=marker.kwargs.pop("max_time", None),
max_rounds=marker.kwargs.pop("max_rounds", None),
)
if len(marker.kwargs) > 0:
raise ValueError(
"Unknown kwargs passed to benchmark marker: "
+ ", ".join(marker.kwargs.keys())
)
return options