File: conftest.py

package info (click to toggle)
python-boost-histogram 1.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,236 kB
  • sloc: python: 7,940; cpp: 3,243; makefile: 22; sh: 1
file content (101 lines) | stat: -rw-r--r-- 2,517 bytes parent folder | download
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
101
from __future__ import annotations

import contextlib
import importlib.metadata
import sys
import sysconfig
from pathlib import Path

if sys.version_info < (3, 11):
    import tomli as tomllib
else:
    import tomllib

import pytest
from packaging.requirements import Requirement

import boost_histogram as bh

DIR = Path(__file__).parent
BASE = DIR.parent


@pytest.fixture(params=(False, True), ids=("no_growth", "growth"))
def growth(request):
    return request.param


@pytest.fixture(params=(False, True), ids=("no_overflow", "overflow"))
def overflow(request):
    return request.param


@pytest.fixture(params=(False, True), ids=("no_underflow", "underflow"))
def underflow(request):
    return request.param


@pytest.fixture(params=(False, True), ids=("no_flow", "flow"))
def flow(request):
    return request.param


@pytest.fixture(
    params=(None, "str", 1, {"a": 1}),
    ids=("no_metadata", "str_metadata", "int_metadata", "dict_metadata"),
)
def metadata(request):
    return request.param


@pytest.fixture(
    params=(
        bh.storage.Double,
        bh.storage.Int64,
        bh.storage.AtomicInt64,
        bh.storage.Weight,
        bh.storage.Unlimited,
    ),
    ids=("Double", "Int64", "AtomicInt64", "Weight", "Unlimited"),
)
def count_storage(request):
    return request.param


@pytest.fixture(
    params=(
        bh.storage.Double,
        bh.storage.Int64,
        bh.storage.AtomicInt64,
        bh.storage.Unlimited,
    ),
    ids=("Double", "Int64", "AtomicInt64", "Unlimited"),
)
def count_single_storage(request):
    return request.param


def pytest_report_header() -> str:
    with BASE.joinpath("pyproject.toml").open("rb") as f:
        pyproject = tomllib.load(f)
    project = pyproject.get("project", {})

    pkgs = project.get("dependencies", [])
    pkgs += [p for ps in project.get("optional-dependencies", {}).values() for p in ps]
    if "name" in project:
        pkgs.append(project["name"])
    interesting_packages = {Requirement(p).name for p in pkgs}
    interesting_packages.add("pip")
    interesting_packages.add("numpy")

    valid = []
    for package in sorted(interesting_packages):
        with contextlib.suppress(ModuleNotFoundError):
            valid.append(f"{package}=={importlib.metadata.version(package)}")
    reqs = " ".join(valid)
    lines = [
        f"installed packages of interest: {reqs}",
    ]
    if sysconfig.get_config_var("Py_GIL_DISABLED"):
        lines.append("free-threaded Python build")
    return "\n".join(lines)