Repository navigation
Expand file tree
/
Copy pathtest_checksums.py
More file actions
49 lines (31 loc) · 1.48 KB
/
Copy pathtest_checksums.py
File metadata and controls
49 lines (31 loc) · 1.48 KB
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
"""The checksum verification `wheel_path()` applies to a built `dist/`."""
from __future__ import annotations
import hashlib
from pathlib import Path
import pytest
from tests.packaging._wheel import _checked, verify_checksum
NAME = "visionset-0.0.0-py3-none-any.whl"
def _dist(tmp_path: Path, content: bytes, digest_of: bytes) -> tuple[Path, Path]:
wheel = tmp_path / NAME
wheel.write_bytes(content)
sums = tmp_path / "SHA256SUMS"
sums.write_text(f"{hashlib.sha256(digest_of).hexdigest()} {NAME}\n", encoding="utf-8")
return wheel, sums
def test_a_matching_digest_passes(tmp_path: Path) -> None:
wheel, sums = _dist(tmp_path, b"wheel", b"wheel")
verify_checksum(wheel, sums)
def test_a_mismatched_digest_fails_loudly(tmp_path: Path) -> None:
wheel, sums = _dist(tmp_path, b"tampered", b"wheel")
with pytest.raises(RuntimeError, match="does not match"):
verify_checksum(wheel, sums)
def test_a_wheel_the_sums_do_not_list_fails(tmp_path: Path) -> None:
wheel, sums = _dist(tmp_path, b"wheel", b"wheel")
sums.write_text("", encoding="utf-8")
with pytest.raises(RuntimeError, match="does not list"):
verify_checksum(wheel, sums)
def test_a_missing_sums_file_is_an_error_only_when_required(tmp_path: Path) -> None:
wheel = tmp_path / NAME
wheel.write_bytes(b"wheel")
assert _checked(wheel, required=False) == wheel
with pytest.raises(RuntimeError, match="SHA256SUMS is missing"):
_checked(wheel, required=True)