#!/usr/bin/env python3 """Создаёт каталоги UI-пробы сортировки и проверяет target-результат.""" from __future__ import annotations import os import pathlib import sys from datetime import datetime FILES = { "ALPHA.BIN": (50, datetime(2025, 1, 2, 12, 0, 0)), "BETA.TXT": (20, datetime(2023, 1, 2, 12, 0, 0)), "GAMMA.TXT": (10, datetime(2024, 1, 2, 12, 0, 0)), "DELTA.EXE": (30, datetime(2022, 1, 2, 12, 0, 0)), } def create(root: pathlib.Path) -> None: for panel_name in ("SORTL", "SORTR"): panel = root / panel_name panel.mkdir(parents=True) for directory in ("ADIR", "ZDIR"): (panel / directory).mkdir() for name, (size, stamp) in FILES.items(): path = panel / name path.write_bytes(bytes((index * 37 + size) & 0xFF for index in range(size))) timestamp = stamp.timestamp() os.utime(path, (timestamp, timestamp)) def verify(root: pathlib.Path) -> None: result = root / "SORTRES.TXT" expected = [ "PASS name ascending and fixed groups", "PASS selection fixture points to BETA", "PASS name descending toggle", "PASS selection preserved after sort", "PASS extension ascending", "PASS extension descending toggle", "PASS size ascending", "PASS size descending toggle", "PASS date ascending", "PASS date descending toggle", "PASS panel sort modes are independent", "PASS second EMM page sorted independently", "ALL PASS", ] failures: list[str] = [] if not result.is_file(): failures.append("нет SORTRES.TXT") else: text = result.read_bytes().decode("cp866", errors="replace") for line in expected: if line not in text: failures.append(f"нет строки результата: {line}") if failures: for failure in failures: print(f"FAIL: {failure}") raise SystemExit(1) print("PASS: 4 sort keys, reverse, fixed groups, selection, two panels.") def main() -> None: if len(sys.argv) != 3 or sys.argv[1] not in {"create", "verify"}: raise SystemExit(f"usage: {sys.argv[0]} create|verify DIR") root = pathlib.Path(sys.argv[2]) if sys.argv[1] == "create": create(root) else: verify(root) if __name__ == "__main__": main()