Files
orisys-sdk/tests/test_pyproject.py
T
2026-09-27 19:21:55 +08:00

121 lines
4.3 KiB
Python

from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[1]
@pytest.fixture
def packaging_utils():
import sys
build_dir = REPO_ROOT / "build"
if str(build_dir) not in sys.path:
sys.path.insert(0, str(build_dir))
from common.pyproject_utils import (
extras_require,
install_requires,
project_metadata,
)
return install_requires, extras_require, project_metadata
def test_pyproject_dependencies(packaging_utils):
install_requires, extras_require, project_metadata = packaging_utils
metadata = project_metadata(REPO_ROOT)
assert metadata["name"] == "orisys"
assert "numpy>=" in install_requires(REPO_ROOT)[0]
assert "cuda12" in extras_require(REPO_ROOT)
assert extras_require(REPO_ROOT)["cuda"] == extras_require(REPO_ROOT)["cuda12"]
def test_pyproject_dynamic_version(packaging_utils):
"""The dynamic version must resolve to a valid version from one source.
Deliberately does NOT assert a literal version: pinning it here means every
release has to edit this file too. ``src/orisys/__init__.py::__version__`` is
the single source of truth, and build/release/version.py checks that the
wheels agree with it.
"""
import re
import sys
build_dir = REPO_ROOT / "build"
if str(build_dir) not in sys.path:
sys.path.insert(0, str(build_dir))
from common.pyproject_utils import get_version
from release.version import dynamic_version_attr
version = get_version(REPO_ROOT)
assert re.fullmatch(r"\d+(?:\.\d+)+(?:[-+][0-9A-Za-z.]+)?", version), version
assert dynamic_version_attr(REPO_ROOT) == "orisys.__version__"
def test_pyproject_bundle_manifest(packaging_utils):
import sys
build_dir = REPO_ROOT / "build"
if str(build_dir) not in sys.path:
sys.path.insert(0, str(build_dir))
from common.pyproject_utils import bundle_data_files, bundle_items
items = bundle_items(REPO_ROOT)
names = {item["name"] for item in items}
# docs/ is intentionally not bundled: it ships with the GitHub repo and the
# PyPI project page only, so doc edits do not invalidate built wheels.
assert names == {"configs", "examples", "sensors"}
data_files = dict(bundle_data_files(REPO_ROOT))
assert "orisys/configs" in data_files
config_files = data_files["orisys/configs"]
assert config_files
assert all("/" in path and "*" not in path for path in config_files)
assert any(path.endswith(".json") for path in config_files)
sensor_dirs = [dest for dest in data_files if dest.startswith("orisys/sensors")]
assert sensor_dirs
all_sensor_files = [path for files in (data_files[d] for d in sensor_dirs) for path in files]
assert any(path.endswith("force_calibration.json") for path in all_sensor_files)
assert any("finger" in path and path.endswith(".json") for path in all_sensor_files)
# Finger mesh/viz assets (flat or nested assets/finger/ checkout).
assert any("finger/assets" in dest or any("finger/assets" in p for p in data_files[dest]) for dest in sensor_dirs)
assert all("*" not in path for files in data_files.values() for path in files)
assert "examples" not in data_files
def test_stage_dev_bundle_into_writes_sensors_under_package(tmp_path):
import sys
build_dir = REPO_ROOT / "build"
if str(build_dir) not in sys.path:
sys.path.insert(0, str(build_dir))
from common.pyproject_utils import stage_dev_bundle_into
pkg = tmp_path / "orisys"
packaged = stage_dev_bundle_into(REPO_ROOT, pkg)
assert any(p.replace("\\", "/").endswith("sensors/box/force_calibration.json") for p in packaged)
assert (pkg / "sensors" / "box" / "force_calibration.json").is_file()
assert (pkg / "configs").is_dir()
assert any((pkg / "configs").glob("*.json"))
def test_bundle_explicit_files():
import sys
build_dir = REPO_ROOT / "build"
if str(build_dir) not in sys.path:
sys.path.insert(0, str(build_dir))
from wheel.layout import data_file_entries_for_item, resolve_bundle_source_files
item = {
"name": "configs",
"source": "config",
"target": "configs",
"files": ["dd02-ov.json"],
}
paths = resolve_bundle_source_files(REPO_ROOT, item)
assert [p.name for p in paths] == ["dd02-ov.json"]
assert data_file_entries_for_item(item) == ["config/dd02-ov.json"]