autocad-bench / tests /test_release.py
Dev Mandal
Initial open-source release
0be8f22
Raw
History Blame Contribute Delete
2.89 kB
from __future__ import annotations
import hashlib
import tarfile
from pathlib import Path
import pytest
from autocad_bench.bundle import BUNDLE_VERSION
from autocad_bench.common.paths import BENCHMARK_ROOT
from autocad_bench.release import (
CHECKSUM_FILENAME,
DEFAULT_SOURCE_DATE_EPOCH,
RELEASE_FILENAME,
ReleaseError,
_write_bundle_archive,
build_release,
verify_release,
)
def test_release_build_is_complete_and_self_verifying(tmp_path: Path) -> None:
output = tmp_path / "release"
built = build_release(
output,
source_root=BENCHMARK_ROOT,
evaluator_versions=(),
)
assert built.source_date_epoch == DEFAULT_SOURCE_DATE_EPOCH
assert built.package_name == "autocad-bench"
assert built.package_version == "0.1.0"
assert built.evaluator_versions == ()
assert {artifact.kind for artifact in built.artifacts} == {
"benchmark_bundle",
"sdist",
"wheel",
}
assert {path.name for path in output.iterdir()} == {
RELEASE_FILENAME,
CHECKSUM_FILENAME,
*(artifact.filename for artifact in built.artifacts),
}
assert verify_release(output) == built
wheel = next(
output / artifact.filename
for artifact in built.artifacts
if artifact.kind == "wheel"
)
wheel.write_bytes(wheel.read_bytes() + b"tampered")
with pytest.raises(ReleaseError, match="size changed"):
verify_release(output)
def test_release_build_refuses_existing_output(tmp_path: Path) -> None:
output = tmp_path / "existing"
output.mkdir()
with pytest.raises(ReleaseError, match="already exists"):
build_release(
output,
source_root=BENCHMARK_ROOT,
evaluator_versions=(),
)
def test_bundle_archive_writer_is_byte_reproducible(tmp_path: Path) -> None:
bundle = tmp_path / "bundle"
(bundle / "nested").mkdir(parents=True)
(bundle / "autocad-bench-bundle.json").write_text(
'{"fixture":true}\n',
encoding="utf-8",
)
(bundle / "nested" / "payload.bin").write_bytes(b"\x00\x01fixture")
first = tmp_path / "first.tar.gz"
second = tmp_path / "second.tar.gz"
_write_bundle_archive(
bundle,
first,
epoch=DEFAULT_SOURCE_DATE_EPOCH,
)
_write_bundle_archive(
bundle,
second,
epoch=DEFAULT_SOURCE_DATE_EPOCH,
)
assert first.read_bytes() == second.read_bytes()
assert hashlib.sha256(first.read_bytes()).hexdigest() == hashlib.sha256(
second.read_bytes()
).hexdigest()
with tarfile.open(first, mode="r:gz") as archive:
assert archive.getnames() == [
BUNDLE_VERSION,
f"{BUNDLE_VERSION}/autocad-bench-bundle.json",
f"{BUNDLE_VERSION}/nested",
f"{BUNDLE_VERSION}/nested/payload.bin",
]