metis/tests/test_image.py

31 lines
742 B
Python

import hashlib
from pathlib import Path
from metis.pkg import image
def test_download_file_url(tmp_path):
src = tmp_path / "src.bin"
src.write_bytes(b"hello")
dest = tmp_path / "dest.bin"
image.Download(f"file://{src}", dest)
assert dest.read_bytes() == b"hello"
def test_checksum_ok(tmp_path):
f = tmp_path / "file.bin"
f.write_bytes(b"abc")
checksum = "sha256:" + hashlib.sha256(b"abc").hexdigest()
image.VerifyChecksum(f, checksum)
def test_checksum_bad(tmp_path):
f = tmp_path / "file.bin"
f.write_bytes(b"abc")
checksum = "sha256:deadbeef"
try:
image.VerifyChecksum(f, checksum)
except Exception:
return
raise AssertionError("expected checksum failure")