fix: show no digest for a file never read

This commit is contained in:
Abdessamad Derraz committed 2026-11-05 11:48:31 +01:00
1 parent 0c92fb6705
commit 7b6b22351a
2 files changed
+22 -8

No files matched your search

+14 -8
View File
@@ -95,10 +95,13 @@ class ValidationResult:
lines = [f"### {status} `{self.filename}`"]
lines.append("")
lines.append(f"- **Path**: `{self.filepath}`")
lines.append(f"- **Size**: {self.size:,} bytes")
lines.append(f"- **SHA1**: `{self.sha1}`")
lines.append(f"- **MD5**: `{self.md5}`")
lines.append(f"- **CRC32**: `{self.crc32}`")
# A path refused before it was read has no size or digest to show:
# empty fields read as an empty file contributed.
if self.sha1:
lines.append(f"- **Size**: {self.size:,} bytes")
lines.append(f"- **SHA1**: `{self.sha1}`")
lines.append(f"- **MD5**: `{self.md5}`")
lines.append(f"- **CRC32**: `{self.crc32}`")
lines.append("")
for status_str, message in self.checks:
@@ -293,7 +296,9 @@ def validate_file(
return result
if not os.path.exists(filepath):
result.add_check(False, f"File not found: {filepath}")
result.add_check(False, f"File not found: {filepath}. A path is read from the folder "
"the command runs in, or pass --changed to check the files "
"changed under bios/")
return result
if not os.path.isfile(filepath):
@@ -670,9 +675,10 @@ def main() -> None:
for r in results:
status = "PASS" if r.passed else "FAIL"
print(f"\n[{status}] {r.filepath}")
print(f" SHA1: {r.sha1}")
print(f" MD5: {r.md5}")
print(f" Size: {r.size:,}")
if r.sha1:
print(f" SHA1: {r.sha1}")
print(f" MD5: {r.md5}")
print(f" Size: {r.size:,}")
for s, m in r.checks:
marker = (
"ok"
+8
View File
@@ -46,6 +46,14 @@ class FileShapeChecks(_Fixture):
self.assertFalse(result.passed)
self.assertEqual(result.sha1, "")
def test_a_path_never_read_shows_no_digest(self):
"""Empty Size, SHA1, MD5 and CRC32 lines read as an empty file contributed."""
result = validate_pr.validate_file("bios/nope.bin", None, EMPTY_HASHES)
markdown = result.to_markdown()
for label in ("**Size**", "**SHA1**", "**MD5**", "**CRC32**"):
self.assertNotIn(label, markdown)
self.assertIn("--changed", markdown)
def test_empty_file_fails(self):
rel = self._bios_file("bios/Sony/PS/empty.bin", b"")
result = validate_pr.validate_file(rel, None, EMPTY_HASHES)