"""The Python builder's install of a release (builder/py/hookshot_builder/setup_parts.py; no network, no real release). Checked here, in a temporary HOOKSHOT_SETUP_BASE with authored zips: - a zip member's name: a device's name (with or without an extension, COM1 to COM9, LPT1 to LPT9), a name that ends in a dot or a space, a colon or a drive's letter, a path from the root or through "..", a character Windows refuses: such a zip is refused whole and nothing of it is written (zipfile's extractall dropped some quietly and wrote the file under another name); - the room on the disk asked before a download's first byte and before an unpacking's first file; - the installed version is the rollback point: the folders an update moves over from it (reuse_part) are written down first, and a cancel, a failure, or an install cut off and run again moves them back, so the version still installed is whole and the unfinished one is gone; (Triforce) and so is what a cut-off install of another release moved (every versions\\*.part with a reused.txt is undone at the start of an install, not only the release's own). python -I -B tests/test_builder_setup_parts.py """ import io import os import shutil import sys import tempfile import unittest import zipfile from pathlib import Path from unittest import mock ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "builder" / "py")) from hookshot_builder import paths, setup_parts as sp # noqa: E402 SHA_A, SHA_B = "a" * 64, "b" * 64 def zip_bytes(names): data = io.BytesIO() with zipfile.ZipFile(data, "w") as z: for n in names: z.writestr(n, b"x") return data.getvalue() class Names(unittest.TestCase): def test_refused(self): for name in ("NUL", "nul.txt", "tools/CON", "a/Aux.dll", "COM1", "lpt9.log", "com\u00b9.txt", "a/CONIN$", "prn .txt", "a/b.", "a/b ", "a./b", "c:/x", "C:x", "a/b:stream", "/etc/x", "\\x", "../x", "a/../../x", "a\\..\\x", "a/b