mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-17 08:53:28 -05:00
fix: exit non-zero when torrentzip check fails
This commit is contained in:
1 parent
61f49b7ac0
commit
0a5e15789f
2 files changed
+28
-4
No files matched your search
@@ -114,8 +114,8 @@ def identify_romset(
|
||||
return None
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Entry point."""
|
||||
def main() -> int:
|
||||
"""Entry point: 1 when a checked archive is not TorrentZip."""
|
||||
parser = argparse.ArgumentParser(description="TorrentZip builder and checker")
|
||||
parser.add_argument("--check", metavar="ZIP", help="report TorrentZip conformance")
|
||||
parser.add_argument("--rebuild", metavar="ZIP", help="normalize an archive")
|
||||
@@ -130,14 +130,14 @@ def main() -> None:
|
||||
print(f" md5: {hashlib.md5(data).hexdigest()}")
|
||||
print(f" rebuilt: {hashlib.md5(rebuilt).hexdigest()}")
|
||||
print(f" conform: {data == rebuilt}")
|
||||
return
|
||||
return 0 if data == rebuilt else 1
|
||||
|
||||
if args.rebuild:
|
||||
data = rebuild_torrentzip(args.rebuild)
|
||||
dest = args.output or args.rebuild
|
||||
Path(dest).write_bytes(data)
|
||||
print(f"{dest}: {len(data)} bytes, md5 {hashlib.md5(data).hexdigest()}")
|
||||
return
|
||||
return 0
|
||||
|
||||
parser.error("nothing to do: pass --check or --rebuild")
|
||||
|
||||
|
||||
@@ -153,5 +153,29 @@ def _as_file(test: unittest.TestCase, data: bytes) -> str:
|
||||
return path
|
||||
|
||||
|
||||
class CheckModeExitCode(unittest.TestCase):
|
||||
"""--check printed `conform: False` and exited 0, so no script could use it."""
|
||||
|
||||
def test_the_exit_code_follows_conformance(self):
|
||||
import subprocess
|
||||
|
||||
with tempfile.TemporaryDirectory(dir=os.path.join(REPO_ROOT, "tmp")) as directory:
|
||||
plain = os.path.join(directory, "plain.zip")
|
||||
with zipfile.ZipFile(plain, "w") as zf:
|
||||
zf.writestr("a.bin", b"rom")
|
||||
torrent = os.path.join(directory, "torrent.zip")
|
||||
with open(torrent, "wb") as handle:
|
||||
handle.write(build_torrentzip([("a.bin", b"rom")]))
|
||||
script = os.path.join(REPO_ROOT, "scripts", "torrentzip.py")
|
||||
codes = [
|
||||
subprocess.run(
|
||||
[sys.executable, script, "--check", path],
|
||||
capture_output=True, check=False, timeout=60,
|
||||
).returncode
|
||||
for path in (plain, torrent)
|
||||
]
|
||||
self.assertEqual(codes, [1, 0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user