llamacppctl/tests/test_build_archive.py
dschlueter 55af8d8fb3 test: cover build_archive and add it to the ruff scope
build_archive.py had no lint or test coverage, which is how the obsolete
requirements/pyproject mirror check slipped through unnoticed. Close that gap:

- Add tests/test_build_archive.py: a network-free smoke test that runs the
  manifest check, dependency parsing, tarball build, and re-verification, and
  asserts the moved docs/ files, LICENSE, and package sources are packaged.
- Lint build_archive.py in both the local gate (scripts/check.sh) and the CI
  workflow; fix the one issue this surfaced (unused variable py_bin).
- List the new test in the REQUIRED_FILES manifest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 11:20:57 +02:00

40 lines
1.6 KiB
Python

"""Smoke test for the archive builder (build_archive.py).
Guards the packaging manifest and dependency parsing so regressions -- a moved
or renamed file, a broken REQUIRED_FILES entry, or the requirements/pyproject
dependency handling -- fail here in the normal test run instead of only
surfacing at release time. Runs the pure build steps (no network, no pip).
"""
import tarfile
from pathlib import Path
import build_archive
# build_archive.py lives at the repo root, so its directory is the project root.
PROJECT_ROOT = Path(build_archive.__file__).resolve().parent
def test_build_archive_builds_and_verifies(tmp_path):
out = tmp_path / "llamacppctl-test.tar.gz"
# Manifest + dependency declaration must be consistent with the real tree.
build_archive.verify_required_files(PROJECT_ROOT)
deps = build_archive.verify_dependencies_declared(PROJECT_ROOT)
assert deps, "expected runtime dependencies declared in pyproject.toml"
# Build the tarball and re-open it to verify every required file is present.
build_archive.build_tarball(PROJECT_ROOT, out)
build_archive.verify_tarball(out)
assert out.is_file()
with tarfile.open(out) as tar:
names = set(tar.getnames())
root = build_archive.ARCHIVE_ROOT_NAME
# Docs moved under docs/; LICENSE ships at the archive root; package present.
assert f"{root}/docs/BEDIENUNGSANLEITUNG.md" in names
assert f"{root}/docs/INSTALL_FROM_ARCHIVE.md" in names
assert f"{root}/docs/SECURITY_AND_OPERATIONS.md" in names
assert f"{root}/LICENSE" in names
assert f"{root}/src/llamacppctl/main.py" in names