| 123456789101112131415161718192021222324252627282930313233343536373839 |
- from __future__ import annotations
- import sys
- import zipfile
- from pathlib import Path
- TOOLS = Path(__file__).resolve().parents[3] / "tools"
- sys.path.insert(0, str(TOOLS))
- from package_hth_review import write_zip_file, zip_file_mode # noqa: E402
- from zip_unix_modes import extract_zip_with_unix_modes # noqa: E402
- def test_zip_file_mode_marks_scripts_executable(tmp_path):
- sh = tmp_path / "run.sh"
- sh.write_text("#!/bin/sh\n", encoding="utf-8")
- py = tmp_path / "tool.py"
- py.write_bytes(b"#!/usr/bin/env python3\nprint(1)\n")
- txt = tmp_path / "note.txt"
- txt.write_text("x\n", encoding="utf-8")
- assert zip_file_mode(sh) == 0o755
- assert zip_file_mode(py) == 0o755
- assert zip_file_mode(txt) == 0o644
- def test_extract_restores_unix_modes(tmp_path):
- zpath = tmp_path / "m.zip"
- with zipfile.ZipFile(zpath, "w") as zf:
- write_zip_file(zf, "bin/run.sh", b"#!/bin/sh\necho ok\n", 0o755)
- write_zip_file(zf, "readme.txt", b"hello\n", 0o644)
- dest = tmp_path / "out"
- extract_zip_with_unix_modes(zpath, dest)
- sh = dest / "bin" / "run.sh"
- txt = dest / "readme.txt"
- assert sh.is_file()
- assert txt.is_file()
- if sys.platform != "win32":
- assert sh.stat().st_mode & 0o777 == 0o755
- assert txt.stat().st_mode & 0o777 == 0o644
|