File: test_properties.py

package info (click to toggle)
awesomeversion 25.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,304 kB
  • sloc: python: 2,411; sh: 146; makefile: 5
file content (47 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (2)
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
"""Property benchmarks for AwesomeVersion."""

from __future__ import annotations

import pytest
from pytest_codspeed import BenchmarkFixture

from awesomeversion import AwesomeVersion, AwesomeVersionStrategy

from .const import DEFAULT_RUNS

semver_first = {
    "ensure_strategy": AwesomeVersionStrategy.SEMVER,
    "find_first_match": True,
}


@pytest.mark.parametrize(
    "version,class_property",
    (
        *[(version, "prefix") for version in ("v1.2.3", "v.1.2.3", "1.2.3")],
        *[(version, "modifier") for version in ("1.2.3-dev2", "1.2.3dev2")],
        *[(version, "modifier_type") for version in ("1.2.3.dev0", "1.2.3.beta0")],
        *[(version, "strategy") for version in ("1.2.3", "2099.1.1", "999")],
        *[
            (version, "strategy_description")
            for version in ("1.2.3", "2099.1.1", "999")
        ],
        *[
            (version, segment)
            for version in ("1.2.3", "123", "0.1.2.3")
            for segment in ("major", "minor", "patch")
        ],
    ),
)
def test_property(
    benchmark: BenchmarkFixture,
    version: str | int | float,
    class_property: str,
) -> None:
    """Benchmark for AwesomeVersion properties."""
    obj = AwesomeVersion(version)

    @benchmark
    def _run_benchmark() -> None:
        for _ in range(DEFAULT_RUNS):
            getattr(obj, class_property)