mirror of
https://github.com/miurahr/aqtinstall.git
synced 2025-12-18 13:14:37 +03:00
Improve ArchiveChecksumError error message
This commit is contained in:
@@ -77,7 +77,7 @@ def getUrl(url: str, timeout) -> str:
|
||||
return result
|
||||
|
||||
|
||||
def downloadBinaryFile(url: str, out: str, hash_algo: str, exp: str, timeout):
|
||||
def downloadBinaryFile(url: str, out: str, hash_algo: str, exp: bytes, timeout):
|
||||
logger = getLogger("aqt.helper")
|
||||
filename = Path(url).name
|
||||
with requests.Session() as session:
|
||||
@@ -109,7 +109,8 @@ def downloadBinaryFile(url: str, out: str, hash_algo: str, exp: str, timeout):
|
||||
if exp is not None and hash.digest() != exp:
|
||||
raise ArchiveChecksumError(
|
||||
f"Downloaded file {filename} is corrupted! Detect checksum error.\n"
|
||||
f"Expected {exp}, Actual {hash.digest()}"
|
||||
f"Expect {exp.hex()}: {url}\n"
|
||||
f"Actual {hash.digest().hex()}: {out}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -129,12 +129,15 @@ def test_helper_downloadBinary_wrong_checksum(tmp_path, monkeypatch):
|
||||
|
||||
actual_hash = binascii.unhexlify("1d41a93e4a585bb01e4518d4af431933")
|
||||
wrong_hash = binascii.unhexlify("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
||||
expected_err = (
|
||||
f"Downloaded file test.xml is corrupted! Detect checksum error.\nExpected {wrong_hash}, Actual {actual_hash}"
|
||||
)
|
||||
out = tmp_path.joinpath("test.xml")
|
||||
url = "http://example.com/test.xml"
|
||||
expected_err = (
|
||||
f"Downloaded file test.xml is corrupted! Detect checksum error."
|
||||
f"\nExpect {wrong_hash.hex()}: {url}"
|
||||
f"\nActual {actual_hash.hex()}: {out}"
|
||||
)
|
||||
with pytest.raises(ArchiveChecksumError) as e:
|
||||
helper.downloadBinaryFile("http://example.com/test.xml", out, "md5", wrong_hash, 60)
|
||||
helper.downloadBinaryFile(url, str(out), "md5", wrong_hash, 60)
|
||||
assert e.type == ArchiveChecksumError
|
||||
assert format(e.value) == expected_err
|
||||
|
||||
|
||||
Reference in New Issue
Block a user