Files
mtusi2026lab4/scripts/prepare_track1_fixtures.py

46 lines
977 B
Python

import os
from pathlib import Path
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
FIXTURES = ROOT / "tests" / "fixtures"
WIDTH = 1600
HEIGHT = 1200
def main():
FIXTURES.mkdir(parents=True, exist_ok=True)
source = FIXTURES / "sample.png"
large = FIXTURES / "sample_large.png"
if not source.exists():
raise FileNotFoundError(
f"Small fixture not found: {source}"
)
pixels = os.urandom(WIDTH * HEIGHT * 3)
image = Image.frombytes(
"RGB",
(WIDTH, HEIGHT),
pixels,
)
image.save(large, format="PNG", optimize=False)
for path in (source, large):
size = path.stat().st_size
print(f"{path.name}: {size} bytes ({size / 1024 / 1024:.2f} MiB)")
if large.stat().st_size > 10 * 1024 * 1024:
raise RuntimeError("Large fixture exceeds the 10 MiB upload limit")
print("PASS: Track 1 fixtures prepared")
if __name__ == "__main__":
main()